Skip to content

Instantly share code, notes, and snippets.

@zimbatm
Created May 25, 2021 11:32
Show Gist options
  • Save zimbatm/34fa747aae09ed0c3e788129a878d841 to your computer and use it in GitHub Desktop.
Save zimbatm/34fa747aae09ed0c3e788129a878d841 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# A small bash wrapper to kaniko with a few assumptions built in.
set -euo pipefail
context=$1
dockerfile=$2
destination=$3
cache=true
cache_repo=$(echo "$destination" | cut -d : -f 1)-cache
shift 3
kaniko_args=(
--dockerfile="${dockerfile}"
--destination="${destination}"
--context=dir:///workspace/
--cache="${cache}"
# ECR doesn't support sub-names so we need a second registry for the cache
--cache-repo="${cache_repo}"
)
# Build
docker run \
-v "${context}":/workspace \
-v "$HOME"/.docker/config.json:/kaniko/.docker/config.json:ro \
gcr.io/kaniko-project/executor:latest \
"${kaniko_args[@]}" \
"$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment