6 Commits
0.1.0 ... 0.2.0

Author SHA1 Message Date
c89db83a59 Merge pull request #4 from banzaicloud/rename
Rename to drone-kaniko
2019-01-08 12:03:55 +01:00
9e96f32e5f Rename to drone-kaniko 2019-01-08 11:51:32 +01:00
5b35b92963 allow for multiple tags 2019-01-08 11:46:39 +01:00
4981f60ed9 update README.md with drone 1.0 example 2019-01-08 11:46:39 +01:00
017ba8156e work correctly for non-alpine based Dockerfiles 2019-01-08 11:46:39 +01:00
554ce3534a allow registry to be set 2019-01-08 11:46:39 +01:00
3 changed files with 54 additions and 22 deletions

View File

@ -1,17 +1,11 @@
FROM gcr.io/kaniko-project/executor:v0.7.0 AS kaniko
FROM gcr.io/kaniko-project/executor:debug-v0.7.0
FROM alpine:3.8
# clone the official kaniko container into this one, env vars needs to be re-set
COPY --from=kaniko / /
ENV HOME /root
ENV USER /root
ENV SSL_CERT_DIR=/kaniko/ssl/certs
ENV DOCKER_CONFIG /kaniko/.docker/
ENV DOCKER_CREDENTIAL_GCR_CONFIG /kaniko/.config/gcloud/docker_credential_gcr_config.json
RUN apk add --update --no-cache jq
# add the wrapper which acts as a drone plugin
COPY plugin.sh /usr/bin/
ENTRYPOINT [ "/usr/bin/plugin.sh" ]
COPY plugin.sh /kaniko/plugin.sh
ENTRYPOINT [ "/kaniko/plugin.sh" ]

View File

@ -1,11 +1,34 @@
# kaniko-plugin
# drone-kaniko
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
```yaml
kind: pipeline
name: default
steps:
- name: publish
image: banzaicloud/drone-kaniko
settings:
registry: registry.example.com
repo: registry.example.com/example-project
tags: ${DRONE_COMMIT_SHA}
cache: true
build_args:
- COMMIT_SHA=${DRONE_COMMIT_SHA}
- COMMIT_AUTHOR_EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL}
username:
from_secret: docker-username
password:
from_secret: docker-password
```
## Test that it can build
```bash
docker run -it --rm -w /src -v $PWD:/src -e DOCKER_USERNAME=${DOCKER_USERNAME} -e DOCKER_PASSWORD=${DOCKER_PASSWORD} -e PLUGIN_REPO=banzaicloud/kaniko-plugin-test -e PLUGIN_TAGS=test -e PLUGIN_DOCKERFILE=Dockerfile.test banzaicloud/kaniko-plugin
docker run -it --rm -w /src -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 banzaicloud/drone-kaniko
```
## Test that caching works
@ -24,7 +47,7 @@ Add the following lines to plugin.sh's final command and build a new image from
```
```bash
docker build -t banzaicloud/kaniko-plugin .
docker build -t banzaicloud/drone-kaniko .
```
@ -38,5 +61,5 @@ docker run -v $PWD:/cache gcr.io/kaniko-project/warmer:latest --image=alpine:3.8
Run the builder on the host network to be able to access the registry:
```bash
docker run --net=host -it --rm -w /src -v $PWD:/cache -v $PWD:/src -e DOCKER_USERNAME=${DOCKER_USERNAME} -e DOCKER_PASSWORD=${DOCKER_PASSWORD} -e PLUGIN_REPO=banzaicloud/kaniko-plugin-test -e PLUGIN_TAGS=test -e PLUGIN_DOCKERFILE=Dockerfile.test banzaicloud/kaniko-plugin
docker run --net=host -it --rm -w /src -v $PWD:/cache -v $PWD:/src -e DOCKER_USERNAME=${DOCKER_USERNAME} -e DOCKER_PASSWORD=${DOCKER_PASSWORD} -e PLUGIN_REPO=banzaicloud/drone-kaniko-test -e PLUGIN_TAGS=test -e PLUGIN_DOCKERFILE=Dockerfile.test banzaicloud/drone-kaniko
```

View File

@ -1,15 +1,17 @@
#!/bin/sh
#!/busybox/sh
set -euo pipefail
export PATH=$PATH:/kaniko/
DOCKER_AUTH=`echo -n "${DOCKER_USERNAME}:${DOCKER_PASSWORD}" | base64`
DOCKER_AUTH=`echo -n "${PLUGIN_USERNAME}:${PLUGIN_PASSWORD}" | base64`
REGISTRY=${PLUGIN_REGISTRY:-https://index.docker.io/v1/}
cat > /kaniko/.docker/config.json <<DOCKERJSON
{
"auths": {
"https://index.docker.io/v1/": {
"${REGISTRY}": {
"auth": "${DOCKER_AUTH}"
}
}
@ -17,13 +19,26 @@ cat > /kaniko/.docker/config.json <<DOCKERJSON
DOCKERJSON
DOCKERFILE=${PLUGIN_DOCKERFILE:-Dockerfile}
DESTINATION=${PLUGIN_REPO}:${PLUGIN_TAGS:-latest}
CONTEXT=${PLUGIN_CONTEXT:-$PWD}
LOG=${PLUGIN_LOG:-info}
BUILD_ARGS=`echo ${PLUGIN_BUILD_ARGS:-} | jq -r 'map("--build-arg " + .) | join(" ")'`
case "${PLUGIN_CACHE:-}" in
true) CACHE="true" ;;
*) CACHE="false" ;;
esac
if [[ -n "${PLUGIN_BUILD_ARGS:-}" ]]; then
BUILD_ARGS=$(echo "${PLUGIN_BUILD_ARGS}" | tr ',' '\n' | while read build_arg; do echo "--build-arg=${build_arg}"; done)
fi
if [[ -n "${PLUGIN_TAGS:-}" ]]; then
DESTINATIONS=$(echo "${PLUGIN_TAGS}" | tr ',' '\n' | while read tag; do echo "--destination=${PLUGIN_REPO}:${tag} "; done)
else
DESTINATIONS="--destination=${PLUGIN_REPO}:latest"
fi
/kaniko/executor -v ${LOG} \
--context ${CONTEXT} \
--dockerfile ${DOCKERFILE} \
--destination ${DESTINATION} \
${BUILD_ARGS}
--context=${CONTEXT} \
--dockerfile=${DOCKERFILE} \
--cache=${CACHE} \
${DESTINATIONS} \
${BUILD_ARGS:-}