mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
273 lines
10 KiB
YAML
273 lines
10 KiB
YAML
name: Build Docker Image
|
|
|
|
on:
|
|
# push:
|
|
# tags:
|
|
# - "[0-9]+.[0-9]+.[0-9]+*"
|
|
release:
|
|
types: [published]
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
# `build` pushes digests here and `merge` tags them from here; the two must agree.
|
|
env:
|
|
DIGEST_IMAGE: ghcr.io/${{ github.repository_owner }}/romm
|
|
|
|
jobs:
|
|
validate-tag-semver:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
outputs:
|
|
valid: ${{ steps.check_tag.outputs.valid }}
|
|
steps:
|
|
- name: Check if tag follows SemVer
|
|
id: check_tag
|
|
env:
|
|
TAG: ${{ github.event.release.tag_name }}
|
|
run: |
|
|
if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+)?$ ]]; then
|
|
echo "valid=true" >>"$GITHUB_OUTPUT"
|
|
else
|
|
echo "valid=false" >>"$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
# Each architecture builds natively and pushes untagged, digest-addressed
|
|
# images; `merge` stitches them into one index per variant.
|
|
build:
|
|
needs: validate-tag-semver
|
|
if: needs.validate-tag-semver.outputs.valid == 'true'
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- platform: linux/amd64
|
|
arch: amd64
|
|
runner: ubuntu-24.04
|
|
- platform: linux/arm64
|
|
arch: arm64
|
|
runner: ubuntu-24.04-arm
|
|
runs-on: ${{ matrix.runner }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
env:
|
|
CACHE_IMAGE: ghcr.io/${{ github.repository_owner }}/romm-buildcache
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Generate Docker metadata (slim)
|
|
id: meta-slim
|
|
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
|
|
with:
|
|
images: |
|
|
name=rommapp/romm
|
|
name=ghcr.io/rommapp/romm
|
|
flavor: |
|
|
latest=auto
|
|
suffix=-slim,onlatest=true
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
labels: |
|
|
org.opencontainers.image.version={{version}}-slim
|
|
org.opencontainers.image.title="rommapp/romm"
|
|
org.opencontainers.image.description="RomM (ROM Manager) allows you to scan, enrich, and browse your game collection with a clean and responsive interface. With support for multiple platforms, various naming schemes and custom tags, RomM is a must-have for anyone who plays on emulators."
|
|
org.opencontainers.image.licenses="AGPLv3"
|
|
|
|
- name: Generate Docker metadata (full)
|
|
id: meta
|
|
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
|
|
with:
|
|
images: |
|
|
name=rommapp/romm
|
|
name=ghcr.io/rommapp/romm
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
labels: |
|
|
org.opencontainers.image.version={{version}}
|
|
org.opencontainers.image.title="rommapp/romm"
|
|
org.opencontainers.image.description="RomM (ROM Manager) allows you to scan, enrich, and browse your game collection with a clean and responsive interface. With support for multiple platforms, various naming schemes and custom tags, RomM is a must-have for anyone who plays on emulators."
|
|
org.opencontainers.image.licenses="AGPLv3"
|
|
|
|
- name: Set version
|
|
run: |
|
|
sed -i 's/<version>/${{ steps.meta.outputs.version }}/' backend/__version__.py
|
|
|
|
- name: Build and push slim image by digest
|
|
id: build-slim
|
|
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
|
with:
|
|
file: docker/Dockerfile
|
|
context: .
|
|
platforms: ${{ matrix.platform }}
|
|
labels: ${{ steps.meta-slim.outputs.labels }}
|
|
target: slim-image
|
|
outputs: type=image,name=${{ env.DIGEST_IMAGE }},push-by-digest=true,name-canonical=true,push=true
|
|
# Deliberately not seeded from the preview cache: those layers are
|
|
# built from PR head content and must not reach a release image.
|
|
cache-from: type=registry,ref=${{ env.CACHE_IMAGE }}:release-${{ matrix.arch }}
|
|
build-args: |
|
|
SCREENSCRAPER_DEV_ID=${{ secrets.SCREENSCRAPER_DEV_ID }}
|
|
SCREENSCRAPER_DEV_PASSWORD=${{ secrets.SCREENSCRAPER_DEV_PASSWORD }}
|
|
|
|
# Only the full build writes the cache: it is a superset of the slim one,
|
|
# so a single `mode=max` export covers every stage either target needs.
|
|
- name: Build and push full image by digest
|
|
id: build-full
|
|
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
|
with:
|
|
file: docker/Dockerfile
|
|
context: .
|
|
platforms: ${{ matrix.platform }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
target: full-image
|
|
outputs: type=image,name=${{ env.DIGEST_IMAGE }},push-by-digest=true,name-canonical=true,push=true
|
|
cache-from: type=registry,ref=${{ env.CACHE_IMAGE }}:release-${{ matrix.arch }}
|
|
cache-to: type=registry,ref=${{ env.CACHE_IMAGE }}:release-${{ matrix.arch }},mode=max
|
|
build-args: |
|
|
SCREENSCRAPER_DEV_ID=${{ secrets.SCREENSCRAPER_DEV_ID }}
|
|
SCREENSCRAPER_DEV_PASSWORD=${{ secrets.SCREENSCRAPER_DEV_PASSWORD }}
|
|
|
|
- name: Export digests
|
|
env:
|
|
SLIM_DIGEST: ${{ steps.build-slim.outputs.digest }}
|
|
FULL_DIGEST: ${{ steps.build-full.outputs.digest }}
|
|
run: |
|
|
mkdir -p /tmp/digests/slim /tmp/digests/full
|
|
touch "/tmp/digests/slim/${SLIM_DIGEST#sha256:}"
|
|
touch "/tmp/digests/full/${FULL_DIGEST#sha256:}"
|
|
|
|
- name: Upload slim digest
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: digest-slim-${{ matrix.arch }}
|
|
path: /tmp/digests/slim/*
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
- name: Upload full digest
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: digest-full-${{ matrix.arch }}
|
|
path: /tmp/digests/full/*
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
merge:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- name: Download slim digests
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
with:
|
|
path: /tmp/digests/slim
|
|
pattern: digest-slim-*
|
|
merge-multiple: true
|
|
|
|
- name: Download full digests
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
with:
|
|
path: /tmp/digests/full
|
|
pattern: digest-full-*
|
|
merge-multiple: true
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Generate Docker metadata (slim)
|
|
id: meta-slim
|
|
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
|
|
with:
|
|
images: |
|
|
name=rommapp/romm
|
|
name=ghcr.io/rommapp/romm
|
|
flavor: |
|
|
latest=auto
|
|
suffix=-slim,onlatest=true
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
|
|
- name: Generate Docker metadata (full)
|
|
id: meta
|
|
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
|
|
with:
|
|
images: |
|
|
name=rommapp/romm
|
|
name=ghcr.io/rommapp/romm
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
|
|
# Tags spanning both registries are fine here: `imagetools create` copies
|
|
# the blobs over when a target sits in a different registry than the digests.
|
|
- name: Create manifest lists and push
|
|
env:
|
|
SLIM_METADATA: ${{ steps.meta-slim.outputs.json }}
|
|
FULL_METADATA: ${{ steps.meta.outputs.json }}
|
|
run: |
|
|
push_variant() {
|
|
local dir="$1" metadata="$2"
|
|
|
|
local tags=()
|
|
while IFS= read -r tag; do
|
|
tags+=(--tag "$tag")
|
|
done < <(jq -r '.tags[]' <<<"$metadata")
|
|
|
|
local sources=()
|
|
local digest
|
|
for digest in "$dir"/*; do
|
|
[[ -f "$digest" ]] || continue
|
|
sources+=("${DIGEST_IMAGE}@sha256:${digest##*/}")
|
|
done
|
|
|
|
# Without both lists `imagetools create` would push an untagged
|
|
# index and still exit 0, publishing a release nobody can pull.
|
|
if [[ ${#tags[@]} -eq 0 || ${#sources[@]} -eq 0 ]]; then
|
|
echo "::error::${dir}: ${#tags[@]} tag(s), ${#sources[@]} digest(s)"
|
|
return 1
|
|
fi
|
|
|
|
docker buildx imagetools create "${tags[@]}" "${sources[@]}"
|
|
}
|
|
|
|
push_variant /tmp/digests/slim "$SLIM_METADATA"
|
|
push_variant /tmp/digests/full "$FULL_METADATA"
|