Skip to content

Build container image using Kaniko in GitHub Actions

License

Notifications You must be signed in to change notification settings

freeletics/kaniko-action

 
 

Repository files navigation

kaniko-action ts

This is an action to build and push a Docker image using Kaniko in GitHub Actions. It is designed to work with the Docker's official actions such as docker/login-action or docker/metadata-action.

Kaniko supports layer caching. See https://github.com/GoogleContainerTools/kaniko#caching for more.

Getting Started

To build and push a container image to GitHub Container Registry,

jobs:
  build:
    steps:
      - uses: actions/checkout@v2
      - uses: docker/metadata-action@v3
        id: metadata
        with:
          images: ghcr.io/${{ github.repository }}
      - uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: int128/kaniko-action@v1
        with:
          push: true
          tags: ${{ steps.metadata.outputs.tags }}
          labels: ${{ steps.metadata.outputs.labels }}
          cache: true
          cache-repository: ghcr.io/${{ github.repository }}/cache

To build and push a container image to Amazon ECR,

jobs:
  build:
    steps:
      - uses: actions/checkout@v2
      - uses: aws-actions/amazon-ecr-login@v1
      - uses: int128/create-ecr-repository-action@v1
        id: ecr
        with:
          repository: example
      - uses: int128/create-ecr-repository-action@v1
        id: ecr-cache
        with:
          repository: example/cache
      - uses: docker/metadata-action@v3
        id: metadata
        with:
          images: ${{ steps.ecr.outputs.repository-uri }}
      - uses: int128/kaniko-action@v1
        with:
          push: true
          tags: ${{ steps.metadata.outputs.tags }}
          labels: ${{ steps.metadata.outputs.labels }}
          cache: true
          cache-repository: ${{ steps.ecr-cache.outputs.repository-uri }}

Specification

This action runs the image of Kaniko executor using docker run command. It mounts ~/.docker/config.json to the Kaniko executor for authentication of remote registry.

Inputs

Here is a list of inputs. See also the flags of Kaniko executor.

Name Description Corresponding flag
executor Image of Kaniko executor. Default to gcr.io/kaniko-project/executor:v1.9.1 -
context *1 Path to the build context. Default to the workspace -
file *1 Path to the Dockerfile. Default to Dockerfile. It must be in the context. If set, this action passes the relative path to Kaniko, same as the behavior of docker build --dockerfile
build-args *1 List of build args --build-arg
labels *1 List of metadata for an image --label
push *1 Push an image to the registry. Default to true --no-push
tags *1 List of tags --destination
target *1 Target stage to build --target
cache Enable caching layers --cache
cache-repository Repository for storing cached layers --cache-repo
cache-ttl Cache timeout --cache-ttl
push-retry Number of retries for the push of an image --push-retry
registry-mirror Use registry mirror(s) --registry-mirror
verbosity Set the logging level --verbosity
kaniko-args Extra args to Kaniko executor -

*1 These inputs are compatible with docker/build-push-action

Outputs

Name Description
digest Image digest such as sha256:abcdef...

About

Build container image using Kaniko in GitHub Actions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 93.1%
  • JavaScript 6.9%