Kaniko

Description

This plugin enables you to build and publish Docker images in a Vela pipeline.

Source Code: https://github.com/go-vela/vela-kaniko

Registry: https://hub.docker.com/r/target/vela-kaniko

Usage

NOTE:

Users should refrain from using latest as the tag for the Docker image.

It is recommended to use a semantically versioned tag instead.

Sample of building and publishing an image:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world

Sample of building an image without publishing:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
+     dry_run: true
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world

Sample of attempting the publishing of an image three times:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
+     push_retry: 3
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world

Sample of building and publishing an image with custom tags:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world
+     tags:
+       - latest
+       - foobar

Sample of building and publishing an image with automatic tags:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
+     auto_tag: true
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world

Depending on the type of event, the image will be tagged as follows:

  • tag event (using v1.0.0 as an example):

    • index.docker.io/octocat/hello-world:latest
    • index.docker.io/octocat/hello-world:v1.0.0
  • all other events:

    • index.docker.io/octocat/hello-world:latest
    • index.docker.io/octocat/hello-world:eeea105fed7fc11bda4b43a00edfc49a5c982968

Sample of building and publishing an image with build arguments:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
+     build_args:
+       - FOO=bar
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world

Sample of building and publishing an image with caching:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
+     cache: true
+     cache_repo: index.docker.io/octocat/hello-world
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world

Sample of building using a snapshot mode and publishing an image with caching:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
+     snapshot_mode: redo
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world

Sample of building using a custom platform:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world
+     custom_platform: linux/arm64/v8

NOTE: This option will only work if your Vela worker is configured appropriately.

Sample of only including repository topics starting with “id” as a value in the “io.vela.build.topics” that gets applied to the built image:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
+     repo_topics_filter: "^id"
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world

Sample of using zstd layer compression:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world
+     compression: zstd
+     compression_level: 3

NOTE: Be aware that while this may yield better compression and/or performance, many common container tools are not yet compatible with this type of compression. Use at your own risk.

Secrets

NOTE: Users should refrain from configuring sensitive information in your pipeline in plain text.

Internal

Users can use Vela internal secrets to substitute these sensitive values at runtime:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
+   secrets: [ kaniko_username, kaniko_password ]
    parameters:
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world
-     username: octocat
-     password: superSecretPassword

This example will add the secrets to the publish_hello-world step as environment variables:

  • KANIKO_USERNAME=<value>
  • KANIKO_PASSWORD=<value>

External

The plugin accepts the following files for authentication:

ParameterVolume Configuration
password/vela/parameters/kaniko/password, /vela/secrets/kaniko/password, /vela/secrets/managed-auth/password
username/vela/parameters/kaniko/username, /vela/secrets/kaniko/username, /vela/secrets/managed-auth/username

Users can use Vela external secrets to substitute these sensitive values at runtime:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
+   secrets: [ kaniko_username, kaniko_password ]
    parameters:
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world
-     username: octocat
-     password: superSecretPassword

This example will read the secret values in the volume stored at /vela/secrets/

Parameters

NOTE:

The plugin supports reading all parameters via environment variables or files.

Any values set from a file take precedence over values set from the environment.

The Snapshot mode can help improve performance but it is recommend to follow Kaniko’s guidelines for picking the mode.

The following parameters are used to configure the image:

