ci: harden build pipeline per adversarial review
Build ErsatzTV Image / Build & test (.NET) (push) Successful in 1m55s
Build ErsatzTV Image / Build & push image (amd64) (push) Successful in 24s

- Add concurrency group so the single jazz runner can't run the
  push-main-then-push-tag release flow in parallel (shared :buildcache
  + smoke container would collide).
- Add pull_request trigger running the test job only (PRs had no gate);
  skip the build job on PRs.
- Only push images from main or a v* tag (workflow_dispatch from other
  refs now builds without publishing, instead of clobbering :latest/:prod).
- Replace the log-grep smoke check with a real HTTP readiness probe
  (docker exec python3 -> http://localhost:8409/), unique container name,
  and trap-based cleanup to avoid leaks on cancel.
- dotnet test now runs -c Release --no-build (was rebuilding in Debug).
- Directory.Build.props: WarningsAsErrors=NU1904 so critical NuGet
  advisories block in every project, not just ones with
  TreatWarningsAsErrors.
- Dockerfile copies global.json + .editorconfig too, so the image build
  matches CI's SDK pin and analyzer severities.
- Remove dead .github/dependabot.yml + FUNDING.yml (upstream-pointed).
- Rewrite docs/ci-cd.md to the implemented pipeline.

Refs #4, #3, #8.
This commit is contained in:
2026-06-27 00:01:22 +02:00
parent 8c9bd680a4
commit 45627ede82
6 changed files with 130 additions and 94 deletions
+85 -49
View File
@@ -1,58 +1,94 @@
# CI/CD Details for ErsatzTV Fork
# CI/CD for the ErsatzTV Fork
## Upstream GitHub Actions (to adapt for Gitea)
The fork builds its own Docker image via **Gitea Actions** on the homelab and pushes
to the **Gitea container registry**. Runner + registry were provisioned in
server-management#172; the build pipeline is ersatztv#4; test/prod containers are
server-management#481.
### Workflows
| File | Trigger | Purpose |
|------|---------|---------|
| `ci.yml` | Push to main | Version calc → docker.yml + artifacts.yml |
| `release.yml` | GitHub Release | Same but with release version tags |
| `docker.yml` | Reusable workflow | Multi-arch Docker build+push (amd64, arm32v7, arm64) |
| `artifacts.yml` | Reusable workflow | Platform binaries (macOS DMG, Windows exe, Linux) |
| `pr.yml` | Pull request | Build+test on Linux, Windows, Mac |
## The workflow: `.gitea/workflows/docker-build.yml`
### What to keep for Gitea fork
- **Docker build**: Simplify to amd64-only (jazz is x86_64), push to Gitea registry or local registry
- **PR checks**: Build + test on Linux only (single runner on jazz)
- **Drop**: macOS/Windows artifacts, code signing, multi-arch, GHCR/DockerHub push
Single workflow, two jobs (`test` → `build`).
### Build Steps (from pr.yml — the test workflow)
```bash
dotnet restore
sed -i '/Scanner/d' ErsatzTV/ErsatzTV.csproj # strip Scanner project ref
dotnet build --configuration Release --no-restore
dotnet test --blame-hang-timeout "2m" --no-restore --verbosity normal
```
### Triggers & tags
### Docker Build (from docker.yml)
- Uses `docker/build-push-action@v5`
- Dockerfile: `docker/Dockerfile` (amd64), `docker/arm32v7/Dockerfile`, `docker/arm64/Dockerfile`
- Build arg: `INFO_VERSION` for version stamp
- Base image: `ghcr.io/ersatztv/ersatztv-ffmpeg:7.1.1` (custom ffmpeg)
- Needs Java in build stage (OpenAPI generator)
- Multi-stage: ffmpeg base → .NET runtime → build → final
| Trigger | `test` job | `build` job | Image tags pushed |
|---------|:----------:|:-----------:|-------------------|
| `pull_request` | ✅ | — (skipped) | none |
| push to `main` | ✅ | ✅ | `:latest` + `:<short-sha>` |
| push tag `v*` | ✅ | ✅ | `:prod` + `:<version>` + `:<short-sha>` |
| `workflow_dispatch` | ✅ | ✅ | only if ref is `main`/`v*`, else build-only (no push) |
### Image References to Update
- `jasongdove/ersatztv` → fork's registry image name
- `ghcr.io/ersatztv/ersatztv` → Gitea registry or local registry
- `ghcr.io/ersatztv/ersatztv-ffmpeg:7.1.1` — still needed as base; could mirror locally
`:latest` is the **test/dev** channel (every `main` commit). Prod pins **`:prod`**,
never `:latest` — enforced in the prod compose (server-management#481). `:prod` is
only produced by pushing a `v*` tag.
### Gitea Actions Compatibility Notes
- Gitea Actions is GitHub Actions compatible but some actions need replacements
- `actions/checkout@v4` → works in Gitea Actions
- `actions/setup-dotnet@v4` → works in Gitea Actions
- `docker/login-action@v3` → needs Gitea registry credentials instead
- `docker/build-push-action@v5` → works but target registry changes
- `actions/upload-artifact@v4` / `download-artifact@v4` → works in Gitea Actions
- Reusable workflows (`workflow_call`) → supported in Gitea Actions
`concurrency: { group: ersatztv-build, cancel-in-progress: false }` serializes all
runs — the single runner on jazz can't safely run the push-`main`-then-push-`v*`
release flow in parallel (shared `:buildcache` tag, shared smoke container).
### Container Registry Options (from server-management#172)
1. **Gitea built-in** (Packages feature) — images at `192.168.1.95:3000/timothy/<package>`, needs HTTPS or `--insecure-registry`
2. **Local Docker registry** — `registry:2` on jazz at port 5000
### `test` job
### Runner Setup (from server-management#172)
- `gitea/act_runner:latest` container on jazz
- Needs Docker socket for DinD builds
- Register via Gitea Admin → Runners → token
- Labels: `ubuntu-latest`, `docker`
- jazz has 128GB RAM, plenty for .NET builds (2-4GB)
`dotnet restore` → strip the Scanner project ref (`sed -i '/Scanner/d'`, matching the
Docker build) → `dotnet build -c Release` → `dotnet test -c Release --no-build`. Gates
the image build.
### `build` job
1. Compute `INFO_VERSION` (`git describe` + short sha on `main`; tag version on `v*`).
2. `docker/setup-buildx-action` with `buildkitd-config-inline` setting `http = true`
for `192.168.1.95:3000` — **BuildKit does not inherit the host daemon's
`insecure-registries`**, so without this, cache/base-image/push over the HTTP
registry fails (`http: server gave HTTP response to HTTPS client`).
3. `docker/login-action` with repo secrets `REGISTRY_USER` / `REGISTRY_PASSWORD`.
4. `docker/build-push-action@v6`: amd64-only, `docker/Dockerfile`, `INFO_VERSION`
build-arg, registry layer cache (`type=registry,ref=…:buildcache`,
`cache-to … ignore-error=true`).
5. **Smoke test**: pull the just-pushed `:<sha>`, run it, and poll ErsatzTV's web
server from inside the container (`docker exec … python3` → `http://localhost:8409/`).
Unique container name + `trap … EXIT` cleanup. Fails if it never serves HTTP.
## Dockerfile notes (`docker/Dockerfile`)
- Base image: **`192.168.1.95:3000/timothy/ersatztv-ffmpeg:7.1.1`** (our Gitea fork of
the archived `ghcr.io/ersatztv/ersatztv-ffmpeg`). FFmpeg 8 upgrade is backlogged:
base image → ersatztv-ffmpeg#4, app-side compat → ersatztv#9.
- Copies `Directory.Build.props`, `Directory.Build.targets`, `global.json`,
`.editorconfig` before `dotnet restore` so the image build uses the same MSBuild
config, SDK pin, and analyzer severities as local/CI builds (it previously copied
only `*.sln`).
- amd64-only (jazz is x86_64). No arm32/arm64, no DMG/exe artifacts, no GHCR/DockerHub.
## NuGet audit
.NET 10 runs NuGet audit on restore. Several projects set `TreatWarningsAsErrors=true`,
so vulnerable transitive packages failed the build. `Directory.Build.props` demotes
low/moderate/high advisories (NU1901-1903) to warnings and promotes NU1904 (critical)
to an error in **every** project via `WarningsAsErrors`. Underlying vulnerable deps are
tracked in ersatztv#8.
## Registry
Gitea Packages, HTTP-only at `192.168.1.95:3000`. jazz's Docker daemon has it as an
insecure-registry (server-management#172). Images: `192.168.1.95:3000/timothy/ersatztv:<tag>`.
## Test / prod environments
Container/compose wiring lives in **server-management** (project boundary): test
`ersatztv-test` on 8410 (`:latest`), prod `ersatztv` on 8409 (`:prod`). See
server-management#481 for the full spec (registry pull on jazz, volumes, Jellyfin
isolation for test, Watchtower/manual promotion).
## Retired upstream workflows
The upstream `.github/workflows/` (`ci.yml`, `docker.yml`, `artifacts.yml`,
`release.yml`, `pr.yml`, `issue-stale.yml`) were removed — they targeted
GHCR/DockerHub + Azure/Apple signing and called reusable workflows at dead
`ersatztv/ersatztv@main` paths, and ran as noise (incl. a daily stale-issue cron) on
the Gitea runner. Upstream is archived, so there are no future merges to preserve them
for. The dead `.github/dependabot.yml` and `FUNDING.yml` (upstream-pointed) were also
removed.
## Known follow-ups
- Pin third-party actions to commit SHAs (currently floating major tags cloned from
github.com at runtime) — low priority for a homelab; tracked informally.