Skip to content

Commit

Permalink
fix: evaluate and expand all orb parameters (#171)
Browse files Browse the repository at this point in the history
* feat: add utils function to expand orb parameters

* fix: import `utils.sh` to emulate behaviour before orb-tools migration

* fix: shellcheck

* ci: add test with params coming from env vars
  • Loading branch information
EricRibeiro authored Dec 5, 2022
1 parent 3d432d7 commit 253987c
Show file tree
Hide file tree
Showing 28 changed files with 152 additions and 18 deletions.
31 changes: 27 additions & 4 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ promotion_requires: &promotion_requires
filters: &filters
tags:
only: /.*/

orbs:
build-tools: circleci/[email protected]
docker: circleci/docker@dev:<<pipeline.git.revision>>
Expand Down Expand Up @@ -246,7 +246,7 @@ jobs:
- docker/install-docker
- docker/install-docker-compose:
version: << parameters.docker-compose-version>>
install-dir: << parameters.install-dir>>
install-dir: << parameters.install-dir>>

workflows:
test-deploy:
Expand Down Expand Up @@ -485,6 +485,27 @@ workflows:
docker-password: DOCKER_PASS
use-docker-credentials-store: true
filters: *filters
- docker/publish:
pre-steps:
- run:
name: Export env vars
command: |
echo 'export DOCKER_USERNAME=cpeorbtesting' >> $BASH_ENV
echo 'export DOCKER_NAME=docker-orb-test' >> $BASH_ENV
echo 'export DOCKERFILE=test.Dockerfile' >> $BASH_ENV
echo 'export REGISTRY=docker.io' >> $BASH_ENV
name: publish-docker-env-var-all-params
executor: docker-latest
context: CPE-orb-docker-testing
use-remote-docker: true
dockerfile: $DOCKERFILE
image: $DOCKER_USERNAME/$DOCKER_NAME
tag: $CIRCLE_SHA1,$CIRCLE_BUILD_NUM
docker-username: DOCKER_USER
docker-password: DOCKER_PASS
use-docker-credentials-store: true
registry: $REGISTRY
filters: *filters
# end docker/publish

# begin test-install-docker-tools
Expand All @@ -502,7 +523,7 @@ workflows:
install-goss: false
filters: *filters
# end test-install-docker-tools

# begin test
- test:
name: test-<< matrix.executor >>
Expand Down Expand Up @@ -552,4 +573,6 @@ executors:
image: ubuntu-2004:202010-01
machine-latest:
machine:
image: ubuntu-2004:current
image: ubuntu-2004:current

# VS Code Extension Version: 1.3.0
1 change: 1 addition & 0 deletions src/commands/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ steps:
PARAM_REGISTRY: <<parameters.registry>>
PARAM_TAG: <<parameters.tag>>
PARAM_USE_BUILDKIT: <<parameters.use-buildkit>>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: <<include(scripts/build.sh)>>
1 change: 1 addition & 0 deletions src/commands/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ steps:
PARAM_REGISTRY: <<parameters.registry>>
PARAM_DOCKER_USERNAME: <<parameters.docker-username>>
PARAM_DOCKER_PASSWORD: <<parameters.docker-password>>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: <<include(scripts/check.sh)>>
1 change: 1 addition & 0 deletions src/commands/configure-docker-credentials-store.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ steps:
environment:
PARAM_HELPER_NAME: "<<parameters.helper-name>>"
PARAM_DOCKER_CONFIG_PATH: "<<parameters.docker-config-path>>"
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: <<include(scripts/configure-docker-credentials-store.sh)>>
1 change: 1 addition & 0 deletions src/commands/dockerlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ steps:
PARAM_DEBUG: <<parameters.debug>>
PARAM_TREAT_WARNING_AS_ERRORS: <<parameters.treat-warnings-as-errors>>
PARAM_DOCKERFILE: <<parameters.dockerfile>>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: <<include(scripts/dockerlint.sh)>>
1 change: 1 addition & 0 deletions src/commands/hadolint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ steps:
PARAM_DOCKERFILES: <<parameters.dockerfiles>>
PARAM_IGNORE_RULES: <<parameters.ignore-rules>>
PARAM_TRUSTED_REGISTRIES: <<parameters.trusted-registries>>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: <<include(scripts/hadolint.sh)>>
1 change: 1 addition & 0 deletions src/commands/install-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ steps:
environment:
PARAM_DOCKER_COMPOSER_VERSION: << parameters.version >>
PARAM_INSTALL_DIR: <<parameters.install-dir>>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: <<include(scripts/install-docker-compose.sh)>>
1 change: 1 addition & 0 deletions src/commands/install-docker-credential-helper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ steps:
environment:
PARAM_HELPER_NAME: << parameters.helper-name >>
PARAM_RELEASE_TAG: << parameters.release-tag >>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: << include(scripts/install-docker-credential-helper.sh) >>
1 change: 1 addition & 0 deletions src/commands/install-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ steps:
environment:
PARAM_VERSION: << parameters.version >>
PARAM_INSTALL_DIR: << parameters.install-dir >>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: << include(scripts/install-docker.sh) >>
1 change: 1 addition & 0 deletions src/commands/install-dockerize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ steps:
environment:
PARAM_VERSION: << parameters.version >>
PARAM_INSTALL_DIR: << parameters.install-dir >>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: << include(scripts/install-dockerize.sh) >>
1 change: 1 addition & 0 deletions src/commands/install-goss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ steps:
PARAM_VERSION: <<parameters.version>>
PARAM_INSTALL_DIR: <<parameters.install-dir>>
PARAM_DEBUG: <<parameters.debug>>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: << include(scripts/install-goss.sh) >>
1 change: 1 addition & 0 deletions src/commands/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ steps:
environment:
PARAM_IMAGES: <<parameters.images>>
PARAM_IGNORE_DOCKER_PULL_ERROR: <<parameters.ignore-docker-pull-error>>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: << include(scripts/pull.sh) >>
1 change: 1 addition & 0 deletions src/commands/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ steps:
PARAM_IMAGE: <<parameters.image>>
PARAM_TAG: <<parameters.tag>>
PARAM_DIGEST_PATH: <<parameters.digest-path>>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: << include(scripts/push.sh) >>
1 change: 1 addition & 0 deletions src/commands/update-description.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ steps:
PARAM_IMAGE: <<parameters.image>>
PARAM_DOCKER_USERNAME: <<parameters.docker-username>>
PARAM_DOCKER_PASSWORD: <<parameters.docker-password>>
SCRIPT_UTILS: <<include(scripts/utils.sh)>>
command: << include(scripts/update-description.sh) >>
4 changes: 4 additions & 0 deletions src/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

DOCKER_TAGS_ARG=""

parse_tags_to_docker_arg() {
Expand Down
6 changes: 5 additions & 1 deletion src/scripts/check.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/usr/bin/env bash

echo "${!PARAM_DOCKER_PASSWORD}" | docker login -u "${!PARAM_DOCKER_USERNAME}" --password-stdin "$PARAM_REGISTRY"
# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

echo "${!PARAM_DOCKER_PASSWORD}" | docker login -u "${!PARAM_DOCKER_USERNAME}" --password-stdin "$PARAM_REGISTRY"
6 changes: 5 additions & 1 deletion src/scripts/configure-docker-credentials-store.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

HELPER_NAME="$PARAM_HELPER_NAME"
DOCKER_CONFIG_PATH="$(eval echo ${PARAM_DOCKER_CONFIG_PATH})"

Expand All @@ -22,4 +26,4 @@ cat "$DOCKER_CONFIG_PATH" |
>/tmp/docker-config-credsstore-update.json
cat /tmp/docker-config-credsstore-update.json > "$DOCKER_CONFIG_PATH"

rm /tmp/docker-config-credsstore-update.json
rm /tmp/docker-config-credsstore-update.json
10 changes: 7 additions & 3 deletions src/scripts/dockerlint.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

if [[ $EUID == 0 ]]; then SUDO=""; else SUDO="sudo"; fi

if ! command -v dockerlint &> /dev/null; then
if ! command -v npm &> /dev/null; then
if ! command -v npm &> /dev/null; then
echo "npm is required to install dockerlint.";
echo "Consider running this command with an image that has node available: https://circleci.com/developer/images/image/cimg/node";
echo "Consider running this command with an image that has node available: https://circleci.com/developer/images/image/cimg/node";
echo "Alternatively, use dockerlint's docker image: https://github.com/RedCoolBeans/dockerlint#docker-image."
exit 1
fi
Expand All @@ -21,4 +25,4 @@ if [ "$PARAM_TREAT_WARNING_AS_ERRORS" = true ]; then
dockerlint -f "$PARAM_DOCKERFILE" -p
else
dockerlint -f "$PARAM_DOCKERFILE"
fi
fi
8 changes: 6 additions & 2 deletions src/scripts/hadolint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

if [ -n "$PARAM_IGNORE_RULES" ]; then
ignore_rules=$(printf '%s' "--ignore ${PARAM_IGNORE_RULES//,/ --ignore }")
readonly ignore_rules
Expand All @@ -16,7 +20,7 @@ printf '%s\n' "$trusted_registries"
readonly old_ifs="$IFS"
IFS=":"

read -ra dockerfiles <<< "$PARAM_DOCKERFILES"
read -ra dockerfiles <<< "$PARAM_DOCKERFILES"
IFS="$old_ifs"

for dockerfile in "${dockerfiles[@]}"; do
Expand All @@ -26,4 +30,4 @@ for dockerfile in "${dockerfiles[@]}"; do
$dockerfile

printf '%s\n' "Success! $dockerfile linted; no issues found"
done
done
4 changes: 4 additions & 0 deletions src/scripts/install-docker-compose.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

trap_exit() {
# clean-up
printf '%s\n' "Cleaning up..."
Expand Down
6 changes: 5 additions & 1 deletion src/scripts/install-docker-credential-helper.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

HELPER_NAME="$PARAM_HELPER_NAME"

if uname | grep -q "Darwin"; then platform="darwin"
Expand Down Expand Up @@ -84,4 +88,4 @@ fi

chmod +x "./$HELPER_FILENAME"
$SUDO mv "./$HELPER_FILENAME" "$BIN_PATH/$HELPER_FILENAME"
"$BIN_PATH/$HELPER_FILENAME" version
"$BIN_PATH/$HELPER_FILENAME" version
6 changes: 5 additions & 1 deletion src/scripts/install-docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi

# grab Docker version
Expand Down Expand Up @@ -73,4 +77,4 @@ do
done

# verify version
echo "$(docker --version) has been installed to $(command -v docker)"
echo "$(docker --version) has been installed to $(command -v docker)"
6 changes: 5 additions & 1 deletion src/scripts/install-dockerize.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi

# grab dockerize version
Expand Down Expand Up @@ -45,4 +49,4 @@ $SUDO mv dockerize "$PARAM_INSTALL_DIR"
$SUDO chmod +x "$PARAM_INSTALL_DIR"/dockerize

# verify version
echo "dockerize $(dockerize --version) has been installed to $(command -v dockerize)"
echo "dockerize $(dockerize --version) has been installed to $(command -v dockerize)"
6 changes: 5 additions & 1 deletion src/scripts/install-goss.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi

# determine specified version
Expand Down Expand Up @@ -69,4 +73,4 @@ if curl --output /dev/null --silent --head --fail "$DGOSS_URL"; then
else
echo "No dgoss wrapper found for the selected version of Goss ($VERSION)..."
echo "Goss installation will proceed, but to use dgoss, please try again with a newer version"
fi
fi
6 changes: 5 additions & 1 deletion src/scripts/pull.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

echo "$PARAM_IMAGES" | sed -n 1'p' | tr ',' '\n' | while read -r image; do
echo "Pulling ${image}";

Expand All @@ -8,4 +12,4 @@ echo "$PARAM_IMAGES" | sed -n 1'p' | tr ',' '\n' | while read -r image; do
else
docker pull "${image}";
fi
done
done
6 changes: 5 additions & 1 deletion src/scripts/push.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

IFS="," read -ra DOCKER_TAGS <<< "$PARAM_TAG"

image="$(eval echo "$PARAM_IMAGE")"
Expand All @@ -17,4 +21,4 @@ if [ -n "$PARAM_DIGEST_PATH" ]; then
IFS="," read -ra DOCKER_TAGS <<< "$PARAM_TAG"
tag=$(eval echo "${DOCKER_TAGS[0]}")
docker image inspect --format="{{index .RepoDigests 0}}" "$PARAM_REGISTRY"/"$image":"$tag" > "$PARAM_DIGEST_PATH"
fi
fi
6 changes: 5 additions & 1 deletion src/scripts/update-description.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

# Import "utils.sh".
eval "$SCRIPT_UTILS"
expand_env_vars_with_prefix "PARAM_"

if [ "$PARAM_REGISTRY" != "docker.io" ]; then
echo "Registry is not set to Docker Hub. Exiting"
exit 1
Expand All @@ -20,4 +24,4 @@ if [ $STATUS -ne 200 ]; then
echo "Could not update image description"
echo "Error code: $STATUS"
exit 1
fi
fi
Loading

0 comments on commit 253987c

Please sign in to comment.