Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
d652653cbe | |||
ad1fd17aa5 | |||
4346dd607c | |||
3cd65aba50 | |||
0eb7c2716d | |||
c89db83a59 | |||
9e96f32e5f | |||
5b35b92963 | |||
4981f60ed9 | |||
017ba8156e | |||
554ce3534a |
14
Dockerfile
14
Dockerfile
@ -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" ]
|
||||
|
31
README.md
31
README.md
@ -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
|
||||
```
|
||||
|
38
plugin.sh
38
plugin.sh
@ -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:-}
|
||||
|
Reference in New Issue
Block a user