Skip to content

Commit

Permalink
fix/docker-tag-args split (#179)
Browse files Browse the repository at this point in the history
* fix: set IFS to null when updating DOCKER_TAGS_ARG

* ci: add test

* chore: code cleanup

---------

Co-authored-by: Micah van der Kolk <[email protected]>
Co-authored-by: Kyle a.k.a. TechSquidTV <[email protected]>
  • Loading branch information
3 people authored Mar 1, 2023
1 parent dcb1c8c commit 44f6295
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
19 changes: 18 additions & 1 deletion .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions src/examples/with-bash-substitution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
description: >
Build/publish a Docker image bash substitution
usage:
version: 2.1

orbs:
docker: circleci/[email protected]

workflows:
build-docker-image-only:
jobs:
- docker/publish:
image: ${CIRCLE_PROJECT_USERNAME,,}/${CIRCLE_PROJECT_REPONAME/_/-}
tag: ${CIRCLE_SHA1:0:10}
2 changes: 2 additions & 0 deletions src/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}

Expand Down
1 change: 0 additions & 1 deletion test3.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 44f6295

Please sign in to comment.