Files
drinktracker/docker-compose.prod.yml
JP 87f951bf94 Run natively under systemd; Docker was unworkable in this LXC
Docker in this unprivileged Proxmox LXC was broken two independent ways:
AppArmor could not load the docker-default profile, so the daemon could
not start any new container, and runc could not set the
net.ipv4.ip_unprivileged_port_start sysctl, which is why every service
needed network_mode: host. `docker build` was impossible outright since
Docker 29 removed the classic builder. The stack only survived because
the containers predated the breakage - a reboot would have left the app
down, and nothing could be redeployed.

Postgres, MinIO and the app now run natively under systemd. Deploys
build out-of-place into releases/<sha> and swap a symlink, so the build
happens while the old release keeps serving and downtime is the ~3s
restart rather than the ~3min build. Rollback is the same swap in
reverse with no rebuild.

Dockerfile and docker-compose.prod.yml are unchanged and still work on
a normal host; the compose app service gains `build: .` so it can come
up on a VPS that cannot reach the LAN-only Gitea registry.

Documents three traps found during the migration: rewrites() in
next.config.mjs is evaluated at build time so MINIO_ENDPOINT changes
silently do nothing, prisma migrate deploy would fail because
production has no _prisma_migrations table, and the image proxy relies
on the bucket's anonymous-download policy.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 17:58:34 +00:00

103 lines
3.1 KiB
YAML

services:
db:
image: postgres:16-alpine
restart: unless-stopped
network_mode: host
security_opt:
- apparmor:unconfined
environment:
POSTGRES_USER: ${POSTGRES_USER:?Set POSTGRES_USER in .env.production}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env.production}
POSTGRES_DB: ${POSTGRES_DB:-drinktracker}
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-drinktracker} -d ${POSTGRES_DB:-drinktracker}"]
interval: 5s
timeout: 5s
retries: 5
minio:
image: minio/minio:latest
restart: unless-stopped
network_mode: host
security_opt:
- apparmor:unconfined
environment:
MINIO_ROOT_USER: ${MINIO_ACCESS_KEY:?Set MINIO_ACCESS_KEY in .env.production}
MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY:?Set MINIO_SECRET_KEY in .env.production}
volumes:
- miniodata:/data
command: server /data --console-address ":9001"
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 5s
timeout: 5s
retries: 5
minio-init:
image: minio/mc:latest
network_mode: host
security_opt:
- apparmor:unconfined
depends_on:
minio:
condition: service_healthy
environment:
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
entrypoint: >
/bin/sh -c "
mc alias set local http://localhost:9000 $$MINIO_ACCESS_KEY $$MINIO_SECRET_KEY;
mc mb local/drink-images --ignore-existing;
mc anonymous set download local/drink-images;
exit 0;
"
migrate:
image: node:20-alpine
network_mode: host
security_opt:
- apparmor:unconfined
depends_on:
db:
condition: service_healthy
working_dir: /app
volumes:
- ./prisma:/app/prisma
- ./package.json:/app/package.json
- ./package-lock.json:/app/package-lock.json
env_file:
- .env.production
environment:
DATABASE_URL: "postgresql://${POSTGRES_USER:-drinktracker}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB:-drinktracker}"
command: sh -c "npm install prisma @prisma/client --silent && npx prisma db push --skip-generate --accept-data-loss"
restart: "no"
app:
# `image:` names the tag this produces; `build:` lets it come up on a host that
# can't reach the LAN-only Gitea registry (e.g. a VPS) via `docker compose build`.
image: 192.168.2.140:3000/jpscott84/drinktracker:latest
build: .
restart: unless-stopped
network_mode: host
security_opt:
- apparmor:unconfined
depends_on:
db:
condition: service_healthy
minio:
condition: service_healthy
migrate:
condition: service_completed_successfully
env_file:
- .env.production
environment:
DATABASE_URL: "postgresql://${POSTGRES_USER:-drinktracker}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB:-drinktracker}"
MINIO_ENDPOINT: "localhost"
SWITCHBOARD_BASE_URL: "${SWITCHBOARD_BASE_URL:-http://192.168.2.11:8787/v1}"
volumes:
pgdata:
miniodata: