Skip to content

Commit

Permalink
fix: enable to expand env vars in extra_build_args (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymtdzzz authored Jun 13, 2022
1 parent 1697d7c commit ef1889f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ workflows:
requires: [orb-tools/publish]
filters:
tags:
only: /.*/
only: /.*/
16 changes: 15 additions & 1 deletion .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ promotion_requires: &promotion_requires
test-macos-old,
test-machine-latest,
test-machine-old,
test-build-command-workspace
test-build-command-workspace,
test-build-with-args
]

filters: &filters
Expand Down Expand Up @@ -179,6 +180,17 @@ jobs:
ls
exit 1
fi
test-build-with-args:
docker:
- image: cimg/base:stable
steps:
- checkout
- setup_remote_docker
- docker/build:
dockerfile: test3.Dockerfile
image: cpeorbtesting/docker-orb-test
tag: $CIRCLE_BUILD_NUM-$CIRCLE_SHA1
extra_build_args: --build-arg COMMIT_HASH=$CIRCLE_SHA1
test-dockerlint:
docker:
- image: cimg/node:17.7.2
Expand Down Expand Up @@ -221,6 +233,8 @@ workflows:
requires:
- test-create-workspace
filters: *filters
- test-build-with-args:
filters: *filters

# begin test-check-command
- test-check-command:
Expand Down
6 changes: 5 additions & 1 deletion src/commands/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ steps:
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 @@ -126,7 +131,6 @@ steps:
PARAM_DOCKER_CONTEXT: <<parameters.docker-context>>
PARAM_DOCKERFILE_NAME: <<parameters.dockerfile>>
PARAM_DOCKERFILE_PATH: <<parameters.path>>
PARAM_EXTRA_BUILD_ARGS: <<parameters.extra_build_args>>
PARAM_IMAGE: <<parameters.image>>
PARAM_REGISTRY: <<parameters.registry>>
PARAM_TAG: <<parameters.tag>>
Expand Down
22 changes: 22 additions & 0 deletions test3.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# vim:set ft=dockerfile:
#
# The Ubuntu-based CircleCI Docker Image. Only use Ubuntu Long-Term Support
# (LTS) releases.

FROM ubuntu:18.04

LABEL maintainer="CircleCI <[email protected]>"

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 \
echo "Error: COMMIT_HASH is invalid commit hash"; \
exit 1; \
fi

WORKDIR /root/project

0 comments on commit ef1889f

Please sign in to comment.