From 98f439a86a8300e106067fdea303fb800bdf4556 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 31 Oct 2023 09:05:21 +0000 Subject: [PATCH 1/5] refactor: aztec-cli better volume mounting strategy --- yarn-project/cli/aztec-cli | 55 +++++++++++--------------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/yarn-project/cli/aztec-cli b/yarn-project/cli/aztec-cli index 381322430491..43eb689f44cd 100755 --- a/yarn-project/cli/aztec-cli +++ b/yarn-project/cli/aztec-cli @@ -97,15 +97,12 @@ function add_mount() { AZTEC_CLI_COMMAND="$1" AZTEC_CLI_EXTRA_ARGS="" -# first process commands with positional arguments -# assumes positional arguments are the first thing -if [[ "$AZTEC_CLI_COMMAND" == "compile" || "$AZTEC_CLI_COMMAND" == "deploy" || "$AZTEC_CLI_COMMAND" == "inspect-contract" ]]; then - add_mount "$2" -fi - # aztec-cli unbox Token my_token_contract # if my_token_contract is missing then pass current folder if [[ "$AZTEC_CLI_COMMAND" == "unbox" ]]; then + # 2nd parameter is the contract name + # 3rd is the directory to unbox in + # this directory might not exist DIR="${3:-$PWD}" if [[ ! -d "$DIR" ]]; then @@ -120,39 +117,19 @@ if [[ "$AZTEC_CLI_COMMAND" == "update" ]]; then add_mount "$PWD" fi -# process flags -if [[ "$AZTEC_CLI_COMMAND" == "compile" || "$AZTEC_CLI_COMMAND" == "call" || "$AZTEC_CLI_COMMAND" == "send" ]]; then - - # bash's builtin getops only works with single characeter flags - # GNU getopt doesn't exist on macOS - # process the flags manually - # NOTE: this won't work with assignement-style flags, e.g. --outdir=/foo - for (( i=2; i <= "$#"; i++ )); do - arg_value=${!i} - next_index=$((i+1)) - # edge case: odd number of flags - if [[ "$next_index" -gt "$#" ]]; then - continue - fi - next_arg=${!next_index} - case $arg_value in - -o | --outdir) - add_mount "$next_arg" - ;; - -ts | --typescript) - add_mount "$next_arg" - ;; - -i | --interface) - add_mount "$next_arg" - ;; - -c | --contract-artifact) - add_mount "$next_arg" - ;; - *) - ;; - esac - done -fi +# bash's builtin getops only works with single characeter flags +# GNU getopt doesn't exist on macOS +# process the flags manually +# +# go through each parameter (execpt the first one, which is the command) +# and check if it's either a filename or a directory. If it is then mount inside the container +# NOTE: this won't work with assignement-style flags, e.g. --outdir=/foo +for (( i=2; i <= "$#"; i++ )); do + arg_value=${!i} + if [[ -f "$arg_value" || -d "$arg_value" ]]; then + add_mount "$arg_value" + fi +done if [[ "$AZTEC_CLI_COMMAND" == "compile" ]]; then # can't use Nargo inside the container From 2e434124437cf6f992d149f6aa1fe033e5894118 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 31 Oct 2023 14:32:18 +0000 Subject: [PATCH 2/5] fix: aztec-cli handle args with escape sequences For commands like `compute-selector` which take arguments with reserved characters, the bash wrapper script required callers to triple escape characters, e.g. what normally would have been aztec-cli compute-selector foo\(Field\) using the `eval $DOCKER_CMD` approach required: aztec-cli computer-selector foo\\\(Field\\\) Replacing the `eval` with directly running the command fixed it. --- yarn-project/cli/aztec-cli | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/yarn-project/cli/aztec-cli b/yarn-project/cli/aztec-cli index 43eb689f44cd..d2ad4384c6db 100755 --- a/yarn-project/cli/aztec-cli +++ b/yarn-project/cli/aztec-cli @@ -145,13 +145,11 @@ fi DOCKER_VOLUME="$DOCKER_VOLUME -v cache:/cache" -DOCKER_CMD="$DOCKER_PATH run \ +$DOCKER_PATH run \ --rm \ --user $(id -u):$(id -g) \ - --workdir \"$PWD\" \ + --workdir "$PWD" \ $DOCKER_HOST \ $DOCKER_ENV \ $DOCKER_VOLUME \ - $CLI_IMAGE:$CLI_VERSION $@ $AZTEC_CLI_EXTRA_ARGS" - -eval "$DOCKER_CMD" + $CLI_IMAGE:$CLI_VERSION $@ $AZTEC_CLI_EXTRA_ARGS From ef7a69a8157e7e8451999677d7b78f879ab474f2 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 31 Oct 2023 14:36:07 +0000 Subject: [PATCH 3/5] feat: pass DEBUG env var to aztec-cli --- yarn-project/cli/aztec-cli | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/yarn-project/cli/aztec-cli b/yarn-project/cli/aztec-cli index d2ad4384c6db..3a58b32d952a 100755 --- a/yarn-project/cli/aztec-cli +++ b/yarn-project/cli/aztec-cli @@ -143,6 +143,11 @@ if [[ ! -z "${PRIVATE_KEY:-}" ]]; then DOCKER_ENV="$DOCKER_ENV -e PRIVATE_KEY=$PRIVATE_KEY" fi +# pass along the debug variable in case the dev wants to see what's happening inside the CLI +if [[ ! -z "${DEBUG:-}" ]]; then + DOCKER_ENV="$DOCKER_ENV -e DEBUG=$DEBUG" +fi + DOCKER_VOLUME="$DOCKER_VOLUME -v cache:/cache" $DOCKER_PATH run \ From 8f03ad1b3333ca6e5115e370ac56077a0dc71cfd Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 31 Oct 2023 15:22:16 +0000 Subject: [PATCH 4/5] refactor: move aztec-cli to separate script folder --- yarn-project/cli/{ => script}/aztec-cli | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename yarn-project/cli/{ => script}/aztec-cli (100%) diff --git a/yarn-project/cli/aztec-cli b/yarn-project/cli/script/aztec-cli similarity index 100% rename from yarn-project/cli/aztec-cli rename to yarn-project/cli/script/aztec-cli From f5fe901c8916353328741e5576fdcff0cadde68a Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 7 Nov 2023 10:56:08 +0000 Subject: [PATCH 5/5] refactor: move back to root folder --- yarn-project/cli/{script => }/aztec-cli | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename yarn-project/cli/{script => }/aztec-cli (100%) diff --git a/yarn-project/cli/script/aztec-cli b/yarn-project/cli/aztec-cli similarity index 100% rename from yarn-project/cli/script/aztec-cli rename to yarn-project/cli/aztec-cli