github-actions

Build docker image

Build the docker image, with or without cache and push to the Github container registry. If the package does not exist yet, it will create it and configure permissions and visibility automatically. For more information, read the Github documentation.

It creates 2 tags:

If caching is enabled via reuse-cache, the caching used depends on the setting of max-cache

max-cache=true is preferred for multi-stage builds.

Note that the cache hit ratio for a workflow running build can be seen on the workflow summary page.

Optionally (recommended) scan the image for vulnerabilities using Snyk.

A service that uses this action with reuse-cache = true, should also have a cache refresh workflow that has reuse-cache = false that runs weekly and on-demand. This is required to refresh the underlying cache so it picks up any underlying image changes.

It’s also possible to override the image tags and caching defaults set by the action. Set any of the following as github environment variables in the calling workflow before calling this action, if it’s required to override the action default settings.

e.g.

- name: Set DOCKER_IMAGE environment variable
  id: build-vars-base
  run: |
    {
      echo 'TAGS_VAR<<EOF'
      echo $:base-$
      echo $:base-sha-$
      echo EOF
    } >> "$GITHUB_ENV"
    {
      echo 'MIN_CACHE_FROM_VAR<<EOF'
      echo type=registry,ref=$:base-$
      echo type=registry,ref=$:base-master
      echo EOF
    } >> "$GITHUB_ENV"

- name: Build and push docker image
  id: build-image-base
  uses: DFE-Digital/github-actions/build-docker-image@master
  with:
    github-token: $
    target: base
    context: .
    max-cache: false
    main-branch: "master"
    docker-repository: $

Inputs

Outputs

Example

- uses: actions/checkout@v4

- name: Build and push docker image
  uses: DFE-Digital/github-actions/build-docker-image@master
  with:
    github-token: $