10 Commits
0.1.0 ... 0.2.1

Author SHA1 Message Date
ad1fd17aa5 Fix handling of long username/password
Apparently the busybox implementation of `base64` will line-wrap long output strings.
This meant that long username+password combinations could produce base64 that
contained spurious "\n" characters, which then led to:
```
2019/05/06 00:47:39 Unable to parse "/kaniko/.docker/config.json": invalid character '\n' in string literal
```

Fixed by just removing the newlines in base64 output.  A "better" solution would use a different base64
implementation that avoided line-wrapping in the first place.
2019-05-06 09:16:50 +02:00
4346dd607c fix user name in dockerfile 2019-01-09 09:39:14 +01:00
3cd65aba50 add support for dockerfile build target 2019-01-09 09:39:14 +01:00
0eb7c2716d change how to handle the cache setting 2019-01-09 09:39:14 +01:00
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 60 additions and 23 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 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 | tr -d "\n"`
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,31 @@ 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(" ")'`
if [[ -n "${PLUGIN_TARGET:-}" ]]; then
TARGET="--target=${PLUGIN_TARGET}"
fi
if [[ "${PLUGIN_CACHE:-}" == "true" ]]; then
CACHE="--cache=true"
fi
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} \
${DESTINATIONS} \
${CACHE:-} \
${TARGET:-} \
${BUILD_ARGS:-}