Skip to content

Commit

Permalink
Update management of parameters with multiple arguments to be able to…
Browse files Browse the repository at this point in the history
… manage values with spaces (#196)
  • Loading branch information
marboledacci authored Sep 16, 2024
1 parent ac2f5c4 commit 92f84b5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
12 changes: 12 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ orbs:
orb-tools: circleci/[email protected]

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:
Expand Down Expand Up @@ -305,6 +316,7 @@ jobs:
workflows:
test-deploy:
jobs:
- build-multispace-args
- docker/hadolint:
name: hadolint
ignore-rules: DL4005,DL3008,DL3009,DL3015,DL3059
Expand Down
15 changes: 4 additions & 11 deletions src/commands/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -116,16 +118,6 @@ steps:
dockerfile: <<parameters.path>>/<<parameters.dockerfile>>
debug: <<parameters.debug>>

- when:
condition: <<parameters.use-buildkit>>
steps:
- run: echo 'export DOCKER_BUILDKIT=1' >> $BASH_ENV

- when:
condition: <<parameters.extra_build_args>>
steps:
- run: echo 'PARAM_EXTRA_BUILD_ARGS="<<parameters.extra_build_args>>"' >> $BASH_ENV

- when:
condition: <<parameters.attach-at>>
steps:
Expand All @@ -136,6 +128,7 @@ steps:
name: <<parameters.step-name>>
no_output_timeout: << parameters.no_output_timeout >>
environment:
EXTRA_BUILD_ARGS: <<parameters.extra_build_args>>
PARAM_CACHE_FROM: <<parameters.cache_from>>
PARAM_CACHE_TO: <<parameters.cache_to>>
PARAM_DOCKER_CONTEXT: <<parameters.docker-context>>
Expand Down
2 changes: 1 addition & 1 deletion src/examples/with-extra-build-args.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/jobs/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

DOCKER_TAGS_ARG=""

parse_tags_to_docker_arg() {
Expand Down Expand Up @@ -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
Expand All @@ -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"

0 comments on commit 92f84b5

Please sign in to comment.