GithubHelp home page GithubHelp logo

banzaicloud / drone-kaniko Goto Github PK

View Code? Open in Web Editor NEW
56.0 6.0 74.0 24 KB

A thin shim-wrapper around the official Google Kaniko Docker image to make it behave like the Drone Docker plugin.

License: Apache License 2.0

Dockerfile 9.89% Shell 90.11%

drone-kaniko's Introduction

drone-kaniko

A thin shim-wrapper around the official Google Kaniko Docker image to make it behave like the Drone Docker plugin.

Example .drone.yml for Drone 1.0 (pushing to Docker Hub):

kind: pipeline
name: default

steps:
- name: publish
  image: banzaicloud/drone-kaniko
  settings:
    registry: registry.example.com # if not provided index.docker.io is supposed
    repo: registry.example.com/example-project
    tags: ${DRONE_COMMIT_SHA}
    cache: true
    skip_tls_verify: false # set to true for testing registries ONLY with self-signed certs
    build_args:
    - COMMIT_SHA=${DRONE_COMMIT_SHA}
    - COMMIT_AUTHOR_EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL}
    username:
      from_secret: docker-username
    password:
      from_secret: docker-password

Pushing to GCR:

kind: pipeline
name: default

steps:
- name: publish
  image: banzaicloud/drone-kaniko
  settings:
    registry: gcr.io
    repo: example.com/example-project
    tags: ${DRONE_COMMIT_SHA}
    cache: true
    json_key:
      from_secret: google-application-credentials

Use .tags file for tagging

Similarily to official drone-docker plugin you can use .tags file to embed some custom logic for creating tags for an image.

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
      - go get 
      - go build
      - make versiontags > .tags
- name: publish
  image: banzaicloud/drone-kaniko
  settings:
    registry: registry.example.com 
    repo: registry.example.com/example-project
    # tags: ${DRONE_COMMIT_SHA} <= it must be left undefined 
    username:
      from_secret: docker-username
    password:
      from_secret: docker-password

Auto tag

Set auto_tag: true.

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
      - go get 
      - go build
- name: publish
  image: banzaicloud/drone-kaniko
  settings:
    registry: registry.example.com 
    repo: registry.example.com/example-project
    auto_tag: true # higher priority then .tags file
    # tags: ${DRONE_COMMIT_SHA} <= it must be left undefined to use auto_tag
    username:
      from_secret: docker-username
    password:
      from_secret: docker-password

Test that it can build

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

Start a Docker registry at 127.0.0.1:5000:

docker run -d -p 5000:5000 --restart always --name registry --hostname registry.local registry:2

Add the following lines to plugin.sh's final command and build a new image from it:

+    --cache=true \
+    --cache-repo=127.0.0.1:5000/${PLUGIN_REPO} \
docker build -t banzaicloud/drone-kaniko .

Warm up the alpine image to the cache:

docker run -v $PWD:/cache gcr.io/kaniko-project/warmer:latest --verbosity=debug --image=alpine:3.8

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:

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:

docker run --net=host -it --rm -w /src -v $PWD:/cache -v $PWD:/src -e PLUGIN_REGISTRY=gcr.io -e PLUGIN_REPO=paas-dev1/drone-kaniko-test -e PLUGIN_TAGS=test -e PLUGIN_DOCKERFILE=Dockerfile.test -e PLUGIN_CACHE=true -e PLUGIN_JSON_KEY="$(<$HOME/google-application-credentials.json)" banzaicloud/drone-kaniko

drone-kaniko's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

drone-kaniko's Issues

Test Container Build *Without* Publishing Image

Is there a way to use this plugin to build the Docker image without publishing it, so that it can be used to validate that pull requests to the image successfully build.

BTW this is an awesome plugin and exactly what I was looking for. Now I can build my Open Source Docker images on the Drone Cloud for free! ๐Ÿ˜ƒ I created a topic on the Drone forum to help people find it.

Failing to check push permissions

Describe the bug
Recently I have seen all my builds that try to push fail with the following message:

error checking push permissions -- make sure you entered the correct tag name, and that you are authenticated correctly, and try again: checking push permission for "index.docker.io/[secret:docker_username]/flexiday:94ade237": UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:[secret:docker_username]/flexiday Type:repository] map[Action:push Class: Name:[secret:docker_username]/flexiday Type:repository]]

I wonder if this is an upstream bug?

