Skip to content

use ghcr feature.

use ghcr feature. #72

Workflow file for this run

#
name: Create and publish a Docker image
# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
workflow_dispatch:
push:
branches:
- 'main'
- 'releases/**'
tags:
- 'v*'
pull_request:
branches:
- 'main'
env:
# Sets the Docker image tag to use for the image built in this workflow.
base_dir: src/devcontainers
context: .devcontainer
workspace_folder: .
readme: README.md
registry: ghcr.io
dockerfile: Dockerfile
server: https://github.com
org: NHSDigital
repository: nhs-notify-devcontainers
vendor: NHS England
node_version: 24
temp_dockerfile: /tmp/Dockerfile.source
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
deploy-nhs-notify-feature:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: "Publish Features"
uses: devcontainers/action@v1
with:
publish-features: "true"
base-path-to-features: "./src/features"
generate-docs: "false"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-push-image:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1
matrix:
include:
- container_name: base
image: nhsdigital/nhs-notify-devcontainer-base
title: NHS Notifiy Devcontainer Base Image
description: Base development container for NHS Notify projects
- container_name: loaded
image: nhsdigital/nhs-notify-devcontainer-loaded
title: NHS Notifiy Devcontainer Loaded Image
description: Loaded development container for NHS Notify projects
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v5
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v6
with:
node-version: ${{ env.node_version }}
- name: Build
working-directory: ${{env.base_dir}}/${{ matrix.container_name }}
run: |
make build IMAGE_NAME=${{ env.registry }}/${{ matrix.image }} WORKSPACE_FOLDER=${{ env.workspace_folder }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.registry }}/${{ matrix.image }}
flavor: |
latest=auto
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=schedule
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=pr
type=sha
labels: |
org.opencontainers.image.title= ${{ matrix.title }}
org.opencontainers.image.description=${{ matrix.description }}
org.opencontainers.image.vendor=${{ env.vendor }}
org.opencontainers.image.url=${{ env.server }}/${{ env.org }}/${{ env.repository }}/blob/main/${{ env.base_dir }}/${{matrix.container_name}}/${{ env.readme }}
org.opencontainers.image.source=${{ env.server }}/${{ env.org }}/${{ env.repository }}/tree/main/${{ env.base_dir }}/${{matrix.container_name}}/
# So we don't rebuild the container image, we create a simple Dockerfile that uses the previously built image as its source.
- name: create temp dockerfile source
run: echo 'FROM ${{ env.registry }}/${{ matrix.image }}' > ${{ env.temp_dockerfile }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: ${{ env.temp_dockerfile }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v3
with:
subject-name: ${{ env.registry }}/${{ matrix.image }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true