mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-16 15:40:12 +01:00
- Create/use orphan branch 'similarity-cache-data' for cache distribution - Add age check to dockerhub-publish: only rebuild if cache >7 days old - Use git add -f to force-add cache files (keeps .gitignore clean) - Weekly scheduled builds will keep cache fresh automatically This avoids rebuilding cache on every Docker publish while ensuring cache is always reasonably fresh (<7 days old).
243 lines
8.9 KiB
YAML
243 lines
8.9 KiB
YAML
name: Publish Docker image to Docker Hub
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
check-cache-age:
|
|
name: Check similarity cache age
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
needs_rebuild: ${{ steps.check.outputs.needs_rebuild }}
|
|
steps:
|
|
- name: Check cache age
|
|
id: check
|
|
run: |
|
|
# Check if cache is older than 7 days
|
|
CACHE_URL="https://raw.githubusercontent.com/${{ github.repository }}/similarity-cache-data/card_files/similarity_cache_metadata.json"
|
|
|
|
if wget -q --spider "$CACHE_URL"; then
|
|
wget -q "$CACHE_URL" -O metadata.json
|
|
BUILD_DATE=$(jq -r '.build_date' metadata.json)
|
|
|
|
# Calculate age in seconds
|
|
BUILD_EPOCH=$(date -d "$BUILD_DATE" +%s 2>/dev/null || echo 0)
|
|
NOW_EPOCH=$(date +%s)
|
|
AGE_DAYS=$(( ($NOW_EPOCH - $BUILD_EPOCH) / 86400 ))
|
|
|
|
echo "Cache age: $AGE_DAYS days"
|
|
|
|
if [ $AGE_DAYS -gt 7 ]; then
|
|
echo "needs_rebuild=true" >> $GITHUB_OUTPUT
|
|
echo "Cache is stale (>7 days), will rebuild"
|
|
else
|
|
echo "needs_rebuild=false" >> $GITHUB_OUTPUT
|
|
echo "Cache is fresh (<7 days), skipping rebuild"
|
|
fi
|
|
else
|
|
echo "needs_rebuild=true" >> $GITHUB_OUTPUT
|
|
echo "Cache not found, will build"
|
|
fi
|
|
|
|
build-cache:
|
|
name: Build similarity cache
|
|
needs: check-cache-age
|
|
if: needs.check-cache-age.outputs.needs_rebuild == 'true'
|
|
uses: ./.github/workflows/build-similarity-cache.yml
|
|
secrets: inherit
|
|
|
|
prepare:
|
|
name: Prepare metadata
|
|
runs-on: ubuntu-latest
|
|
needs: [check-cache-age, build-cache]
|
|
if: always() && (needs.build-cache.result == 'success' || needs.build-cache.result == 'skipped')
|
|
permissions:
|
|
contents: read
|
|
outputs:
|
|
version: ${{ steps.notes.outputs.version }}
|
|
desc: ${{ steps.notes.outputs.desc }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v5.0.0
|
|
|
|
- name: Prepare release notes from template
|
|
id: notes
|
|
shell: bash
|
|
run: |
|
|
VERSION_REF="${GITHUB_REF##*/}" # e.g. v1.2.3
|
|
TEMPLATE="RELEASE_NOTES_TEMPLATE.md"
|
|
if [ -f "$TEMPLATE" ]; then
|
|
sed "s/\${VERSION}/${VERSION_REF}/g" "$TEMPLATE" > RELEASE_NOTES.md
|
|
else
|
|
echo "# MTG Python Deckbuilder ${VERSION_REF}" > RELEASE_NOTES.md
|
|
echo >> RELEASE_NOTES.md
|
|
echo "Automated release." >> RELEASE_NOTES.md
|
|
fi
|
|
DESC=$(awk 'BEGIN{ORS="\\n"} {print}' RELEASE_NOTES.md)
|
|
echo "desc=$DESC" >> $GITHUB_OUTPUT
|
|
echo "version=$VERSION_REF" >> $GITHUB_OUTPUT
|
|
|
|
- name: Extract Docker metadata (latest only)
|
|
id: meta
|
|
uses: docker/metadata-action@v5.8.0
|
|
with:
|
|
images: |
|
|
mwisnowski/mtg-python-deckbuilder
|
|
tags: |
|
|
type=raw,value=latest
|
|
labels: |
|
|
org.opencontainers.image.title=MTG Python Deckbuilder
|
|
org.opencontainers.image.version=${{ github.ref_name }}
|
|
org.opencontainers.image.description=${{ steps.notes.outputs.desc }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
|
|
build_amd64:
|
|
name: Build (amd64)
|
|
runs-on: ubuntu-latest
|
|
needs: prepare
|
|
permissions:
|
|
contents: read
|
|
outputs:
|
|
digest: ${{ steps.build.outputs.digest }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v5.0.0
|
|
|
|
- name: Download similarity cache from branch
|
|
run: |
|
|
# Download cache files from similarity-cache-data branch
|
|
mkdir -p card_files
|
|
wget -q https://raw.githubusercontent.com/${{ github.repository }}/similarity-cache-data/card_files/similarity_cache.parquet -O card_files/similarity_cache.parquet || echo "Cache not found, will build without it"
|
|
wget -q https://raw.githubusercontent.com/${{ github.repository }}/similarity-cache-data/card_files/similarity_cache_metadata.json -O card_files/similarity_cache_metadata.json || echo "Metadata not found"
|
|
|
|
if [ -f card_files/similarity_cache.parquet ]; then
|
|
echo "✓ Downloaded similarity cache"
|
|
ls -lh card_files/similarity_cache.parquet
|
|
fi
|
|
|
|
- name: Compute amd64 tag
|
|
id: arch_tag
|
|
shell: bash
|
|
run: |
|
|
echo "tag=mwisnowski/mtg-python-deckbuilder:${{ needs.prepare.outputs.version }}-amd64" >> $GITHUB_OUTPUT
|
|
|
|
- name: Docker Hub login
|
|
uses: docker/login-action@v3.5.0
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3.11.1
|
|
|
|
- name: Smoke test Web UI (local build)
|
|
shell: bash
|
|
env:
|
|
APP_VERSION: ${{ needs.prepare.outputs.version }}
|
|
run: |
|
|
docker buildx build --platform linux/amd64 --load -t mtg-deckbuilder:test --build-arg APP_VERSION=$APP_VERSION .
|
|
docker rm -f mtg-smoke 2>/dev/null || true
|
|
docker run -d --name mtg-smoke -p 8080:8080 mtg-deckbuilder:test
|
|
echo "Waiting for Web UI (amd64)..."
|
|
for i in {1..30}; do
|
|
if curl -fsS http://localhost:8080/ >/dev/null; then echo "Up"; break; fi
|
|
sleep 2
|
|
done
|
|
if ! curl -fsS http://localhost:8080/ >/dev/null; then
|
|
echo "Web UI did not start in time. Logs:" && docker logs mtg-smoke || true
|
|
exit 1
|
|
fi
|
|
docker rm -f mtg-smoke >/dev/null 2>&1 || true
|
|
|
|
- name: Build & push arch image (amd64)
|
|
id: build
|
|
uses: docker/build-push-action@v6.18.0
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
platforms: linux/amd64
|
|
tags: ${{ steps.arch_tag.outputs.tag }}
|
|
labels: ${{ needs.prepare.outputs.labels }}
|
|
build-args: |
|
|
APP_VERSION=${{ needs.prepare.outputs.version }}
|
|
|
|
build_arm64:
|
|
name: Build (arm64)
|
|
runs-on: ubuntu-24.04-arm
|
|
needs: prepare
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v5.0.0
|
|
|
|
- name: Download similarity cache from branch
|
|
run: |
|
|
# Download cache files from similarity-cache-data branch
|
|
mkdir -p card_files
|
|
wget -q https://raw.githubusercontent.com/${{ github.repository }}/similarity-cache-data/card_files/similarity_cache.parquet -O card_files/similarity_cache.parquet || echo "Cache not found, will build without it"
|
|
wget -q https://raw.githubusercontent.com/${{ github.repository }}/similarity-cache-data/card_files/similarity_cache_metadata.json -O card_files/similarity_cache_metadata.json || echo "Metadata not found"
|
|
|
|
if [ -f card_files/similarity_cache.parquet ]; then
|
|
echo "✓ Downloaded similarity cache"
|
|
ls -lh card_files/similarity_cache.parquet
|
|
fi
|
|
|
|
- name: Compute arm64 tag
|
|
id: arch_tag
|
|
shell: bash
|
|
run: |
|
|
echo "tag=mwisnowski/mtg-python-deckbuilder:${{ needs.prepare.outputs.version }}-arm64" >> $GITHUB_OUTPUT
|
|
|
|
- name: Docker Hub login
|
|
uses: docker/login-action@v3.5.0
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Set up QEMU (for emulation)
|
|
uses: docker/setup-qemu-action@v3.6.0
|
|
|
|
- name: Set up Buildx
|
|
uses: docker/setup-buildx-action@v3.11.1
|
|
|
|
- name: Build & push arch image (arm64)
|
|
uses: docker/build-push-action@v6.18.0
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
platforms: linux/arm64
|
|
tags: ${{ steps.arch_tag.outputs.tag }}
|
|
labels: ${{ needs.prepare.outputs.labels }}
|
|
build-args: |
|
|
APP_VERSION=${{ needs.prepare.outputs.version }}
|
|
|
|
manifest:
|
|
name: Create latest multi-arch manifest
|
|
runs-on: ubuntu-latest
|
|
needs: [prepare, build_amd64, build_arm64]
|
|
steps:
|
|
- name: Docker Hub login
|
|
uses: docker/login-action@v3.5.0
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
- name: Create & push latest multi-arch manifest
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
VERSION='${{ needs.prepare.outputs.version }}'
|
|
AMD_TAG="mwisnowski/mtg-python-deckbuilder:${VERSION}-amd64"
|
|
ARM_TAG="mwisnowski/mtg-python-deckbuilder:${VERSION}-arm64"
|
|
echo "Creating manifest: latest -> ${AMD_TAG} + ${ARM_TAG}"
|
|
SOURCES="$AMD_TAG $ARM_TAG"
|
|
docker buildx imagetools create -t mwisnowski/mtg-python-deckbuilder:latest $SOURCES
|
|
echo "Inspecting latest"
|
|
docker buildx imagetools inspect mwisnowski/mtg-python-deckbuilder:latest
|
|
|