Steps to reproduce the issue:
I was using latest (or no version tag)
Using any version above 0.5.1 will break my builds, however 0.5.1 works fine.

Expected behavior
Not break

Screenshots

Additional context

Not caching the base layer?

Describe the bug
Hi! I am trying this plugin now and have a problem. I can see that it pushes layers to Github Package Registry because it says so. However when the build starts it seems it tries to read from a local /cache directory for the first layer instead of the cache repo. I see this in the log:

INFO[0001] Resolved base name ubuntu:bionic to ubuntu:bionic
--
2 | INFO[0001] Resolved base name ubuntu:bionic to ubuntu:bionic
3 | INFO[0001] Downloading base image ubuntu:bionic
4 | 2019/10/07 17:36:07 No matching credentials were found, falling back on anonymous
5 | ย 
6 | INFO[0003] Error while retrieving image from cache: getting file info: stat /cache/sha256:1bbdea4846231d91cce6c7ff3907d26fca444fd6b7e3c282b90c7fe4251f9f86: no such file or directory
7 | INFO[0003] Downloading base image ubuntu:bionic

This means that every time it starts the build from scratch. Is there a way to avoid this and ensure that everything is cached? Thanks!

Steps to reproduce the issue:
Just set cache: true.

Expected behavior
I would expect the caching to cache the first layer as well, because otherwise the caching of following layers is very little useful.

Caching not pushing cache layers to docker hub

Hi,

I am testing this plugins with cache: true and a docker hub registry. For some reason the cache layers are not pushed to the registry but the final image is. All subsequent build are rebuilding all the layers. I noticed the following message at the beginning of the builds: Error while retrieving image from cache: geting file info: stat /cache/sha256:***************: no such file or directory.

And during the push at the end:
WARN[0269] error uploading layer to cache: failed to push to destination index.docker.io/*/*/cache:*************: unsupported status code 401;

Update to Kaniko 0.18.0

Describe the bug
Kaniko version is currently 0.16.0. They have made a lot of improvements, especially concerning the cache.

Thank!

Support additional Kaniko options

Is your feature request related to a problem? Please describe.
I am running an internal registry in my kubernetes cluster and as such I am not using SSL.
Kaniko seems to offer an --insecure option which is not available on this plugin.

Describe the solution you'd like to see
Kaniko doesn't seem to have that many flags and it should be possible to support them all.

Describe alternatives you've considered
Instead of keeping EXTRA_OPTS itnernal expose it to the users. It kind of goes against the idea of having settings but that the only other solution.

Additional context

Possible bug in upstream Kaniko affecting latest version

Describe the bug
GoogleContainerTools/kaniko#1110

Tl;dr
This happens during a COPY . .

error building image: error building stage: failed to execute command: read /drone/src/deps/absinthe/priv: is a directory

Steps to reproduce the issue:
build a docker image with the latest banzaicloud/drone-kaniko (e.g. omitting the image tag)

- name: build-docker-image
    image: banzaicloud/drone-kaniko
    settings:
      username:
        from_secret: docker_username
      password:
        from_secret: docker_password
      repo: my-repo
      registry: my.private-registry.com
      tags:
        - latest
        - ${DRONE_COMMIT_SHA}

Expected behavior
It should build correctly.

Additional context
When pinning the version to banzaicloud/drone-kaniko:0.5.1 it does build correctly.

standard_init_linux.go:211: exec user process caused "permission denied"

Describe the bug
When running drone-kaniko from a drone kubernetes runner, I get the following error:

standard_init_linux.go:211: exec user process caused "permission denied"

Steps to reproduce the issue:
Running on GKE cluster (on COS_containerd type node)

Pipeline:

---
kind: pipeline
type: kubernetes
name: Kapitan Compile

clone:
  depth: 10

steps:
- name: publish
  image: banzaicloud/drone-kaniko
  settings:
    cache: true
    registry: eu.gcr.io
    repo: eu.gcr.io/antha-images/kapitan
    dockerfile: kapitan/Dockerfile
    tags: latest
    build_args:
    - KAPITAN_RELEASE=0.27.4-ci
    json_key:
      from_secret: google_credentials

---
kind: secret
name: google_credentials
get:
  path: drone-runner
  name: google_credentials

Expected behavior
Drone builds the image

Screenshots
image

Additional context

  • Using drone kubernetes runners
  • running on GKE 1.16 with COS_Containerd nodes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.