Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom build args/secrets #12

Open
wants to merge 1 commit into
base: production
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@ COMMIT_SHA_SHORT=$(git describe --always --tags 2>/dev/null)
DOCKER_IMAGE_PATH="gcr.io/${GCE_PROJECT}/${APP_NAME}"
DOCKER_IMAGE_TAG=$(gcloud container images list-tags ${DOCKER_IMAGE_PATH} --filter="tags=${COMMIT_SHA_SHORT}" --format=json)

DOCKER_ARGS=''
prefix='TRAVIS_BUILDARG_'
for varname in $(env | grep "^${prefix}"); do
varname=${varname/#$prefix}
DOCKER_ARGS="${DOCKER_ARGS} --build-arg $varname "
done

secret_prefix='TRAVIS_BUILDSECRET_'
for varname in $(env | grep "^${secret_prefix}" | cut -d'=' -f 1); do
envname=$varname
varname=${varname/#$secret_prefix}
DOCKER_ARGS="${DOCKER_ARGS} --secret id=$varname,env=$envname "
done

echo "Adding custom build arguments: ${DOCKER_ARGS}"

if [[ "${DOCKER_IMAGE_TAG}" == "[]" ]]; then
echo "Tag doesn't exist in gcr.io. Building image..."
gcloud docker -- pull $DOCKER_IMAGE_PATH:latest || true
if [[ "${APP_NAME}" == "travis-web" ]]; then
docker build . --secret id=GITHUB_PERSONAL_TOKEN,env=GITHUB_PERSONAL_TOKEN --build-arg bundle_gems__contribsys__com --cache-from $DOCKER_IMAGE_PATH:latest -t $DOCKER_IMAGE_PATH:$COMMIT_SHA_SHORT
docker build . --secret id=GITHUB_PERSONAL_TOKEN,env=GITHUB_PERSONAL_TOKEN --build-arg bundle_gems__contribsys__com --cache-from $DOCKER_IMAGE_PATH:latest -t $DOCKER_IMAGE_PATH:$COMMIT_SHA_SHORT $DOCKER_ARGS
else
docker build . --build-arg bundle_gems__contribsys__com --cache-from $DOCKER_IMAGE_PATH:latest -t $DOCKER_IMAGE_PATH:$COMMIT_SHA_SHORT
docker build . --build-arg bundle_gems__contribsys__com --cache-from $DOCKER_IMAGE_PATH:latest -t $DOCKER_IMAGE_PATH:$COMMIT_SHA_SHORT $DOCKER_ARGS
fi
docker tag $DOCKER_IMAGE_PATH:$COMMIT_SHA_SHORT $DOCKER_IMAGE_PATH:latest
gcloud docker -- push $DOCKER_IMAGE_PATH:$COMMIT_SHA_SHORT
Expand Down