mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-28 14:47:11 -07:00
Use buildx provided in runner, see https://github.com/actions/runner-images/blob/main/images/ubuntu-slim/ubuntu-slim-Readme.md
175 lines
5.6 KiB
YAML
175 lines
5.6 KiB
YAML
name: Build Docker
|
|
|
|
permissions:
|
|
contents: read # needed to checkout repo
|
|
id-token: write # needed for signing attestations (SBOM & provenance) with GitHub OIDC
|
|
packages: write # needed for interacting with GHCR
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
pull_request:
|
|
branches:
|
|
- master
|
|
paths:
|
|
- '.github/workflows/docker-release.yml'
|
|
- '.dockerignore'
|
|
- 'Dockerfile'
|
|
- 'docker-compose.yml'
|
|
- 'docker-compose.yml.windows'
|
|
release:
|
|
types:
|
|
- released # publishing of stable releases
|
|
|
|
# Cancel earlier, unfinished runs of this workflow on the same branch (unless on release)
|
|
concurrency:
|
|
group: "${{ github.workflow }} @ ${{ github.ref_name }}"
|
|
cancel-in-progress: ${{ github.event_name != 'release' }}
|
|
|
|
env:
|
|
GHCR_IMAGE: ghcr.io/cockatrice/servatrice
|
|
OCI_DESCRIPTION: Server for Cockatrice, a cross-platform virtual tabletop for multiplayer card games
|
|
OCI_TITLE: Servatrice
|
|
OCI_URL: https://cockatrice.github.io/
|
|
|
|
jobs:
|
|
# Create one platform-specific image and publish its OCI image manifest per matrix job
|
|
build:
|
|
name: "${{ matrix.label }}"
|
|
if: github.repository_owner == 'Cockatrice'
|
|
runs-on: ${{ matrix.runner }}
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- label: x86
|
|
platform: linux/amd64
|
|
runner: ubuntu-latest
|
|
|
|
- label: arm
|
|
platform: linux/arm64
|
|
runner: ubuntu-24.04-arm # to be replaced with "ubuntu-latest-arm" once available
|
|
|
|
env:
|
|
CACHE_SCOPE: servatrice-${{ matrix.label }}
|
|
|
|
steps:
|
|
- name: "Checkout"
|
|
uses: actions/checkout@v7
|
|
|
|
- name: "Set up Docker buildx"
|
|
uses: docker/setup-buildx-action@v4
|
|
|
|
- name: "Login to GitHub Container Registry (GHCR)"
|
|
if: github.event_name == 'release' && github.event.release.prerelease == false
|
|
id: login
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ github.token }}
|
|
|
|
# Don't push for non-release triggers
|
|
- name: "Build image"
|
|
if: steps.login.outcome != 'success'
|
|
uses: docker/build-push-action@v7
|
|
with:
|
|
cache-from: type=gha,scope=${{ env.CACHE_SCOPE }}
|
|
cache-to: type=gha,mode=max,scope=${{ env.CACHE_SCOPE }}
|
|
context: .
|
|
platforms: ${{ matrix.platform }}
|
|
push: false
|
|
|
|
# Add OCI labels and push single-platform image by digest (without tags)
|
|
- name: "Build image and push by digest"
|
|
if: steps.login.outcome == 'success'
|
|
id: build
|
|
uses: docker/build-push-action@v7
|
|
with:
|
|
cache-from: type=gha,scope=${{ env.CACHE_SCOPE }}
|
|
cache-to: type=gha,mode=max,scope=${{ env.CACHE_SCOPE }}
|
|
context: .
|
|
labels: |
|
|
org.opencontainers.image.description=${{ env.OCI_DESCRIPTION }}
|
|
org.opencontainers.image.title=${{ env.OCI_TITLE }}
|
|
org.opencontainers.image.url=${{ env.OCI_URL }}
|
|
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
|
|
platforms: ${{ matrix.platform }}
|
|
provenance: mode=max # Do not pass secrets as build arguments with this option
|
|
sbom: true
|
|
|
|
- name: "Export digest"
|
|
if: steps.login.outcome == 'success'
|
|
env:
|
|
DIGEST: ${{ steps.build.outputs.digest }}
|
|
run: |
|
|
mkdir -p $RUNNER_TEMP/digests
|
|
touch "$RUNNER_TEMP/digests/${DIGEST#sha256:}"
|
|
|
|
- name: "Upload digest"
|
|
if: steps.login.outcome == 'success'
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
if-no-files-found: error
|
|
name: digest-${{ matrix.platform }}
|
|
path: $RUNNER_TEMP/digests/*
|
|
retention-days: 1
|
|
|
|
|
|
# Create an OCI image index from the platform-specific image manifests
|
|
index:
|
|
name: "Publish multi-platform image"
|
|
if: github.repository_owner == 'Cockatrice' && github.event_name == 'release' && github.event.release.prerelease == false
|
|
needs: build
|
|
runs-on: ubuntu-slim
|
|
|
|
steps:
|
|
- name: "Download digests"
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: $RUNNER_TEMP/digests
|
|
pattern: digest-*
|
|
merge-multiple: true
|
|
|
|
- name: "Login to GitHub Container Registry (GHCR)"
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ github.token }}
|
|
|
|
- name: "Docker metadata"
|
|
id: metadata
|
|
uses: docker/metadata-action@v6
|
|
with:
|
|
images: ${{ env.GHCR_IMAGE }}
|
|
tags: |
|
|
type=raw,value=latest
|
|
type=ref,event=tag
|
|
|
|
# Add OCI annotations to image index and publish tags
|
|
- name: "Create image index"
|
|
env:
|
|
TAGS: ${{ steps.metadata.outputs.tags }}
|
|
working-directory: ${{ runner.temp }}/digests
|
|
run: |
|
|
TAG_ARGS=""
|
|
for tag in $TAGS; do
|
|
TAG_ARGS="$TAG_ARGS -t $tag"
|
|
done
|
|
|
|
docker buildx imagetools create \
|
|
--prefer-index=true \
|
|
--annotation "index:org.opencontainers.image.description=$OCI_DESCRIPTION" \
|
|
--annotation "index:org.opencontainers.image.title=$OCI_TITLE" \
|
|
--annotation "index:org.opencontainers.image.url=$OCI_URL" \
|
|
$TAG_ARGS \
|
|
$(printf '%s@sha256:%s ' "$GHCR_IMAGE" *)
|
|
|
|
- name: "Inspect images"
|
|
run: |
|
|
docker buildx imagetools inspect "$GHCR_IMAGE:latest"
|
|
docker buildx imagetools inspect "$GHCR_IMAGE:$OCI_VERSION"
|