Phase 10, part 9: the server package

compose.server.yaml runs Supermarket behind Caddy (HTTPS from Let's
Encrypt, Caddy's own CA or the team's), with Postgres on an internal
network and a nightly pg_dump kept two weeks. install-server.sh asks for
the domain, certificate and mail server, makes the secret key and database
password, starts it all and prints the setup link. Settings → Backups lists
the dumps on a server, and how the operator restores one. Checked end to
end in Docker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 09:37:34 -07:00
co-authored by Claude Opus 5.5
parent c8964cec12
commit da16736fb4
15 changed files with 532 additions and 17 deletions
+15
View File
@@ -0,0 +1,15 @@
# Caddy in front of Supermarket's server edition (compose.server.yaml).
# SUPERMARKET_ACME and SUPERMARKET_TLS are whole lines, or nothing (see
# compose.server.yaml); Caddy fills them in before reading this file.
{
{$SUPERMARKET_ACME}
}
{$SUPERMARKET_DOMAIN} {
{$SUPERMARKET_TLS}
encode zstd gzip
header Strict-Transport-Security "max-age=31536000"
# Caddy sets X-Forwarded-For to the client's address (it ignores what the
# client sent), which Supermarket's sign-in limits use.
reverse_proxy supermarket:8080
}
+26
View File
@@ -0,0 +1,26 @@
#!/bin/sh
# Dumps Supermarket's database every night at 03:00, and keeps 14 days of
# dumps. Runs in the backup service of compose.server.yaml.
set -u
cd /backups || exit 1
umask 077
while true; do
now=$(date +%s)
next=$(date -d "$(date +%Y-%m-%d) 03:00" +%s 2>/dev/null || date -D "%Y-%m-%d %H:%M" -d "$(date +%Y-%m-%d) 03:00" +%s)
[ "$next" -le "$now" ] && next=$((next + 86400))
# The first dump right away, if there's none yet.
if ls supermarket-*.dump > /dev/null 2>&1; then
sleep $((next - now))
fi
name="supermarket-$(date +%Y-%m-%d).dump"
if pg_dump --format=custom --file="$name.part" && mv "$name.part" "$name"; then
echo "backup: wrote $name"
else
echo "backup: pg_dump failed" >&2
rm -f "$name.part"
sleep 600
continue
fi
find /backups -name 'supermarket-*.dump' -mtime +14 -delete
sleep 60
done
View File