feat: zero-config first run — in-browser admin bootstrap + auto-generated secrets

Fresh installs need nothing in .env. See PR description for the full feature.
This commit is contained in:
Luca
2026-07-01 14:49:18 +02:00
parent b8b33ae6d6
commit 415bffa04c
17 changed files with 869 additions and 22 deletions
+52 -2
View File
@@ -1,16 +1,53 @@
version: '3.8'
services:
# Generates machine secrets (JWT/DB/Redis) on first run when they aren't set
# in .env, so a fresh install needs zero secret management. Each file is seeded
# from the matching env var when provided (backward-compatible), otherwise a
# strong random value. Idempotent — never overwrites an existing file, so the
# DB password can't drift out from under an already-initialised Postgres volume.
secrets-init:
image: alpine:3.20
container_name: picpeak-secrets-init
env_file: .env
entrypoint:
- sh
- -c
- |
set -e
mkdir -p /run/secrets
if [ ! -s /run/secrets/jwt_secret ]; then
if [ -n "$$JWT_SECRET" ]; then printf '%s' "$$JWT_SECRET" > /run/secrets/jwt_secret;
else tr -dc A-Za-z0-9 < /dev/urandom | head -c 48 > /run/secrets/jwt_secret; fi
fi
if [ ! -s /run/secrets/db_password ]; then
if [ -n "$$DB_PASSWORD" ]; then printf '%s' "$$DB_PASSWORD" > /run/secrets/db_password;
else tr -dc A-Za-z0-9 < /dev/urandom | head -c 48 > /run/secrets/db_password; fi
fi
if [ ! -s /run/secrets/redis_password ]; then
if [ -n "$$REDIS_PASSWORD" ]; then printf '%s' "$$REDIS_PASSWORD" > /run/secrets/redis_password;
else tr -dc A-Za-z0-9 < /dev/urandom | head -c 48 > /run/secrets/redis_password; fi
fi
chmod 644 /run/secrets/jwt_secret /run/secrets/db_password /run/secrets/redis_password
volumes:
- picpeak-secrets:/run/secrets
restart: "no"
postgres:
image: postgres:15-alpine
container_name: picpeak-postgres
userns_mode: "host"
environment:
POSTGRES_USER: ${DB_USER:-picpeak}
POSTGRES_PASSWORD: ${DB_PASSWORD}
# Reads the generated (or .env-seeded) password from the shared secrets volume.
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
POSTGRES_DB: ${DB_NAME:-picpeak}
volumes:
- postgres-data:/var/lib/postgresql/data
- picpeak-secrets:/run/secrets:ro
depends_on:
secrets-init:
condition: service_completed_successfully
networks:
- picpeak-network
restart: unless-stopped
@@ -30,9 +67,14 @@ services:
image: redis:7-alpine
container_name: picpeak-redis
userns_mode: "host"
command: redis-server --requirepass ${REDIS_PASSWORD}
# Reads the generated (or .env-seeded) password from the shared secrets volume.
command: sh -c 'exec redis-server --requirepass "$$(cat /run/secrets/redis_password)"'
volumes:
- redis-data:/data
- picpeak-secrets:/run/secrets:ro
depends_on:
secrets-init:
condition: service_completed_successfully
networks:
- picpeak-network
restart: unless-stopped
@@ -59,11 +101,14 @@ services:
- ${APP_STORAGE}:/app/storage
- ${LOGS}:/app/logs
- ${APP_DATA}:/app/data
- picpeak-secrets:/run/secrets:ro
ports:
- "${BACKEND_PORT:-3001}:3000"
networks:
- picpeak-network
depends_on:
secrets-init:
condition: service_completed_successfully
postgres:
condition: service_healthy
redis:
@@ -144,6 +189,11 @@ volumes:
driver: local
redis-data:
driver: local
# Holds the auto-generated machine secrets (jwt_secret, db_password,
# redis_password). Keep it — deleting it orphans the DB password from the
# Postgres volume. Back it up alongside postgres-data.
picpeak-secrets:
driver: local
networks:
picpeak-network: