Trying a web UI change meant starting Postgres, running the server, bootstrapping an account, creating a team and an integration, and firing alerts by hand. make dev does that: a throwaway Postgres on port 5434, the server on :8080, an administrator, a second user, and ten incidents in different states (triggered, acknowledged, snoozed, resolved). The database is new every run, so the seed is always the same. It checks the port is free first, proves the seeded login works before it prints it, and makes sure the server is gone when it exits. The first version printed a login that did not work when something else held the port, or when it started the server during the Postgres image's first-run restart. That restart also bit make test-db: pg_isready answers on the socket while the image is still setting up, then Postgres restarts, and a suite started in that gap failed every api test in 0.00s. Both now ask over TCP with a real query, as the server and the tests connect. Server code and the shipped image are untouched; this is a dev convenience like test-db.
5.6 KiB
Development and releasing
Building, testing and releasing the server. Back to the README and the documentation index.
Upgrading
The schema is a single baseline (internal/db/migrations/001_schema.sql) and no
release has shipped yet, so there is no upgrade path from earlier development
databases: start from an empty one. Changes after the first release arrive as
new numbered migrations.
Development
make test-db # start a local Postgres for the tests (podman or docker)
make test # run all tests
go build ./... # compile all packages
go run ./cmd/terdut # run locally (needs TERDUT_DB_DSN)
make dev # run locally with seeded incidents, to try the web UI
make dev (scripts/dev.sh) starts a throwaway Postgres on port 5434, runs the server on
:8080 and seeds an administrator, a team and ten incidents in different states, then prints
the login. The database is new every run, and Ctrl-C removes it. The web files are embedded in
the binary, so after editing internal/web/static/ stop it and run it again.
The tests need a real Postgres, because the server does — there is no in-memory Postgres.
TERDUT_TEST_DSN says where it is, make test-db starts
one on port 5433 and prints the DSN, and make test-db-stop removes it. Each test gets its
own schema on that server, so tests cannot see each other's rows. An unset TERDUT_TEST_DSN
fails the suite rather than skipping it: a run that quietly tests nothing is worse than one
that does not run.
make fmt lint test helm-lint is the gate. It mirrors .gitea/workflows/ci.yaml step for
step, so a green run here means a green pipeline — with one deliberate exception: make test
adds -race, which CI does not. The sweeper, the notifier goroutine and the dead man's switch
sweep all run concurrently against the same database, and a race between them would surface as
a flaky incident in production rather than as a red build.
The web UI lives in internal/web/static/ as plain HTML, CSS and ES modules,
embedded into the binary with go:embed. It has no build step and no npm, so
editing a file and restarting the server is the whole loop.
Releasing
push or PR → ci.yaml gofmt, go vet, go test -race
govulncheck, gitleaks
helm lint + render
push tag vX.Y.Z → release.yaml the same gate, then publish:
git.ryuvia.com/niklas/terdut-server:vX.Y.Z
oci://git.ryuvia.com/niklas/terdut-server X.Y.Z
then trivy-scan the pushed image
PR to Ryuvia/charts → bump the wrapper chart to X.Y.Z; on merge
Flux reconciles and the release rolls out
Both artifacts go to the personal Gitea namespace rather than ryuvia, because Gitea
scopes package visibility to the owner with no per-package override — so ryuvia/* is private
because the org is. Publishing to niklas keeps them anonymously pullable, which is why no
pull secret is needed in the cluster. Same reasoning, and the same choice, as riksdata and
rd-web.
Saying "Release" runs all three rows: the release skill commits, pushes, tags, waits for
the pipeline, and opens the Ryuvia/charts PR, stopping before the merge. See
~/.claude/skills/release/, or .release.conf here for this repo's part of it.
The chart is published only from the tag, by the chart job. There used to be a second
publisher on every charts/** push to main, and the two raced for the same chart version with
different answers — chart 0.9.0 went out reading appVersion: "latest" that way. One
publisher, triggered by the tag (766f439). The cost is that a chart-only change has no
version of its own and rides the next app tag.
Both workflows are thin drivers over the Makefile: ci.yaml runs make fmt lint test and
make helm-lint, release.yaml adds make binaries, make push, make helm-package and
make helm-push. That is deliberate — it is what makes a green local gate and a green
pipeline the same code rather than two descriptions of it, and it is how riksdata and rd-web
have always worked.
make push builds and pushes in one step, unlike those two, because the image is
linux/amd64,linux/arm64 and buildx cannot load a multi-platform result into the local image
store. make build stays single-platform and local-only. Both refuse VERSION=dev:
publishing is one command, so it is also one command to run by accident. Publishing happens
by pushing a tag.
Two things the release process needs to know about this repo:
- The image scan runs after publishing, like riksdata's and rd-web's: trivy cannot read
a locally built image on this runner, so it pulls the pushed one. A red
scan-imagemeans do not bump the wrapper chart to that version — it cannot unpublish anything. The image isFROM scratch, so trivy sees exactly one target, the Go binary and its module graph. - The wrapper chart's
values.yamlhas twotag:lines — the app image and the python backup sidecar — sochart-bumpis given--imageto say which one moves. Once the wrapper chart drops the sidecar and declares apostgresqlCR instead, there is onetag:line again, and--imagebecomes belt and braces.
The wrapper chart must have its own version: bumped in the same commit. Flux reconciles
with reconcileStrategy: ChartVersion, so a chart whose version did not change produces no
new artifact and the change is never deployed — with no error anywhere.