From 44f62951b0951e9765dc90e9355a00990170199b Mon Sep 17 00:00:00 2001 From: Brian Vu <64455338+brivu@users.noreply.github.com> Date: Wed, 1 Mar 2023 11:04:33 -0800 Subject: [PATCH] fix/docker-tag-args split (#179) * fix: set IFS to null when updating DOCKER_TAGS_ARG * ci: add test * chore: code cleanup --------- Co-authored-by: Micah van der Kolk Co-authored-by: Kyle a.k.a. TechSquidTV <33272306+KyleTryon@users.noreply.github.com> --- .circleci/test-deploy.yml | 19 ++++++++++++++++++- src/examples/with-bash-substitution.yml | 15 +++++++++++++++ src/scripts/build.sh | 2 ++ test3.Dockerfile | 1 - 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/examples/with-bash-substitution.yml diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index caebb45..8d8f638 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -39,7 +39,8 @@ promotion_requires: &promotion_requires test-machine-latest, test-machine-old, test-build-command-workspace, - test-build-with-args + test-build-with-args, + test-build-bash-substitution ] filters: &filters @@ -209,6 +210,20 @@ jobs: image: cpeorbtesting/docker-orb-test tag: $CIRCLE_BUILD_NUM-$CIRCLE_SHA1 extra_build_args: --build-arg COMMIT_HASH=$CIRCLE_SHA1 + test-build-bash-substitution: + docker: + - image: cimg/base:current + environment: + DOCKER_ACCOUNT: CPEOrbTesting + DOCKER_REPO: docker_orb_test + steps: + - checkout + - setup_remote_docker + - docker/build: + dockerfile: test3.Dockerfile + image: ${DOCKER_ACCOUNT,,}/${DOCKER_REPO,,/_/-} + tag: ${CIRCLE_BUILD_NUM,,}-${CIRCLE_SHA1:0:10} + extra_build_args: --build-arg COMMIT_HASH=$CIRCLE_SHA1 test-dockerlint: docker: - image: cimg/node:17.7.2 @@ -307,6 +322,8 @@ workflows: filters: *filters - test-build-with-args: filters: *filters + - test-build-bash-substitution: + filters: *filters # begin test-install-docker-compose - test-install-docker-compose: diff --git a/src/examples/with-bash-substitution.yml b/src/examples/with-bash-substitution.yml new file mode 100644 index 0000000..e49d215 --- /dev/null +++ b/src/examples/with-bash-substitution.yml @@ -0,0 +1,15 @@ +description: > + Build/publish a Docker image bash substitution + +usage: + version: 2.1 + + orbs: + docker: circleci/docker@x.y.z + + workflows: + build-docker-image-only: + jobs: + - docker/publish: + image: ${CIRCLE_PROJECT_USERNAME,,}/${CIRCLE_PROJECT_REPONAME/_/-} + tag: ${CIRCLE_SHA1:0:10} diff --git a/src/scripts/build.sh b/src/scripts/build.sh index 55daf7c..d49167e 100644 --- a/src/scripts/build.sh +++ b/src/scripts/build.sh @@ -23,6 +23,8 @@ parse_tags_to_docker_arg() { fi done + # Set IFS to null to stop "," from breaking bash substitution + local IFS= DOCKER_TAGS_ARG="$(eval echo $docker_arg)" } diff --git a/test3.Dockerfile b/test3.Dockerfile index e0d8db5..cdc9a11 100644 --- a/test3.Dockerfile +++ b/test3.Dockerfile @@ -11,7 +11,6 @@ ARG COMMIT_HASH # Change default shell from Dash to Bash RUN rm /bin/sh && ln -s /bin/bash /bin/sh - RUN if [[ "${COMMIT_HASH}" =~ ^[0-9a-f]{5,40}$ ]]; then \ echo "Success: COMMIT_HASH is valid commit hash"; \ else \