- deploy.yml gets a deploy job after the build: pull, compose up on Unraid through the runner's Docker socket, then a health gate on eb-blazor /health from inside proxynet; docs-only pushes trigger nothing, manual runs allowed - STRATO_DYNDNS_PASSWORD comes from a Gitea secret instead of the Compose Manager env file - restart: always, because Unraid stops containers explicitly on shutdown and unless-stopped would leave the stack down after a reboot; the dev overlay turns it off - Docs describe the automatic rollout and the one-time switch away from the Compose Manager stack Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
122 lines
4.5 KiB
YAML
122 lines
4.5 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
|