NameDescriptionRequiredDefaultEnvironment Variables
auto_tagenables automatic tagging of images (tag or sha, and latest)falsefalsePARAMETER_AUTO_TAG
KANIKO_AUTO_TAG
build_argsvariables passed to image at build-timefalseN/APARAMETER_BUILD_ARGS
KANIKO_BUILD_ARGS
cacheenable caching of image layersfalsefalsePARAMETER_CACHE
KANIKO_CACHE
cache_repospecific repo to enable caching forfalseN/APARAMETER_CACHE_REPO
KANIKO_CACHE_REPO
compressioncompression to use (gzip or zstd - kaniko uses gzip if not defined)falseN/APARAMETER_COMPRESSION
KANIKO_COMPRESSION
compression_levelcompression level to use (1 - 9, inclusive)falseN/APARAMETER_COMPRESSION_LEVEL
KANIKO_COMPRESSION_LEVEL
compressed_cachingset this to false in order to prevent tar compression for cached layersfalsetruePARAMETER_COMPRESSED_CACHING
KANIKO_COMPRESSED_CACHING
contextpath to context for building the imagetrue.PARAMETER_CONTEXT
KANIKO_CONTEXT
dockerfilepath to the file for building the imagetrueDockerfilePARAMETER_DOCKERFILE
KANIKO_DOCKERFILE
dry_runenable building the image without publishingfalsefalsePARAMETER_DRY_RUN
KANIKO_DRY_RUN
eventevent generated for buildtrueset by VelaPARAMETER_EVENT
KANIKO_EVENT
VELA_BUILD_EVENT
force_build_metadataenable force adding metadata layers to build imagefalsefalsePARAMETER_FORCE_BUILD_METADATA
KANIKO_FORCE_BUILD_METADATA
repo_topics_filterregex expression to filter out repository topicsfalseempty slicePARAMETER_REPO_TOPICS_FILTER
KANIKO_REPO_TOPICS_FILTER
ignore_pathignore path when taking an image snapshotfalseempty slicePARAMETER_IGNORE_PATH
KANIKO_IGNORE_PATH
ignore_var_runsets --ignore-var-run kaniko flag to control whether /var/run is included in image snapshotfalsetruePARAMETER_IGNORE_VAR_RUN
KANIKO_IGNORE_VAR_RUN
VELA_IGNORE_VAR_RUN
labelsunique labels to add to the imagefalseN/APARAMETER_LABELS
KANIKO_LABELS
log_levelset the log level for the plugintrueinfoPARAMETER_LOG_LEVEL
KANIKO_LOG_LEVEL
log_timestampsadd timestamps to log linesfalsefalsePARAMETER_LOG_TIMESTAMPS
KANIKO_LOG_TIMESTAMPS
mirrorname of the mirror registry to usefalseN/APARAMETER_MIRROR
KANIKO_MIRROR
passwordpassword for communication with the registrytrueN/APARAMETER_PASSWORD
KANIKO_PASSWORD
DOCKER_PASSWORD
push_retrynumber of retries for pushing an image to a remote destinationfalse0PARAMETER_PUSH_RETRY
KANIKO_PUSH_RETRY
registryname of the registry for the repositorytrueindex.docker.ioPARAMETER_REGISTRY
KANIKO_REGISTRY
reponame of the repository for the imagetrueN/APARAMETER_REPO
KANIKO_REPO
shaSHA-1 hash generated for committrueset by VelaPARAMETER_SHA
KANIKO_SHA
VELA_BUILD_COMMIT
use_new_runuse experimental run implementation for detecting changes without requiring file system snapshotsfalsefalsePARAMETER_USE_NEW_RUN
KANIKO_USE_NEW_RUN
single_snapshottakes a single snapshot of the filesystem at the end of the build, so only one layer will be appended to the base imagefalsefalsePARAMETER_SINGLE_SNAPSHOT
KANIKO_SINGLE_SNAPSHOT
snapshot_modecontrol how to snapshot the filesystem. - options: full, redo, or timefalseN/APARAMETER_SNAPSHOT_MODE
KANIKO_SNAPSHOT_MODE
tagtag generated for buildfalseset by VelaPARAMETER_TAG
KANIKO_TAG
VELA_BUILD_TAG
tagsunique tags of the imagetruelatestPARAMETER_TAGS
KANIKO_TAGS
tar_pathsave the image as a tarball at pathfalseN/APARAMETER_TAR_PATH
KANIKO_TAR_PATH
targetset the target build stage for the imagefalseN/APARAMETER_TARGET
KANIKO_TARGET
usernameuser name for communication with the registrytrueN/APARAMETER_USERNAME
KANIKO_USERNAME
DOCKER_USERNAME
custom_platformset the custom platform for the imagefalseN/APARAMETER_CUSTOM_PLATFORM
KANIKO_CUSTOM_PLATFORM
insecure_registriesinsecure docker registries to push or pull to/fromfalseempty slicePARAMETER_INSECURE_REGISTRIES
KANIKO_INSECURE_REGISTRIES
insecure_pullenable pulling from any insecure registryfalsefalsePARAMETER_INSECURE_PULL
KANIKO_INSECURE_PULL
insecure_pushenable pushing to any insecure registryfalsefalsePARAMETER_INSECURE_PUSH
KANIKO_INSECURE_PUSH

Template

COMING SOON!

Troubleshooting

You can start troubleshooting this plugin by tuning the level of logs being displayed:

steps:
  - name: publish_hello-world
    image: target/vela-kaniko:latest
    pull: always
    parameters:
+     log_level: trace
      registry: index.docker.io
      repo: index.docker.io/octocat/hello-world

Below are a list of common problems and how to solve them: