From 92f84b568878248419879d889f714729cb522c48 Mon Sep 17 00:00:00 2001 From: marboledacci Date: Mon, 16 Sep 2024 08:16:06 -0500 Subject: [PATCH] Update management of parameters with multiple arguments to be able to manage values with spaces (#196) --- .circleci/test-deploy.yml | 12 ++++++++++++ src/commands/build.yml | 15 ++++----------- src/examples/with-extra-build-args.yml | 2 +- src/jobs/publish.yml | 2 ++ src/scripts/build.sh | 12 +++++------- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index f3e8fd5..53b3534 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -56,6 +56,17 @@ orbs: orb-tools: circleci/orb-tools@11.1 jobs: + build-multispace-args: + machine: + image: ubuntu-2004:current + steps: + - checkout + - docker/install-docker + - docker/build: + dockerfile: test3.Dockerfile + image: docker-orb-test-temporal + tag: tempora-test + extra_build_args: --build-arg=COMMIT_HASH=$CIRCLE_SHA1 --build-arg=CARG='i am a good parameter' --build-arg=DATE=$(date +%F) test: parameters: executor: @@ -305,6 +316,7 @@ jobs: workflows: test-deploy: jobs: + - build-multispace-args - docker/hadolint: name: hadolint ignore-rules: DL4005,DL3008,DL3009,DL3015,DL3059 diff --git a/src/commands/build.yml b/src/commands/build.yml index b03f756..a6a8c56 100644 --- a/src/commands/build.yml +++ b/src/commands/build.yml @@ -52,7 +52,9 @@ parameters: default: "" description: > Extra flags to pass to docker build. For examples, see - https://docs.docker.com/engine/reference/commandline/build + https://docs.docker.com/engine/reference/commandline/build. + Pass the desired args using an equal sign (=) instead of an space. + For example, --build-arg=ARG1=value, instead of --build-arg ARG1=vallue. cache_from: type: string @@ -116,16 +118,6 @@ steps: dockerfile: <>/<> debug: <> - - when: - condition: <> - steps: - - run: echo 'export DOCKER_BUILDKIT=1' >> $BASH_ENV - - - when: - condition: <> - steps: - - run: echo 'PARAM_EXTRA_BUILD_ARGS="<>"' >> $BASH_ENV - - when: condition: <> steps: @@ -136,6 +128,7 @@ steps: name: <> no_output_timeout: << parameters.no_output_timeout >> environment: + EXTRA_BUILD_ARGS: <> PARAM_CACHE_FROM: <> PARAM_CACHE_TO: <> PARAM_DOCKER_CONTEXT: <> diff --git a/src/examples/with-extra-build-args.yml b/src/examples/with-extra-build-args.yml index ce32bd1..b2adb63 100644 --- a/src/examples/with-extra-build-args.yml +++ b/src/examples/with-extra-build-args.yml @@ -12,4 +12,4 @@ usage: jobs: - docker/publish: image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME - extra_build_args: --build-arg FOO=bar --build-arg BAZ=qux + extra_build_args: --build-arg=FOO=bar --build-arg=BAZ=qux diff --git a/src/jobs/publish.yml b/src/jobs/publish.yml index 9fec9be..0e56454 100644 --- a/src/jobs/publish.yml +++ b/src/jobs/publish.yml @@ -90,6 +90,8 @@ parameters: description: > Extra flags to pass to docker build. For examples, see https://docs.docker.com/engine/reference/commandline/build + Pass the desired args using an equal sign (=) instead of an space. + For example, --build-arg=ARG1=value, instead of --build-arg ARG1=vallue. cache_from: type: string diff --git a/src/scripts/build.sh b/src/scripts/build.sh index b2daebc..5aae559 100644 --- a/src/scripts/build.sh +++ b/src/scripts/build.sh @@ -3,7 +3,6 @@ # Import "utils.sh". eval "$SCRIPT_UTILS" expand_env_vars_with_prefix "PARAM_" - DOCKER_TAGS_ARG="" parse_tags_to_docker_arg() { @@ -54,12 +53,12 @@ fi build_args=( "--file=$PARAM_DOCKERFILE_PATH/$PARAM_DOCKERFILE_NAME" - "$DOCKER_TAGS_ARG" ) -if [ -n "$PARAM_EXTRA_BUILD_ARGS" ]; then - extra_build_args="$(eval echo "$PARAM_EXTRA_BUILD_ARGS")" - build_args+=("$extra_build_args") +eval 'for t in '$DOCKER_TAGS_ARG'; do build_args+=("$t"); done' + +if [ -n "$EXTRA_BUILD_ARGS" ]; then + eval 'for p in '$EXTRA_BUILD_ARGS'; do build_args+=("$p"); done' fi if [ -n "$PARAM_CACHE_FROM" ]; then @@ -79,8 +78,7 @@ old_ifs="$IFS" IFS=' ' set -x -# shellcheck disable=SC2048 # We want word splitting here. -docker buildx build ${build_args[*]} +docker buildx build "${build_args[@]}" set +x IFS="$old_ifs"