ci: Fix build and publish workflow #102
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Docker Image to GHCR | |
on: | |
workflow_dispatch: | |
release: | |
types: | |
- created | |
pull_request: | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-n-publish: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
# This is used to complete the identity challenge | |
# with sigstore/fulcio when running outside of PRs. | |
id-token: write | |
strategy: | |
matrix: | |
platform: | |
- linux/amd64 | |
- linux/arm64 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Cat Dockerfile | |
run: cat Dockerfile | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=sha | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
# login to ghcr only when tagged with "v*" | |
- name: Login to image registry ${{ env.REGISTRY }} | |
if: startsWith(github.ref, 'refs/tags/v') | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Build and push Docker image with Buildx (don't push on PR) | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: ${{ matrix.platform }} | |
#push: ${{ startsWith(github.ref, 'refs/tags/v') }} | |
push: false | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
annotations: ${{ steps.meta.outputs.annotations }} | |
provenance: mode=max | |
sbom: true | |
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description="Custom Multi-Arch Container Image that contains unoserver, LibreOffice and major set of fonts for file format conversions" | |
# BuildKit doesn't preserve cache mounts in the GitHub Actions cache by default | |
# see: https://docs.docker.com/build/ci/github-actions/cache/#cache-mounts | |
# cache-from: type=gha | |
# cache-to: type=gha,mode=max | |
# Install the cosign tool except on PR | |
# https://github.com/sigstore/cosign-installer | |
- name: Install cosign | |
if: startsWith(github.ref, 'refs/tags/v') | |
uses: sigstore/[email protected] | |
- name: Sign the images with GitHub OIDC Token | |
if: startsWith(github.ref, 'refs/tags/v') | |
env: | |
DIGEST: ${{ steps.build-and-push.outputs.digest }} | |
TAGS: ${{ steps.meta.outputs.tags }} | |
run: | | |
images="" | |
for tag in ${TAGS}; do | |
images+="${tag}@${DIGEST} " | |
done | |
cosign sign --yes ${images} |