Drone plugin for building and publishing Docker images using kaniko + personal patches
Go to file
surtur ab07d57e85
All checks were successful
continuous-integration/drone/push Build is passing
Merge remote-tracking branch 'upstream/main' into merge-main
2022-03-26 17:15:57 +01:00
.github Working kaniko publish to docker 2020-11-16 23:41:59 +05:30
cmd Merge remote-tracking branch 'upstream/main' into merge-main 2022-03-26 17:15:57 +01:00
docker Merge remote-tracking branch 'upstream/main' into merge-main 2022-03-26 17:15:57 +01:00
pkg Port the auto tag feature from docker plugin (#36) 2022-02-10 13:06:14 +05:30
scripts feat: build {amd64,pure docker} only 2021-05-02 01:15:12 +02:00
.drone.yml Merge remote-tracking branch 'upstream/main' into merge-main 2022-03-26 17:15:57 +01:00
.gitignore Add ECR policy management support (#26) 2021-09-08 15:19:52 +05:30
go.mod Merge remote-tracking branch 'upstream/main' into merge-main 2022-03-26 17:15:57 +01:00
go.sum Merge remote-tracking branch 'upstream/main' into merge-main 2022-03-26 17:15:57 +01:00
kaniko_test.go Fix the broken link in readme (#38) 2022-02-10 18:36:36 +05:30
kaniko.go Merge remote-tracking branch 'upstream/main' into merge-main 2022-03-26 17:15:57 +01:00
LICENSE Initial kaniko docker 2020-11-16 23:07:13 +05:30
README.md Merge remote-tracking branch 'upstream/main' into merge-main 2022-03-26 17:15:57 +01:00

drone-kaniko

Note: this is a remote working branch of https://github.com/drone/drone-kaniko
with my personal changes on top. GH would call it a "fork".
Development occurs in the dev branch while the main branch remains a
perfect clone of the remote main (as long as I keep it updated).

Drone kaniko plugin uses kaniko to build and publish Docker images to a container registry.

Build

Build the binaries with the following commands:

export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on

go build -v -a -tags netgo -o release/linux/amd64/kaniko-docker ./cmd/kaniko-docker
go build -v -a -tags netgo -o release/linux/amd64/kaniko-gcr ./cmd/kaniko-gcr
go build -v -a -tags netgo -o release/linux/amd64/kaniko-ecr ./cmd/kaniko-ecr

Docker

Build the Docker images with the following commands:

docker build \
  --label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
  --label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \
  --file docker/docker/Dockerfile.linux.amd64 --tag plugins/kaniko .

docker build \
  --label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
  --label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \
  --file docker/gcr/Dockerfile.linux.amd64 --tag plugins/kaniko-gcr .

docker build \
  --label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
  --label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \
  --file docker/ecr/Dockerfile.linux.amd64 --tag plugins/kaniko-ecr .

Usage

Manual Tagging

docker run --rm \
    -e PLUGIN_TAGS=1.2,latest \
    -e PLUGIN_DOCKERFILE=/drone/Dockerfile \
    -e PLUGIN_REPO=foo/bar \
    -e PLUGIN_USERNAME=foo \
    -e PLUGIN_PASSWORD=bar \
    -v $(pwd):/drone \
    -w /drone \
    plugins/kaniko:linux-amd64

With expanded tagging enabled, semantic versions can be passed to PLUGIN_TAGS directly for expansion.

Note: this feature only works for build labels. Artifact labels are not supported.

docker run --rm \
    -e PLUGIN_TAGS=v1.2.3,latest \
    -e PLUGIN_EXPAND_TAG=true \
    -v $(pwd):/drone \
    -w /drone \
    plugins/kaniko:linux-amd64

would both be equivalent to

PLUGIN_TAGS=1,1.2,1.2.3,latest

This allows for passing $DRONE_TAG directly as a tag for repos that use semver tags.

To avoid confusion between repo tags and image tags, PLUGIN_EXPAND_TAG also recognizes a semantic version without the v prefix. As such, the following is also equivalent to the above:

docker run --rm \
    -e PLUGIN_TAGS=1.2.3,latest \
    -e PLUGIN_EXPAND_TAG=true \
    -v $(pwd):/drone \
    -w /drone \
    plugins/kaniko:linux-amd64

Auto Tagging

The auto tag feature of docker plugin is also supported.

When auto tagging is enabled, if any of the case is matched below, a docker build will be pushed with auto generated tags. Otherwise the docker build will be skipped.

Note: this feature only works for build labels. Artifact labels are not supported.

Git Tag Push:

docker run --rm \
    -e DRONE_COMMIT_REF=refs/tags/v1.2.3 \
    -e PLUGIN_REPO=foo/bar \
    -e PLUGIN_USERNAME=foo \
    -e PLUGIN_PASSWORD=bar \
    -e PLUGIN_AUTO_TAG=true \
    -v $(pwd):/drone \
    -w /drone \
    plugins/kaniko:linux-amd64

Tags to push:

  • 1.2.3
  • 1.2
  • 1

Git Commit Push in default branch:

docker run --rm \
    -e DRONE_COMMIT_REF=refs/heads/master \
    -e DRONE_REPO_BRANCH=main \
    -e PLUGIN_REPO=foo/bar \
    -e PLUGIN_USERNAME=foo \
    -e PLUGIN_PASSWORD=bar \
    -e PLUGIN_AUTO_TAG=true \
    -v $(pwd):/drone \
    -w /drone \
    plugins/kaniko:linux-amd64

Tags to push:

  • latest