diff --git a/README.md b/README.md index 66883ba..6b54903 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A thin shim-wrapper around the official [Google Kaniko](https://cloud.google.com/blog/products/gcp/introducing-kaniko-build-container-images-in-kubernetes-and-google-container-builder-even-without-root-access) Docker image to make it behave like the [Drone Docker plugin](http://plugins.drone.io/drone-plugins/drone-docker/). -Example .drone.yml for Drone 1.0 +Example .drone.yml for Drone 1.0 (pushing to Docker Hub): ```yaml kind: pipeline @@ -25,6 +25,23 @@ steps: from_secret: docker-password ``` +Pushing to GCR: + +```yaml +kind: pipeline +name: default + +steps: +- name: publish + image: banzaicloud/drone-kaniko + settings: + repo: gcr.io/example.com/example-project + tags: ${DRONE_COMMIT_SHA} + cache: true + google_application_credentials: + from_secret: google-application-credentials +``` + ## Test that it can build ```bash @@ -58,8 +75,14 @@ docker run -v $PWD:/cache gcr.io/kaniko-project/warmer:latest --verbosity=debug ``` -Run the builder on the host network to be able to access the registry and the local disk cache: +Run the builder (on the host network to be able to access the registry, if any specified) with mounting the local disk cache, this example pushes to Docker Hub: ```bash docker run --net=host -it --rm -w /src -v $PWD:/cache -v $PWD:/src -e PLUGIN_USERNAME=${DOCKER_USERNAME} -e PLUGIN_PASSWORD=${DOCKER_PASSWORD} -e PLUGIN_REPO=banzaicloud/drone-kaniko-test -e PLUGIN_TAGS=test -e PLUGIN_DOCKERFILE=Dockerfile.test -e PLUGIN_CACHE=true banzaicloud/drone-kaniko ``` + +The very same example just pushing to GCR instead of Docker Hub: + +```bash +docker run --net=host -it --rm -w /src -v $PWD:/cache -v $PWD:/src -e PLUGIN_REPO=gcr.io/banzaicloud/drone-kaniko-test -e PLUGIN_TAGS=test -e PLUGIN_DOCKERFILE=Dockerfile.test -e PLUGIN_CACHE=true -e PLUGIN_GOOGLE_APPLICATION_CREDENTIALS="$(<$HOME/google-application-credentials.json)" banzaicloud/drone-kaniko +``` diff --git a/plugin.sh b/plugin.sh index 5e91eaa..2f4b9ef 100755 --- a/plugin.sh +++ b/plugin.sh @@ -4,11 +4,12 @@ set -euo pipefail export PATH=$PATH:/kaniko/ -DOCKER_AUTH=`echo -n "${PLUGIN_USERNAME}:${PLUGIN_PASSWORD}" | base64 | tr -d "\n"` +if [ "${PLUGIN_USERNAME:-}" ] || [ "${PLUGIN_PASSWORD:-}" ]; then + DOCKER_AUTH=`echo -n "${PLUGIN_USERNAME}:${PLUGIN_PASSWORD}" | base64 | tr -d "\n"` -REGISTRY=${PLUGIN_REGISTRY:-https://index.docker.io/v1/} + REGISTRY=${PLUGIN_REGISTRY:-https://index.docker.io/v1/} -cat > /kaniko/.docker/config.json < /kaniko/.docker/config.json < /kaniko/.docker/config.json < /kaniko/gcr.json + export GOOGLE_APPLICATION_CREDENTIALS=/kaniko/gcr.json +fi DOCKERFILE=${PLUGIN_DOCKERFILE:-Dockerfile} CONTEXT=${PLUGIN_CONTEXT:-$PWD}