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
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ updates:

- package-ecosystem: github-actions
directory: /
# PostgreSQL majors move by hand with a data upgrade (docker-compose.yml); a bump would
# also turn the one-shot 17 dump image into 18.
ignore:
- dependency-name: postgres
update-types: ["version-update:semver-major"]
schedule:
interval: weekly
cooldown:
Expand All @@ -52,6 +57,11 @@ updates:

- package-ecosystem: docker
directory: /
# PostgreSQL majors move by hand with a data upgrade (docker-compose.yml); a bump would
# also turn the one-shot 17 dump image into 18.
ignore:
- dependency-name: postgres
update-types: ["version-update:semver-major"]
schedule:
interval: weekly
cooldown:
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ jobs:
profile: [normal, fips]
services:
postgres:
image: postgres:17-alpine
image: postgres:18.7-alpine3.24@sha256:0115267ab5a509022df9319c77be365cef335adb71556c75f60f5360ee247e71
env:
POSTGRES_USER: ci
POSTGRES_PASSWORD: ci
Expand Down Expand Up @@ -330,7 +330,7 @@ jobs:
name: Docker image build & run
if: github.event.pull_request.draft != true
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Build image
Expand All @@ -339,6 +339,10 @@ jobs:
- name: Strong-key profile preserves Compose configuration
run: python3 docs/check-strong-crypto-compose.py

# Seeds 17 data with the previous docker-compose.yml, then proves this one moves it to 18.
- name: PostgreSQL 17 to 18 upgrade on docker-compose.yml
run: scripts/test-postgres-17-to-18.sh

- name: Container serves the app
run: |
# The hardening docker-compose.yml applies, so the image is proven to run under it.
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Design authority: `docs/superpowers/specs/2026-09-26-kypulse-design.md`. Plans l
- `internal/egress`, `internal/poller`, `internal/alerts`, `internal/notify`, `internal/monitor`,
`internal/kyyard`: the monitoring backend; each has its own AGENTS.md.
- `web/`: the React PWA, embedded into the binary from `web/dist`.
- `scripts/`: smoke test.
- `scripts/`: smoke test; `postgres-17-to-18.sh` is the shared Ky kit, vendored byte for byte (never edit it here), and `test-postgres-17-to-18.sh` proves it on `docker-compose.yml`.
- `docs/RESTORE.md`: restore runbook.
- `docs/STRONG-CRYPTO.md`, `docker-compose.strong-crypto.yml` and
`docs/check-strong-crypto-compose.py`: supported key/TLS configuration,
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.6.1 — pending

- The bundled PostgreSQL (`--profile postgres`) moves from 17 to 18 (`18.7`, pinned by digest), in a new `postgres` volume. The next `up` dumps the 17 `pgdata` volume once and restores it into 18; `pgdata` is kept for rollback, and removing it is the operator's choice. It needs about twice the 17 data in free disk. Read [PostgreSQL 17 to 18](docs/CONFIGURATION.md#postgresql-17-to-18) before upgrading.

- Keep SQLite `v1.62.0` with its upstream-required libc `v1.80.1` and memory `v1.12.1`; defer independent updates of those runtime dependencies.

- Prepare application version `0.6.1` (from `0.6.0`) for the compatible dependency refresh. Rebuild or install the updated application; this version bump requires no additional data, account, key or configuration migration.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test-race:

# Runs the same suite against PostgreSQL; needs a reachable server. The default DSN matches
# CI's throwaway one, e.g. docker run --rm -d -p 127.0.0.1:5432:5432 -e POSTGRES_USER=ci
# -e POSTGRES_PASSWORD=ci -e POSTGRES_DB=ci_test postgres:17-alpine
# -e POSTGRES_PASSWORD=ci -e POSTGRES_DB=ci_test postgres:18.7-alpine3.24@sha256:0115267ab5a509022df9319c77be365cef335adb71556c75f60f5360ee247e71
test-postgres:
@echo "==> Running test suite against PostgreSQL..."
@KYPULSE_TEST_POSTGRES_DSN="$${KYPULSE_TEST_POSTGRES_DSN:-postgres://ci:ci@127.0.0.1:5432/ci_test?sslmode=disable}" go test -count=1 ./...
Expand Down
63 changes: 63 additions & 0 deletions cmd/server/deploy_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"crypto/sha256"
"fmt"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -65,3 +67,64 @@ func TestComposeForwardsSettingsAndBindsLoopback(t *testing.T) {
t.Errorf("app port is not loopback by default: %v", ports)
}
}

