Skip to content

Publish Docker Image #24

Publish Docker Image

Publish Docker Image #24

name: Publish Docker Image
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Image tag to use (e.g. dev, latest, my-branch)'
default: 'dev'
required: true
branch:
description: 'Git branch to build from'
default: 'main'
required: true
env:
REGISTRY: ghcr.io
IMAGE_REPOSITORY: ghcr.io/DiamondLightSource/visr-ui
jobs:
docker-build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_REPOSITORY }}
tags: |
${{ github.event_name == 'release' && 'type=semver,pattern={{version}}' || github.event.inputs.tag }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
if: ${{ github.event_name == 'release' }}
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.IMAGE_REPOSITORY }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true