Files
Elternbeirat/.gitea/workflows/deploy.yml
T
TomandClaude Opus 5.5 955e2faa3f Remove untagged images after a healthy deploy
Every deploy leaves the previous :latest behind untagged on Unraid. The deploy
job now prunes untagged images once the health gate passed; a rollback pulls
its :<sha> from the registry anyway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 20:53:41 +02:00

127 lines
4.7 KiB
YAML

# Builds the production image on every push to main, pushes it to the Gitea
# registry (tagged :latest AND the short commit SHA, for rollback) and deploys the
# stack on Unraid from the repo's compose.yaml -- the repo is the only copy of the
# compose file; there is no duplicate in the Compose Manager.
#
# The deploy works because the act_runner runs ON Unraid and hands its Docker
# socket to the job: every `docker` command here talks to the Unraid daemon, so
# absolute paths in compose.yaml (the pb_data bind mount) are host paths.
#
# `docker compose up -d` only recreates containers whose image or config changed:
# a new image restarts eb-blazor for a few seconds, eb-pocketbase and eb-ddns keep
# running. Content lives in PocketBase and is never touched by a deploy.
#
# Required repository secrets (Gitea -> repo -> Settings -> Actions -> Secrets):
# REGISTRY_USER the registry username (e.g. Tom)
# REGISTRY_TOKEN a Gitea access token with package:write -- NOT the password
# STRATO_DYNDNS_PASSWORD the DynDNS password for eb-ddns (docs/deployment.md)
name: Build and deploy
on:
push:
branches: [main]
# Docs alone change neither the image nor the stack.
paths-ignore:
- "docs/**"
- "**/*.md"
# Manual run from Gitea (Actions tab), e.g. to redeploy after a server restart.
workflow_dispatch:
# Two quick pushes must not deploy over each other; the later one waits.
concurrency:
group: deploy
cancel-in-progress: false
env:
IMAGE: gitea.anticarnist.de/tom/elternbeirat
COMPOSE_VERSION: v2.39.4
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out the source
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Gitea registry
uses: docker/login-action@v3
with:
registry: gitea.anticarnist.de
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
# The short SHA names the image content unambiguously and never moves,
# so it is the stable handle for a rollback.
- name: Compute the short commit SHA
id: sha
run: echo "short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Build and push (:latest and :<sha>)
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:${{ steps.sha.outputs.short }}
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Check out the source
uses: actions/checkout@v4
# The job image ships the Docker CLI (the build needs it) but not
# necessarily the compose plugin; install a pinned one if it is missing.
- name: Ensure docker compose
run: |
docker compose version && exit 0
mkdir -p ~/.docker/cli-plugins
curl -fsSL -o ~/.docker/cli-plugins/docker-compose \
"https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-linux-x86_64"
chmod +x ~/.docker/cli-plugins/docker-compose
docker compose version
# The image is private; the pull below runs with this job's login.
- name: Log in to the Gitea registry
uses: docker/login-action@v3
with:
registry: gitea.anticarnist.de
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
# An explicit pull: `up` alone keeps a local :latest and would not notice
# the image the build job just pushed.
- name: Pull and start the stack
env:
STRATO_DYNDNS_PASSWORD: ${{ secrets.STRATO_DYNDNS_PASSWORD }}
run: |
docker compose -f compose.yaml pull
docker compose -f compose.yaml up -d --wait --remove-orphans
# /health answers 200 only when the app runs AND reaches PocketBase. It is
# checked from inside proxynet, the same way NPM reaches the app. A failure
# marks the run red; the rollback stays a deliberate step (docs/deployment.md).
- name: Health gate
run: |
for attempt in $(seq 1 30); do
if docker run --rm --network proxynet busybox:1.37 \
wget -qO- http://eb-blazor:8080/health; then
exit 0
fi
sleep 2
done
echo "eb-blazor did not report healthy within 60 seconds." >&2
docker logs --tail 50 eb-blazor >&2
exit 1
# Every deploy leaves the previous :latest behind as an untagged image. Only
# untagged images go; a rollback pulls its :<sha> from the registry anyway.
- name: Remove untagged images
run: docker image prune -f