// The bundled PostgreSQL is 18, pinned by digest, on the volume layout 18 accepts, and an
// install that ran 17 is moved by the vendored, unmodified upgrade script: never a bare image
// bump, which leaves 18 refusing the old mount. scripts/test-postgres-17-to-18.sh runs it.
func TestComposePostgres18UpgradesFrom17(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("..", "..", "docker-compose.yml"))
if err != nil {
t.Fatal(err)
}
body := string(raw)
service := func(name string) string {
m := regexp.MustCompile(`(?ms)^ ` + name + `:\n(.*?)(?:\n\n|\z)`).FindStringSubmatch(body)
if m == nil {
t.Fatalf("docker-compose.yml has no %s service", name)
}
return m[1]
}
for name, rules := range map[string][]string{
"postgres": {
`(?m)^ image: postgres:18\.7-alpine3\.24@sha256:0115267ab5a509022df9319c77be365cef335adb71556c75f60f5360ee247e71$`,
`(?m)^ entrypoint: \[bash, /ky/postgres-17-to-18\.sh, restore\]$`,
`(?m)^ command: \[postgres\]$`,
`(?m)^ stop_grace_period: 2m$`,
`(?m)^ postgres-17-dump:\n condition: service_completed_successfully$`,
`(?m)^ - postgres:/var/lib/postgresql$`,
`(?m)^ - \./scripts/postgres-17-to-18\.sh:/ky/postgres-17-to-18\.sh:ro$`,
},
"postgres-17-dump": {
`(?m)^ image: postgres:17\.12-alpine3\.24@sha256:f9cf3e1f0066f0eb0c48707d864f0ac5941e9ff454a072077d97a4d278d07d73$`,
`(?m)^ network_mode: none$`,
`(?m)^ stop_grace_period: 2m$`,
`(?m)^ restart: "no"$`,
`(?m)^ profiles: \["postgres"\]$`,
`(?m)^ entrypoint: \[bash, /ky/postgres-17-to-18\.sh, dump\]$`,
`(?m)^ POSTGRES_USER: postgres$`,
`(?m)^ OLD: /var/lib/postgresql/data$`,
`(?m)^ NEW: /pg18$`,
`(?m)^ - pgdata:/var/lib/postgresql/data$`,
`(?m)^ - postgres:/pg18$`,
`(?m)^ - \./scripts/postgres-17-to-18\.sh:/ky/postgres-17-to-18\.sh:ro$`,
},
} {
s := service(name)
for _, rule := range rules {
if !regexp.MustCompile(rule).MatchString(s) {
t.Errorf("%s service lacks %s", name, rule)
}
}
}
if strings.Contains(service("postgres"), "/var/lib/postgresql/data") || strings.Contains(service("postgres"), "PGDATA") {
t.Error("the 18 service mounts the 17 path or sets PGDATA; 18 refuses the first and the second skips the move")
}
script, err := os.ReadFile(filepath.Join("..", "..", "scripts", "postgres-17-to-18.sh"))
if err != nil {
t.Fatal(err)
}
// The kit's sha256; every Ky repo vendors the same bytes.
if sum := fmt.Sprintf("%x", sha256.Sum256(script)); sum != "2992644109716cd34297fbcb76eba8907f4a5e3031a12c05aade010e5ea2b571" {
t.Errorf("scripts/postgres-17-to-18.sh differs from the shared kit (sha256 %s)", sum)
}
}
34 changes: 33 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,49 @@ services:
# KYPULSE_DB_DSN=postgres://postgres:<POSTGRES_PASSWORD>@postgres:5432/kypulse?sslmode=disable
# (An unset password cannot be a `:?` error here: Compose interpolates every profile, so it
# would break the default SQLite install too.)
# PostgreSQL 18 keeps its data in the `postgres` volume. An install that ran 17 (volume
# `pgdata`) is moved on the first `up`: postgres-17-dump dumps it once, then the 18 service
# restores that dump before it starts. `pgdata` is only read and never removed
# (docs/CONFIGURATION.md, PostgreSQL 17 to 18).
postgres:
image: postgres:17-alpine
image: postgres:18.7-alpine3.24@sha256:0115267ab5a509022df9319c77be365cef335adb71556c75f60f5360ee247e71
container_name: kypulse_postgres
restart: unless-stopped
# Room for a clean shutdown, so the data never needs crash recovery on the next start.
stop_grace_period: 2m
profiles: ["postgres"]
entrypoint: [bash, /ky/postgres-17-to-18.sh, restore]
command: [postgres]
depends_on:
postgres-17-dump:
condition: service_completed_successfully
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-}
POSTGRES_DB: kypulse
volumes:
- postgres:/var/lib/postgresql
- ./scripts/postgres-17-to-18.sh:/ky/postgres-17-to-18.sh:ro

