Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

github-action-build-dockerfile

Cache aware building and publishing of Dockerfiles.

Usage

Pairs well with github-action-detect-image-metadata to set the image labels and tags.

jobs:
  publish-dockerfile:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        ref: ${{ github.event.pull_request.head.sha || '' }}

    - name: Gather Image Labels and Tags
      id: meta
      uses: briceburg/github-action-detect-image-metadata

    - name: Log in to the Container registry
      uses: docker/login-action
      with:
        registry: ${{ steps.meta.outputs.registry }}
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}

    - name: Build and Publish Docker Image
      uses: briceburg/github-action-build-dockerfile
      with:
        context: .
        dockerfile-path: src/Dockerfile
        image-labels: ${{ steps.meta.outputs.labels }}
        images: ${{ steps.meta.outputs.images }}

Inputs

name description required default
build-args

Newline separated build arguments, e.g. "VERSION=foo\nAUTHOR=bar".

false ""
build-secrets

Newline separated build secrets, e.g. "VERSION=foo\nAUTHOR=bar".

false ""
build-target

Target stage to build

false ""
cache-branches

JSON array of branches which trigger publishing layers to gha cache. Use long lived branches. E.g. '["main", "master"]'. If empty, uses the default branch.

false ["${{ github.event.repository.default_branch }}"]
context

Docker build context directory. Defaults to "Git context" so you don't need to use actions/checkout, but it will not pickup local changes. Point to a directory to pickup local changes from a checkout, e.g. '.' or './alt/docker/build/path'.

false {{defaultContext}}:.
dockerfile-path

Dockerfile path (relative to build context).

false Dockerfile
image-labels

Newline list of Image Labels (in name=value format)

false ""
images

Newline list of images (in registry/image-name:tag format)

false ""
platforms

target platforms to build image(s) for, e.g. 'linux/amd64,linux/arm64'.

false linux/amd64
push

The string 'true' to push the built image to registry, otherwise the string 'false'.

false true
skip-summary

The string 'true' to skip writing the job summary, otherwise the string 'false'.

false false

Outputs

name description
image-digest

Image Digest

In addition to the action outputs, the following environment variables are set:

name description
BUILD_DOCKERFILE_IMAGE_DIGEST

Image Digest

About

Cache aware building of Dockerfiles

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors