Last active
March 28, 2018 14:22
-
-
Save norrs/34f25e6dd02cf5f7805d925f2663ab46 to your computer and use it in GitHub Desktop.
Wrap the original container-builder-local so we can use cloudbuild.yaml files with COMMIT_SHA.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Wrapper around container-builder-local to deal with annoying missing features. | |
# Missing global subtituions by tool: | |
# COMMIT_SHA not being available. | |
command -v container-builder-local >/dev/null 2>&1 || { echo -e >&2 "I require container-builder-local but it's not installed. Aborting.\\nhttps://github.com/GoogleCloudPlatform/container-builder-local#install-using-gcloud"; exit 1; } | |
command -v envsubst >/dev/null 2>&1 || { echo >&2 "I require envsubst but it's not installed. Aborting."; exit 1; } | |
die() { | |
printf '%s\n' "$1" >&2 | |
exit 1 | |
} | |
wrapper_usage() { | |
printf 'Extra wrapper options for container-builder-local:\n' | |
# shellcheck disable=SC2016 | |
printf ' --commit-sha=<string> [default: git rev-parse --short HEAD in $PWD (%s)]\n\n' "$PWD" | |
} | |
args=( ) | |
config_value= | |
commit_sha= | |
while :; do | |
case $1 in | |
-h|-help|--help) | |
wrapper_usage | |
args+=( "$1" ) | |
;; | |
--commit-sha) | |
if [ "$2" ]; then | |
commit_sha=$2 | |
shift | |
else | |
die 'ERROR: "--commit-sha" requires a non-empty option argument.' | |
fi | |
;; | |
--commit-sha=?*) | |
commit_sha=${1#*=} | |
;; | |
--commit-sha=) | |
die 'ERROR: "--commit-sha" requires a non-empty option argument.' | |
;; | |
-config|--config) | |
if [ "$2" ]; then | |
config_value=$2 | |
shift | |
fi | |
;; | |
-config=?*|--config=?*) | |
config_value=${1#*=} | |
;; | |
-config=|--config=) | |
die 'ERROR: "--config" requires a non-empty option argument.' | |
;; | |
--) # End of all options. | |
shift | |
break | |
;; | |
*) # Default case: No more options, so break out of the loop. | |
break | |
esac | |
shift | |
done | |
if [ -n "$config_value" ]; then | |
test -n "$commit_sha" || commit_sha="$(git rev-parse --short HEAD)" | |
echo container-builder-local "${args[@]}" --config "<(COMMIT_SHA=${commit_sha} envsubst '\${COMMIT_SHA}' < \"$config_value\")" "$@" | |
container-builder-local "${args[@]}" --config <(COMMIT_SHA=${commit_sha} envsubst "\${COMMIT_SHA}" < "$config_value") "$@" | |
else | |
container-builder-local "${args[@]}" "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment