Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,6 @@ jobs:
echo "$out"
# Only judge our units: the runner's own system units print unrelated warnings.
if echo "$out" | grep -E 'novastack-demo-reset|demo/systemd/' | grep -v 'Unit demo-postgres.service not found' | grep -q .; then exit 1; fi
- name: Reset SQL runs as systemd would run it
# Unescapes $$ like systemd, then runs it against a throwaway Postgres (before and after tables exist)
run: python3 demo/tools/check-reset.py docker
8 changes: 7 additions & 1 deletion demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ demo/install.sh # install or update the units, generate secrets once,
| Update units after a `git pull` | `demo/install.sh` |
| Stop and remove | `demo/install.sh --uninstall` (keeps the secrets and the `novastack-demo-pg` volume) |

## Troubleshooting

- **Tunnel won't connect, `cloudflared` logs `dial udp 10.89.x.1:53: i/o timeout`, often after the host changed networks.** Rootless Podman routes every bridge-networked container through one shared network namespace, which copies the host's routes when it's created. After a network change it can be left without a default route. Check with `podman unshare --rootless-netns ip route`: there must be a `default via …` line. To fix it, stop every rootless container that uses a bridge network (the demo units plus any other stacks, e.g. `systemctl --user stop 'demo-*'`), confirm `podman ps` is empty, then start them again. The namespace is rebuilt with the current routes.
- **`/metrics` is public.** In the tunnel's Routes, the `^/metrics` → `http_status:404` route must be above the plain `rest-demo` route (routes match top to bottom). `cloudflared`'s log line `Updated to new configuration` lists the order it uses.
- **An app keeps restarting:** `journalctl --user -u demo-<app>` and `podman logs demo-<app>`. Its settings are in `~/.config/novastack-demo/<app>.env`.

## Checks

- **CI, every PR** (`demo units` job): Podman 5.8's Quadlet generator accepts every unit, all six services are generated, no unit publishes a port, `install.sh` passes shellcheck, and the reset units pass `systemd-analyze verify`.
- **CI, every PR** (`demo units` job): Podman 5.8's Quadlet generator accepts every unit, all six services are generated, no unit publishes a port, `install.sh` passes shellcheck, the reset units pass `systemd-analyze verify`, and the reset unit's SQL (after systemd's `$$` unescaping) runs against Postgres, both before and after the tables exist.
- **Each image build:** the image runs read-only with no capabilities (and Postgres where needed) and passes the same HTTP checks as the Docker smoke tests.
- **After deploying:** `curl -4 https://rest-demo.cybercoretech.net/health` and the other hostnames, plus `grpcurl grpc-demo.cybercoretech.net:443 list`.
7 changes: 4 additions & 3 deletions demo/systemd/novastack-demo-reset.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ After=demo-postgres.service

[Service]
Type=oneshot
# Tables exist once the apps have run their migrations; IF EXISTS keeps a fresh install quiet.
ExecStart=/usr/bin/podman exec demo-postgres psql -U novastack -d rest -v ON_ERROR_STOP=1 -c "DO $$ BEGIN IF to_regclass('public.items') IS NOT NULL THEN TRUNCATE items, users RESTART IDENTITY; END IF; END $$;"
ExecStart=/usr/bin/podman exec demo-postgres psql -U novastack -d htmx -v ON_ERROR_STOP=1 -c "DO $$ BEGIN IF to_regclass('public.todos') IS NOT NULL THEN TRUNCATE todos, users RESTART IDENTITY; END IF; END $$;"
# Tables exist once the apps have run their migrations; the check keeps a fresh install quiet.
# systemd turns $$ into $, so the SQL dollar quotes are written $$$$.
ExecStart=/usr/bin/podman exec demo-postgres psql -U novastack -d rest -v ON_ERROR_STOP=1 -c "DO $$$$ BEGIN IF to_regclass('public.items') IS NOT NULL THEN TRUNCATE items, users RESTART IDENTITY; END IF; END $$$$;"
ExecStart=/usr/bin/podman exec demo-postgres psql -U novastack -d htmx -v ON_ERROR_STOP=1 -c "DO $$$$ BEGIN IF to_regclass('public.todos') IS NOT NULL THEN TRUNCATE todos, users RESTART IDENTITY; END IF; END $$$$;"
85 changes: 85 additions & 0 deletions demo/tools/check-reset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3
"""Runs the reset unit's SQL against a throwaway Postgres container, the way systemd would.

demo/tools/check-reset.py [docker|podman]

systemd unescapes `$$` to `$` in ExecStart and splits words on quotes (no shell expansion),
so this does the same, then swaps `podman exec demo-postgres` for the chosen engine and a
temporary container. It checks the reset twice: on a fresh database (tables not created yet)
and after inserting rows (they must be gone).
"""
import shlex
import subprocess
import sys
import time
from pathlib import Path

ENGINE = sys.argv[1] if len(sys.argv) > 1 else "docker"
UNIT = Path(__file__).resolve().parent.parent / "systemd" / "novastack-demo-reset.service"
NAME = f"reset-check-{int(time.time())}"
PREFIX = ["/usr/bin/podman", "exec", "demo-postgres"]


def run(*args, check=True):
return subprocess.run(args, check=check, capture_output=True, text=True)


def psql(db, sql):
return run(ENGINE, "exec", NAME, "psql", "-U", "novastack", "-d", db, "-tAc", sql).stdout.strip()


def reset_commands():
commands = []
for line in UNIT.read_text().splitlines():
if line.startswith("ExecStart="):
argv = shlex.split(line[len("ExecStart="):].replace("$$", "$"))
assert argv[:3] == PREFIX, f"unexpected ExecStart: {argv[:3]}"
commands.append([ENGINE, "exec", NAME, *argv[3:]])
assert len(commands) == 2, f"expected 2 ExecStart lines, found {len(commands)}"
return commands


def reset():
for cmd in reset_commands():
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
sys.exit(f"reset failed: {result.stderr.strip()}")


def main():
init = Path(__file__).resolve().parent.parent / "postgres" / "init.sql"
run(ENGINE, "run", "-d", "--name", NAME,
"-e", "POSTGRES_USER=novastack", "-e", "POSTGRES_PASSWORD=check", "-e", "POSTGRES_DB=rest",
"-v", f"{init}:/docker-entrypoint-initdb.d/init.sql:ro,Z",
"docker.io/library/postgres:17.10-alpine")
try:
for _ in range(60):
if run(ENGINE, "exec", NAME, "psql", "-U", "novastack", "-d", "htmx", "-tAc", "select 1",
check=False).returncode == 0:
break
time.sleep(1)
else:
sys.exit("postgres did not come up")

reset()
print("ok reset on a fresh database (no tables yet)")

psql("rest", "create table items(id bigserial primary key, name text);"
"create table users(id bigserial primary key, username text);"
"insert into items(name) values ('a'),('b'); insert into users(username) values ('u');")
psql("htmx", "create table todos(id bigserial primary key, title text);"
"create table users(id bigserial primary key, username text);"
"insert into todos(title) values ('t'); insert into users(username) values ('u');")
reset()
counts = [psql("rest", "select count(*) from items"), psql("rest", "select count(*) from users"),
psql("htmx", "select count(*) from todos"), psql("htmx", "select count(*) from users")]
assert counts == ["0"] * 4, f"rows left after reset: {counts}"
psql("rest", "insert into items(name) values ('c')")
assert psql("rest", "select max(id) from items") == "1", "ids did not restart at 1"
print("ok reset empties items, todos and users and restarts ids")
finally:
run(ENGINE, "rm", "-f", NAME, check=False)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion scripts/docker-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ checks_realtime() {
expect "publish accepted (202)" sh -c "[ \"\$(curl -s -o /dev/null -w %{http_code} -H 'content-type: application/json' -d '{\"message\":\"smoke-hello\"}' $b/publish)\" = 202 ]"
wait "$sse" || true
expect "SSE stream delivered the message" grep -q 'data: smoke-hello' "$events"
expect "websocket upgrade (101)" sh -c "[ \"\$(curl -s -o /dev/null -w %{http_code} --max-time 3 -H 'Connection: Upgrade' -H 'Upgrade: websocket' -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' $b/ws)\" = 101 ]"
expect "websocket upgrade (101)" sh -c "[ \"\$(curl -s -o /dev/null -w %{http_code} --max-time 3 --http1.1 -H 'Connection: Upgrade' -H 'Upgrade: websocket' -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' $b/ws)\" = 101 ]"
}

checks_minimal() {
Expand Down
Loading