# One-shot, no network: dumps PostgreSQL 17 data from `pgdata` into `postgres` once, and
# exits at once when there is nothing to move or the move is done.
postgres-17-dump:
image: postgres:17.12-alpine3.24@sha256:f9cf3e1f0066f0eb0c48707d864f0ac5941e9ff454a072077d97a4d278d07d73
restart: "no"
stop_grace_period: 2m
profiles: ["postgres"]
network_mode: none
entrypoint: [bash, /ky/postgres-17-to-18.sh, dump]
environment:
POSTGRES_USER: postgres
OLD: /var/lib/postgresql/data
NEW: /pg18
volumes:
- pgdata:/var/lib/postgresql/data
- postgres:/pg18
- ./scripts/postgres-17-to-18.sh:/ky/postgres-17-to-18.sh:ro

volumes:
# PostgreSQL 17 data, kept for rollback until the operator removes it.
pgdata:
postgres:
26 changes: 26 additions & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,31 @@ compose network. Point KyPulse at it with `KYPULSE_DB_DRIVER=postgres` and
`KYPULSE_DB_DSN=postgres://postgres:<password>@postgres:5432/kypulse?sslmode=disable`. Backups
snapshot SQLite only, so a PostgreSQL deployment backs up its database separately.

### PostgreSQL 17 to 18

The bundled database is PostgreSQL 18, with its data in the `postgres` volume. Earlier
releases ran 17 with its data in the `pgdata` volume, which 18 cannot open. The next
`docker compose --profile postgres up -d` moves it. Nothing needs to be done by hand:

- The one-shot `postgres-17-dump` service (the 17 image, no network) dumps `pgdata` once
into `upgrade-from-17/` in the `postgres` volume. 18 then restores that dump before it
starts, so roles, passwords and data come across. A restore that is interrupted runs
again on the next start. A dump that does not restore never leaves an empty database:
postgres keeps failing, with the error in `docker compose logs postgres`. Later starts
skip both steps. A fresh install has nothing to move and initialises 18.
- **Space:** about twice the size of the 17 data, free on the `postgres` volume's disk. The
dump checks first and refuses with the amount it needs, writing nothing.
- **Time:** about as long as a `pg_dump` and a restore of the same data. A small KyPulse
database takes seconds. Until postgres accepts connections, the app fails its start and
Compose restarts it, as on any slow postgres start.
- **Rollback:** `pgdata` is only read and never removed, so 17 can still run on it. Stop
the stack, check out the previous release's `docker-compose.yml` and start it. Rows
written while on 18 are not carried back.
- **Clean-up**, once you are satisfied with 18, and only if you want it. The volume names
carry your Compose project name, `kypulse-server` by default, so check them with
`docker volume ls`. Run `docker volume rm <project>_pgdata` to drop the 17 data and
`docker compose --profile postgres run --rm --no-deps --entrypoint rm postgres -r
/var/lib/postgresql/upgrade-from-17` to drop the dump.

The published image is `ghcr.io/busnes-app/kypulse-server`. `docker-compose.yml` explains how
to pin a commit by digest (`KYPULSE_IMAGE`) and verify its build attestation first.
89 changes: 89 additions & 0 deletions scripts/postgres-17-to-18.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash
# Moves a PostgreSQL 17 data directory to 18 by dump and restore. The 17 data is only read
# (starting 17 may replay its WAL); it is never deleted or reinitialised.
# dump in the postgres:17 image. OLD = the 17 data directory, NEW = the directory that the
# 18 container mounts at /var/lib/postgresql. Dumps OLD once into NEW/upgrade-from-17.
# restore in the postgres:18 image, as its entrypoint: restores that dump once into
# $PGDATA.part, renames it to $PGDATA, then runs the image's entrypoint with the args.
# Runs as root (compose) or as the postgres user (Kubernetes runAsUser 70).
set -Eeuo pipefail
mode=${1:-}; shift || true
new=${NEW:-/var/lib/postgresql}
dump_dir=$new/upgrade-from-17
as_pg() { if [ "$(id -u)" = 0 ]; then gosu postgres "$@"; else "$@"; fi; }
sock=$(mktemp -d)
[ "$(id -u)" != 0 ] || chown postgres "$sock"

