Make the Compose stack safe and reproducible on a fresh host: parameterize database credentials, bind Postgres to loopback by default, add an app healthcheck and log rotation, and pass Postmark/archive settings through. Document the complete Ubuntu deployment path, including bootstrap, TLS, firewall, cron, NFS, backups, updates, and troubleshooting.
This commit is contained in:
+26
-9
@@ -14,7 +14,9 @@ services:
|
||||
dockerfile: Dockerfile
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
DATABASE_URL: postgres://media:media@db:5432/media
|
||||
# Built from the POSTGRES_* values in .env. Use a URL-safe password
|
||||
# (hex is simplest); reserved URL characters must be percent-encoded.
|
||||
DATABASE_URL: postgres://${POSTGRES_USER:-media}:${POSTGRES_PASSWORD:-media}@db:5432/${POSTGRES_DB:-media}
|
||||
# Fallback base URL only. Generated links (magic link, invite, publish
|
||||
# emails) use the origin of the request that created them, so access via
|
||||
# http://<lan-ip>:3000 and https://<public-domain> both produce working
|
||||
@@ -23,7 +25,9 @@ services:
|
||||
# Secure cookie is rejected by browsers on plain-http LAN access.
|
||||
NEXTAUTH_URL: ${NEXTAUTH_URL:-http://localhost:3000}
|
||||
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET:-dev-only-secret-change-me}
|
||||
POSTMARK_FROM: media@localhost
|
||||
POSTMARK_FROM: ${POSTMARK_FROM:-media@localhost}
|
||||
POSTMARK_SERVER_TOKEN: ${POSTMARK_SERVER_TOKEN:-}
|
||||
ARCHIVE_FOLDER: ${ARCHIVE_FOLDER:-Glenloch Media}
|
||||
APP_ORIGIN: ${APP_ORIGIN:-http://localhost:3000}
|
||||
# Canonical origin for emailed links. Set this to the public URL when the
|
||||
# app is reachable from outside the LAN; empty means "use the request
|
||||
@@ -56,26 +60,39 @@ services:
|
||||
- uploads-data:/tmp/uploads
|
||||
- ${MEDIA_ARCHIVE_DIR:-archive-data}:/archive
|
||||
ports:
|
||||
- "${APP_PORT:-3000}:3000"
|
||||
# Default keeps LAN access working. A proxied host should set
|
||||
# APP_BIND=127.0.0.1 so only Caddy/Nginx can reach the app.
|
||||
- "${APP_BIND:-0.0.0.0}:${APP_PORT:-3000}:3000"
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/api/health >/dev/null 2>&1 || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 30s
|
||||
logging:
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
restart: unless-stopped
|
||||
|
||||
db:
|
||||
image: postgres:16-alpine
|
||||
environment:
|
||||
POSTGRES_USER: media
|
||||
POSTGRES_PASSWORD: media
|
||||
POSTGRES_DB: media
|
||||
POSTGRES_USER: ${POSTGRES_USER:-media}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-media}
|
||||
POSTGRES_DB: ${POSTGRES_DB:-media}
|
||||
# Host 5433 -> container 5432 (local postgres already holds 5432).
|
||||
# Override POSTGRES_PORT if 5433 is taken by another stack.
|
||||
ports:
|
||||
- "${POSTGRES_PORT:-5433}:5432"
|
||||
# Loopback by default: the app reaches Postgres over the Compose network.
|
||||
- "${POSTGRES_BIND:-127.0.0.1}:${POSTGRES_PORT:-5433}:5432"
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U media"]
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-media} -d ${POSTGRES_DB:-media}"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
@@ -90,7 +107,7 @@ services:
|
||||
target: tools
|
||||
command: ["sh", "-c", "pnpm db:migrate && pnpm db:seed"]
|
||||
environment:
|
||||
DATABASE_URL: postgres://media:media@db:5432/media
|
||||
DATABASE_URL: postgres://${POSTGRES_USER:-media}:${POSTGRES_PASSWORD:-media}@db:5432/${POSTGRES_DB:-media}
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
Reference in New Issue
Block a user