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>
117 lines
3.6 KiB
YAML
117 lines
3.6 KiB
YAML
# Supermarket's server edition: one team, signing in, on its own domain.
|
|
# install-server.sh writes server.env (the domain, the mail server, the
|
|
# secret key and the database password) and starts it:
|
|
#
|
|
# docker compose -f compose.server.yaml --env-file server.env up -d --build
|
|
#
|
|
# Caddy answers on ports 80 and 443 and gets the certificate; Supermarket
|
|
# itself is published only to Caddy, on the compose network.
|
|
name: supermarket-server
|
|
|
|
services:
|
|
supermarket:
|
|
build:
|
|
context: .
|
|
args:
|
|
VERSION: ${SUPERMARKET_VERSION:-dev}
|
|
image: supermarket:server
|
|
restart: unless-stopped
|
|
init: true
|
|
user: "10001:10001"
|
|
environment:
|
|
SUPERMARKET_MODE: server
|
|
SUPERMARKET_PUBLIC_URL: https://${SUPERMARKET_DOMAIN:?}${SUPERMARKET_PUBLIC_PORT:-}
|
|
SUPERMARKET_DATABASE_URL: postgres://supermarket:${SUPERMARKET_DB_PASSWORD:?}@db:5432/supermarket?sslmode=disable
|
|
SUPERMARKET_SECRET_KEY: ${SUPERMARKET_SECRET_KEY:?}
|
|
SUPERMARKET_MAIL_URL: ${SUPERMARKET_MAIL_URL:?}
|
|
SUPERMARKET_MAIL_FROM: ${SUPERMARKET_MAIL_FROM:-}
|
|
SUPERMARKET_PG_BACKUPS: /backups
|
|
TZ: ${SUPERMARKET_TZ:-UTC}
|
|
volumes:
|
|
- appdata:/data # scratch: the sites' clones and previews
|
|
- pgbackups:/backups:ro # the nightly dumps, for Settings → Backups
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
networks: [internal, web]
|
|
read_only: true
|
|
tmpfs:
|
|
- /tmp
|
|
cap_drop:
|
|
- ALL
|
|
security_opt:
|
|
- no-new-privileges:true
|
|
|
|
db:
|
|
image: postgres:18-alpine
|
|
restart: unless-stopped
|
|
environment:
|
|
POSTGRES_DB: supermarket
|
|
POSTGRES_USER: supermarket
|
|
POSTGRES_PASSWORD: ${SUPERMARKET_DB_PASSWORD:?}
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql
|
|
healthcheck:
|
|
test: ["CMD", "pg_isready", "-U", "supermarket", "-d", "supermarket"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 20
|
|
networks: [internal]
|
|
|
|
# A dump of the database every night at 03:00 (the server's TZ), kept for
|
|
# two weeks: supermarket-YYYY-MM-DD.dump, in pg_dump's custom format.
|
|
# Restoring is the operator's: see server/README.md.
|
|
backup:
|
|
image: postgres:18-alpine
|
|
restart: unless-stopped
|
|
environment:
|
|
PGHOST: db
|
|
PGUSER: supermarket
|
|
PGDATABASE: supermarket
|
|
PGPASSWORD: ${SUPERMARKET_DB_PASSWORD:?}
|
|
TZ: ${SUPERMARKET_TZ:-UTC}
|
|
volumes:
|
|
- pgbackups:/backups
|
|
- ./server/backup.sh:/usr/local/bin/backup.sh:ro
|
|
entrypoint: ["/bin/sh", "/usr/local/bin/backup.sh"]
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
networks: [internal]
|
|
|
|
caddy:
|
|
image: caddy:2-alpine
|
|
restart: unless-stopped
|
|
ports:
|
|
- "${SUPERMARKET_HTTP_PORT:-80}:80"
|
|
- "${SUPERMARKET_HTTPS_PORT:-443}:443"
|
|
- "${SUPERMARKET_HTTPS_PORT:-443}:443/udp"
|
|
environment:
|
|
SUPERMARKET_DOMAIN: ${SUPERMARKET_DOMAIN:?}
|
|
# "email you@example.com", for Let's Encrypt's notices; or empty.
|
|
SUPERMARKET_ACME: ${SUPERMARKET_ACME:-}
|
|
# Empty: a certificate from Let's Encrypt (the server must be reachable
|
|
# from the internet on ports 80 and 443). "tls internal": Caddy's own
|
|
# CA, for a private network or VPN. "tls /certs/cert.pem
|
|
# /certs/key.pem": your own CA's certificate, put in server/certs/.
|
|
SUPERMARKET_TLS: ${SUPERMARKET_TLS:-}
|
|
volumes:
|
|
- ./server/Caddyfile:/etc/caddy/Caddyfile:ro
|
|
- ./server/certs:/certs:ro
|
|
- caddydata:/data
|
|
- caddyconfig:/config
|
|
depends_on: [supermarket]
|
|
networks: [web]
|
|
|
|
volumes:
|
|
appdata:
|
|
pgdata:
|
|
pgbackups:
|
|
caddydata:
|
|
caddyconfig:
|
|
|
|
networks:
|
|
internal:
|
|
internal: true # the database has no way out
|
|
web:
|