Build Headless Anki Docker image #25
Workflow file for this run
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: Build Headless Anki Docker image | |
on: | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: 'Image tag' | |
required: true | |
type: string | |
default: 'latest' | |
ankiconnect_version: | |
description: 'AnkiConnect version' | |
required: false | |
type: string | |
default: '24.7.25.0' | |
env: | |
REGISTRY: ghcr.io | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
arch: [amd64, arm64] | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
attestations: write | |
steps: | |
- name: Set image name | |
id: image-name | |
run: | | |
echo "name=${GITHUB_REPOSITORY,,}-headless-anki" >> $GITHUB_OUTPUT | |
- name: Set environment variables | |
run: | | |
echo "IMAGE_NAME=${{ steps.image-name.outputs.name }}" >> $GITHUB_ENV | |
- name: Log in to the Container registry | |
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=${{ inputs.tag }} | |
- name: Build and push by digest | |
id: build | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./deployment/ | |
file: ./deployment/Dockerfile.headless-anki | |
platforms: linux/${{ matrix.arch }} | |
labels: ${{ steps.meta.outputs.labels }} | |
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true | |
build-args: | | |
ANKICONNECT_VERSION=${{ inputs.ankiconnect_version }} | |
TARGETARCH=${{ matrix.arch }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Export digest | |
run: | | |
mkdir -p /tmp/digests | |
digest="${{ steps.build.outputs.digest }}" | |
touch "/tmp/digests/${digest#sha256:}" | |
- name: Upload digest | |
uses: actions/upload-artifact@v4 | |
with: | |
name: digests-${{ matrix.arch }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
merge: | |
runs-on: ubuntu-latest | |
needs: | |
- build-and-push-image | |
permissions: | |
packages: write | |
id-token: write | |
attestations: write | |
steps: | |
- name: Download digests | |
uses: actions/download-artifact@v4 | |
with: | |
path: /tmp/digests | |
pattern: digests-* | |
merge-multiple: true | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the 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.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=${{ inputs.tag }} | |
- name: Set image name | |
id: image-name | |
run: | | |
echo "name=${GITHUB_REPOSITORY,,}-headless-anki" >> $GITHUB_OUTPUT | |
- name: Set environment variables | |
run: | | |
echo "IMAGE_NAME=${{ steps.image-name.outputs.name }}" >> $GITHUB_ENV | |
- name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
for digest in *; do | |
digests="$digests ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:$digest" | |
done | |
docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.tag }} $digests | |
- name: Inspect image | |
run: | | |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.tag }} |