case $mode in
dump)
old=${OLD:?set OLD to the PostgreSQL 17 data directory}
if [ -s "$new/18/docker/PG_VERSION" ] || [ -s "$dump_dir/dump.sql" ]; then
echo "postgres-17-to-18: already done"; exit 0
fi
if [ ! -s "$old/PG_VERSION" ]; then
echo "postgres-17-to-18: no PostgreSQL 17 data in $old, nothing to move"; exit 0
fi
if [ "$(cat "$old/PG_VERSION")" != 17 ]; then
echo "postgres-17-to-18: $old holds PostgreSQL $(cat "$old/PG_VERSION"), expected 17" >&2; exit 1
fi
# PostgreSQL's own lock check cannot see a server in another container (its PID 1 looks
# like our grandparent), so a 17 still running on OLD would get a second postmaster.
if [ -e "$old/postmaster.pid" ]; then
echo "postgres-17-to-18: $old/postmaster.pid exists: PostgreSQL 17 is running on it, or did not stop cleanly; stop it (start it once with the previous setup and stop it, if it crashed), then start again" >&2
exit 1
fi
# The dump and the restored cluster each take at most about the size of the 17 data.
need=$(( $(du -sk "$old" | cut -f1) * 2 ))
free=$(df -Pk "$new" | awk 'NR == 2 { print $4 }')
if [ "$free" -lt "$need" ]; then
echo "postgres-17-to-18: $new has $((free / 1024)) MiB free, the move needs $((need / 1024)) MiB; free space or grow the volume, then start again" >&2
exit 1
fi
mkdir -p "$dump_dir"
[ "$(id -u)" != 0 ] || chown postgres "$new" "$dump_dir"
# No network, and a private socket that only trusts local connections.
printf 'local all all trust\n' > "$sock/hba"
[ "$(id -u)" != 0 ] || chown postgres "$sock/hba"
as_pg pg_ctl -D "$old" -w -t 3600 -l "$sock/log" \
-o "-c listen_addresses= -c unix_socket_directories=$sock -c hba_file=$sock/hba" start ||
{ cat "$sock/log" >&2; exit 1; }
trap 'as_pg pg_ctl -D "$old" -m fast -w stop' EXIT
su=$(as_pg psql -h "$sock" -U "${POSTGRES_USER:-postgres}" -d template1 -XAtc "select rolname from pg_roles where oid = 10")
printf '%s\n' "$su" > "$dump_dir/superuser"
as_pg pg_dumpall -h "$sock" -U "$su" -f "$dump_dir/dump.sql.part"
as_pg sync "$dump_dir/dump.sql.part"
mv "$dump_dir/dump.sql.part" "$dump_dir/dump.sql"
sync "$dump_dir"
echo "postgres-17-to-18: dumped $old into $dump_dir/dump.sql; the 17 data is kept"
;;
restore)
final=${PGDATA:?}
if [ ! -s "$final/PG_VERSION" ] && [ -s "$dump_dir/dump.sql" ]; then
# shellcheck source=/dev/null # the image's entrypoint, only inside the postgres image
source /usr/local/bin/docker-entrypoint.sh
# initdb's superuser is the 17 cluster's bootstrap role, so the dump's roles map one to one.
POSTGRES_USER=$(cat "$dump_dir/superuser")
export POSTGRES_USER PGDATA=$final.part
rm -rf "$PGDATA" # a restore an earlier start did not finish; never the 17 data
docker_setup_env
docker_create_db_directories
as_pg bash -c 'source /usr/local/bin/docker-entrypoint.sh; docker_setup_env; docker_init_database_dir; pg_setup_hba_conf'
as_pg pg_ctl -D "$PGDATA" -w -o "-c listen_addresses= -c unix_socket_directories=$sock" start
# pg_dumpall writes CREATE ROLE for the role it ran as, which initdb already made: drop that
# one line, only in the roles section above the first \connect (row data comes later).
q=$(as_pg psql -h "$sock" -U "$POSTGRES_USER" -d postgres -XAtc "select quote_ident(current_user)")
awk -v skip="CREATE ROLE $q;" 'seen || $0 != skip { print } /^\\connect / { seen = 1 }' "$dump_dir/dump.sql" |
as_pg psql -h "$sock" -U "$POSTGRES_USER" -d postgres -X -q -v ON_ERROR_STOP=1
as_pg vacuumdb -h "$sock" -U "$POSTGRES_USER" --all --analyze-only -q
as_pg pg_ctl -D "$PGDATA" -m fast -w stop
sync "$PGDATA"
mv "$PGDATA" "$final"
sync "$(dirname "$final")"
export PGDATA=$final
echo "postgres-17-to-18: restored $dump_dir/dump.sql into $final"
fi
rm -rf "$sock"
exec docker-entrypoint.sh "$@"
;;
*) echo "usage: postgres-17-to-18.sh dump | restore postgres [args...]" >&2; exit 2 ;;
esac
Loading