Deploy the stack from the repo's compose.yaml via Gitea Actions

- 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>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-10-10 00:37:42 +02:00
1 parent 4968b62f06
commit 05b1666f81
5 files changed
+152 -99

No files matched your search

+78 -11
View File
@@ -1,25 +1,41 @@
# Builds the production image on every push to main and pushes it to the Gitea # Builds the production image on every push to main, pushes it to the Gitea
# registry, tagged with :latest AND the short commit SHA (for rollback) -- the # registry (tagged :latest AND the short commit SHA, for rollback) and deploys the
# same tagging scheme as scripts/release.sh, but run by the act_runner instead # stack on Unraid from the repo's compose.yaml -- the repo is the only copy of the
# of by hand. # compose file; there is no duplicate in the Compose Manager.
# #
# It does NOT deploy: pulling and starting the new :latest on Unraid stays a # The deploy works because the act_runner runs ON Unraid and hands its Docker
# manual, deliberate step (Compose Down/Up). Auto-deploy via Watchtower is an # socket to the job: every `docker` command here talks to the Unraid daemon, so
# open item in docs/deployment.md and needs a health gate first, so a broken # absolute paths in compose.yaml (the pb_data bind mount) are host paths.
# page can never go live unnoticed. #
# `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): # Required repository secrets (Gitea -> repo -> Settings -> Actions -> Secrets):
# REGISTRY_USER the registry username (e.g. Tom) # REGISTRY_USER the registry username (e.g. Tom)
# REGISTRY_TOKEN a Gitea access token with package:write -- NOT the password # 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 push image name: Build and deploy
on: on:
push: push:
branches: [main] 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: env:
IMAGE: gitea.anticarnist.de/tom/elternbeirat IMAGE: gitea.anticarnist.de/tom/elternbeirat
COMPOSE_VERSION: v2.39.4
jobs: jobs:
build: build:
@@ -52,3 +68,54 @@ jobs:
tags: | tags: |
${{ env.IMAGE }}:latest ${{ env.IMAGE }}:latest
${{ env.IMAGE }}:${{ steps.sha.outputs.short }} ${{ 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
+4
View File
@@ -10,6 +10,9 @@
services: services:
eb-pocketbase: eb-pocketbase:
# The base's `restart: always` is for Unraid; locally the stack should not come
# back on its own after a reboot of the dev machine.
restart: "no"
ports: ports:
- "8090:8090" # PocketBase admin UI at http://localhost:8090/_/ - "8090:8090" # PocketBase admin UI at http://localhost:8090/_/
environment: environment:
@@ -36,6 +39,7 @@ services:
# changes show up without a push+CI round-trip. image: "" clears the inherited # changes show up without a push+CI round-trip. image: "" clears the inherited
# tag from the base, which forces compose to use the build below. # tag from the base, which forces compose to use the build below.
image: "" image: ""
restart: "no"
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
+11 -3
View File
@@ -7,6 +7,14 @@
# web app publishes no host port. The `ports:` block on PocketBase is TEMPORARY: it # web app publishes no host port. The `ports:` block on PocketBase is TEMPORARY: it
# is the editors' way onto the admin UI until they reach it through an NPM subdomain # is the editors' way onto the admin UI until they reach it through an NPM subdomain
# (#9). Unraid setup: docs/unraid-infrastructure.md. # (#9). Unraid setup: docs/unraid-infrastructure.md.
#
# On Unraid this file is deployed as is by .gitea/workflows/deploy.yml (project
# eb-stack), not pasted into the Compose Manager.
#
# `restart: always`, not `unless-stopped`: Unraid stops every container explicitly
# when Docker or the array goes down, and `unless-stopped` treats that as a manual
# stop -- the stack would stay down after a reboot. Without the Compose Manager
# there is no autostart toggle to bring it back.
# For local development use the dev overlay on top, which adds host ports and builds # For local development use the dev overlay on top, which adds host ports and builds
# the web image from source: # the web image from source:
@@ -25,7 +33,7 @@ services:
eb-pocketbase: eb-pocketbase:
image: ghcr.io/muchobien/pocketbase:0.40.4 image: ghcr.io/muchobien/pocketbase:0.40.4
container_name: eb-pocketbase container_name: eb-pocketbase
restart: unless-stopped restart: always
environment: environment:
TZ: Europe/Berlin TZ: Europe/Berlin
volumes: volumes:
@@ -47,7 +55,7 @@ services:
eb-web: eb-web:
image: gitea.anticarnist.de/tom/elternbeirat:latest image: gitea.anticarnist.de/tom/elternbeirat:latest
container_name: eb-blazor container_name: eb-blazor
restart: unless-stopped restart: always
depends_on: depends_on:
eb-pocketbase: eb-pocketbase:
condition: service_healthy condition: service_healthy
@@ -71,7 +79,7 @@ services:
# tests quiet, where the service is disabled. Setup: docs/deployment.md. # tests quiet, where the service is disabled. Setup: docs/deployment.md.
image: qmcgaw/ddns-updater:2.10 image: qmcgaw/ddns-updater:2.10
container_name: eb-ddns container_name: eb-ddns
restart: unless-stopped restart: always
environment: environment:
TZ: Europe/Berlin TZ: Europe/Berlin
PERIOD: 5m PERIOD: 5m
+48 -74
View File
@@ -1,8 +1,9 @@
# Deployment # Deployment
How a new version of the website ends up on Unraid. Current state: How a new version of the website ends up on Unraid: a merge to `main` runs
**manual** — build the image locally, push it to the Gitea registry, pull it on `.gitea/workflows/deploy.yml`, which builds the image, pushes it to the Gitea
Unraid. Automation via Gitea Actions comes later. registry and starts the stack on Unraid from the repo's `compose.yaml`. Nothing is
copied or pasted by hand.
The site runs as a **three-container stack** (project `eb-stack`): the Blazor app The site runs as a **three-container stack** (project `eb-stack`): the Blazor app
(`eb-blazor`), a PocketBase container (`eb-pocketbase`) that holds the content, (`eb-blazor`), a PocketBase container (`eb-pocketbase`) that holds the content,
@@ -52,16 +53,11 @@ DynDNS password.
2. **Strato password:** DynDNS accepts the package password **or** a separate 2. **Strato password:** DynDNS accepts the package password **or** a separate
DynDNS password, set under **Security → Set passwords** (not under Dynamic DynDNS password, set under **Security → Set passwords** (not under Dynamic
DNS). Use the separate one — the package password also opens the webspace. DNS). Use the separate one — the package password also opens the webspace.
3. **Compose Manager Plus** → stack **eb-stack** → env file: add 3. **Gitea** → repo → **Settings** → **Actions** → **Secrets**: add
`STRATO_DYNDNS_PASSWORD`. The deploy hands it to compose, which fills it into
```ini `CONFIG`. The password ends up inside JSON, so it must not contain `"` or `\`;
STRATO_DYNDNS_PASSWORD=<DynDNS password> avoid `$` and `#` as well.
``` 4. Run the workflow (**Actions** → **Build and deploy** → **Run workflow**).
**No quotes** — Compose Manager Plus passed them on as part of the password,
which Strato answered with `badauth`. The password ends up inside JSON, so it
must not contain `"` or `\`; avoid `$` and `#` as well.
4. **Compose Down**, then **Compose Up** (a plain restart keeps the old env).
`docker logs eb-ddns` shows `Updating record … to use <IP>` with no `ERROR` `docker logs eb-ddns` shows `Updating record … to use <IP>` with no `ERROR`
after it. after it.
5. Check: the Strato nameservers answer with the public IP of the connection 5. Check: the Strato nameservers answer with the public IP of the connection
@@ -79,8 +75,8 @@ domain or password are wrong:
curl -u elternbeirat-igmh.info "https://dyndns.strato.com/nic/update?hostname=elternbeirat-igmh.info&myip=<current IP>" curl -u elternbeirat-igmh.info "https://dyndns.strato.com/nic/update?hostname=elternbeirat-igmh.info&myip=<current IP>"
``` ```
> **The DynDNS password is a secret** like the registry token: only in the stack's > **The DynDNS password is a secret** like the registry token: only as a Gitea
> env on the server, never in Git. A missing value does not stop the stack; it > secret, never in Git. A missing value does not stop the stack; it
> shows up as a failed update in `docker logs eb-ddns`. The dev overlay disables > shows up as a failed update in `docker logs eb-ddns`. The dev overlay disables
> `eb-ddns`, so a local `up` never touches the public DNS. > `eb-ddns`, so a local `up` never touches the public DNS.
@@ -125,67 +121,48 @@ dev stack (`entwicklung.md`) — it builds the web image from source and pushes
nothing, so a development state can never accidentally land in the registry as nothing, so a development state can never accidentally land in the registry as
`:latest`. `:latest`.
## Rolling out a new version (manual) ## Rolling out a new version
Prerequisite: logged in to the registry once (see below). Then, **on main** and Merge the pull request into `main`. The workflow then:
with a clean working directory:
```bash 1. builds the image and pushes it as `:latest` **and** `:<short-sha>` (rollback),
scripts/release.sh 2. pulls it on Unraid and runs `docker compose up -d` with the repo's
``` `compose.yaml` — only containers whose image or config changed are recreated,
3. checks `http://eb-blazor:8080/health` from inside `proxynet` (health gate). A
red run means the new version is live but not healthy: roll back (below).
The script builds the image, tags it with `:latest` **and** the short commit SHA Pushes that only touch `docs/` or Markdown files trigger nothing. A manual run
(for rollback), and pushes both. It **aborts** if you are not on `main` or have (**Actions** → **Build and deploy** → **Run workflow**) redeploys the current
uncommitted changes, and warns about unpushed commits. `main`.
> The image path `gitea.anticarnist.de/tom/elternbeirat` is **lowercase** — > The image path `gitea.anticarnist.de/tom/elternbeirat` is **lowercase** —
> container registries require that in the path, even though the user (`Tom`) and > container registries require that in the path, even though the user (`Tom`) and
> the repo (`Elternbeirat`) are capitalized. > the repo (`Elternbeirat`) are capitalized.
### Logging Unraid in to the registry once `scripts/release.sh` still builds and pushes by hand from `main`, as a fallback
when the runner is down. It does not deploy.
The image is **private**, so Unraid has to log in once before it can pull. The ### One-time switch from the Compose Manager
**Compose Manager Plus** plugin has no UI field for this — the login runs through
the Unraid terminal (`>_` symbol at the top right of the web interface, prompt
`root@Cube:~#`):
```bash Before the workflow took over, the stack was a Compose Manager stack
docker login gitea.anticarnist.de (`elternbeirat`) with a pasted copy of `compose.yaml`. The workflow runs the stack
# Username: Tom as project `eb-stack`; the fixed `container_name`s would clash with the old
# Password: <package token> containers, so the old stack goes first:
```
The login stays stored; it only has to be repeated when the token changes. Two 1. Add the secrets in Gitea (see "Automation" below).
pitfalls learned from experience: 2. Compose Manager → stack `elternbeirat` → **Compose Down**, then delete the
stack. `pb_data` is a bind mount and stays.
3. Run the workflow by hand. The site is down from step 2 until it finishes.
- **Don't confuse it with PowerShell/laptop.** The login has to happen in the From then on, a click on **Compose Up** in the Compose Manager is never needed —
*Unraid* terminal (`root@Cube`), not in Windows PowerShell (`PS C:\`). The laptop and there is no stale copy left there that could be started by accident.
needs the login only to *push*, Unraid to *pull*.
- **A wrong username gets stuck.** If the login reports "Stored credentials
invalid or expired" and does *not* ask for the name, first `docker logout
gitea.anticarnist.de`, then log in again — otherwise a nonsense username gets
stored by accident.
- **Plain-text warning.** Docker stores the token unencrypted in
`/root/.docker/config.json`. On your own server, okay for a start.
*Cleaner later:* set up a credential helper (→ open item below).
### Pull and start again on Unraid
In the **Compose Manager Plus** plugin (Unraid web interface):
- **Docker** tab → **Compose** section → stack **eb-stack** →
**Compose Down**, then **Compose Up** (or "Pull" + "Up", depending on the plugin
version), so that the new `:latest` is pulled. Only the `eb-blazor` image
changes on a deploy; `eb-pocketbase` and its `pb_data` volume stay as they are.
> `docker compose up` does **not** automatically re-pull a `:latest` if an image of
> the same name is already present locally. When in doubt, explicitly "Pull" first.
--- ---
## The compose files ## The compose files
`compose.yaml` is the **production** base and is the file Unraid uses. It defines `compose.yaml` is the **production** base; the workflow deploys it to Unraid as
is. It defines
all services. `eb-blazor` publishes no host port and joins the external network all services. `eb-blazor` publishes no host port and joins the external network
`proxynet`, so NPM is the only path to the web app. `eb-pocketbase` still publishes `proxynet`, so NPM is the only path to the web app. `eb-pocketbase` still publishes
`8090` for the editors until they reach it through an NPM subdomain (see #9). `8090` for the editors until they reach it through an NPM subdomain (see #9).
@@ -224,10 +201,9 @@ web app is needed — the site comes back by itself.
## Rollback ## Rollback
`scripts/release.sh` additionally tags each release with the short commit SHA, Every image is also tagged with the short commit SHA, which — unlike the moving
which — unlike the moving `:latest` — never shifts. To roll back, replace `:latest` — never shifts. To roll back, pin that SHA in `compose.yaml` on a branch,
`:latest` in the Unraid `compose.yaml` with the `:<sha>` of the last working state merge it and let the workflow deploy it:
and bring it back up:
```yaml ```yaml
image: gitea.anticarnist.de/tom/elternbeirat:99dd052 # instead of :latest image: gitea.anticarnist.de/tom/elternbeirat:99dd052 # instead of :latest
@@ -240,25 +216,23 @@ Which SHA tags are in the registry is shown by Gitea under
## Automation ## Automation
### Build and push (done) ### Build and deploy (done)
`.gitea/workflows/deploy.yml` builds the image on every push to `main` and pushes `.gitea/workflows/deploy.yml` has two jobs: `build` (image → registry) and
it to the registry, tagged `:latest` **and** `:<short-sha>` — the same scheme as `deploy` (compose up on Unraid + health gate). The `deploy` job works because the
`scripts/release.sh`, just run by the `act_runner` instead of by hand. It does `act_runner` runs on Unraid and passes its Docker socket into the job, so every
**not** deploy; pulling and starting the new `:latest` on Unraid stays a manual, `docker` command there talks to the Unraid daemon.
deliberate step (see "Pull and start again on Unraid" above).
Requires two repository secrets (Gitea → repo → **Settings** → **Actions** → Requires three repository secrets (Gitea → repo → **Settings** → **Actions** →
**Secrets**): **Secrets**):
- `REGISTRY_USER` — the registry username (e.g. `Tom`). - `REGISTRY_USER` — the registry username (e.g. `Tom`).
- `REGISTRY_TOKEN` — a Gitea access token with **`package: write`**, *not* the - `REGISTRY_TOKEN` — a Gitea access token with **`package: write`**, *not* the
login password. login password.
- `STRATO_DYNDNS_PASSWORD` — the DynDNS password for `eb-ddns` (see above).
The workflow currently only builds and pushes — it does **not** run the tests Still open: the workflow does not run the tests yet, and a failed health gate
yet, and it does **not** deploy. Those open steps (tests in the workflow, does not roll back on its own.
auto-deploy with a health gate via Watchtower, encrypting the registry token on
Unraid) are tracked as Gitea issues under the "Elternbeirat-Website" milestone.
Two known pitfalls: the `act_runner` needs Docker socket access to build, and it Two known pitfalls: the `act_runner` needs Docker socket access to build, and it
must offer the `ubuntu-latest` label the workflow asks for. To check the runner: must offer the `ubuntu-latest` label the workflow asks for. To check the runner:
+11 -11
View File
@@ -10,7 +10,7 @@ What runs on the Unraid host and how the website stack fits in. This is the
| LAN IP | `192.168.1.14` | | LAN IP | `192.168.1.14` |
| Web UI | `https://unraid.server:44302` | | Web UI | `https://unraid.server:44302` |
| Version | Unraid OS 7.0.1 | | Version | Unraid OS 7.0.1 |
| Stack management | Compose Manager plugin, stack `elternbeirat` | | Stack management | Gitea Actions (`.gitea/workflows/deploy.yml`), no Compose Manager |
| Docker network for NPM | `proxynet` (created with `docker network create proxynet`) | | Docker network for NPM | `proxynet` (created with `docker network create proxynet`) |
**Settings → Docker → Advanced View → Preserve user defined networks: Yes.** **Settings → Docker → Advanced View → Preserve user defined networks: Yes.**
@@ -19,17 +19,17 @@ attached to it fails to start.
## Website stack ## Website stack
The stack is created in the Compose Manager under the name `elternbeirat`. Its The stack is deployed by `.gitea/workflows/deploy.yml` as project `eb-stack`,
compose content is a copy of `compose.yaml` **without the comments**, pasted straight from the repo's `compose.yaml` (`deployment.md`). It is **not** a Compose
into the stack's config in the Unraid UI. Manager stack: there is no copy of the compose file on the server. It shows up
on the Docker tab like any other container.
> **The project name comes from the stack folder, not from `name:`.** The The `Gitea-Runner` container runs the deploy. It has `/var/run/docker.sock` mounted,
> Compose Manager starts the stack with `-p elternbeirat`, which overrides so the workflow's `docker compose` talks to the Unraid daemon directly.
> `name: eb-stack`. Renaming the stack in the UI does not change it. That is why
> `compose.yaml` gives the stack's network the fixed name `eb-internal` instead of > **Network names.** The stack's own network has the fixed name `eb-internal`.
> the derived `elternbeirat_default`. Changing a network name needs **Compose Down** > Changing a network name needs `docker compose down` and then `up`; a plain `up`
> and then **Compose Up**; a plain Up fails because the existing containers still > fails because the existing containers still point at the old network.
> point at the old network.
| Container | Network | Container port | Host port | | Container | Network | Container port | Host port |
|---|---|---|---| |---|---|---|---|