Program.cs: wrap the boot-time MigrateAsync in try/catch (was an unhandled exception into a restart:unless-stopped crash-loop), log critical and exit(1) on failure, and add a --migrate-only flag that applies migrations then exits 0 without starting the web host. deploy.sh: run migrations as a preflight via the new --migrate-only image against the live novelly-data volume, before the running (old-image) stack is touched. A failing migration now aborts the deploy with the old containers still serving traffic, instead of swapping to a crash-looping new container first and finding out from the health-check timeout.
58 lines
1.5 KiB
YAML
58 lines
1.5 KiB
YAML
name: novelly
|
|
|
|
# Persistent LAN deployment, pulled and recreated by CI on every push to main.
|
|
# Unlike a throwaway QA stack, this one keeps its data volume across deploys — `down`
|
|
# is run without `-v` so the author's novel data survives a redeploy.
|
|
services:
|
|
|
|
api:
|
|
image: ${API_IMAGE}:latest
|
|
restart: unless-stopped
|
|
environment:
|
|
ConnectionStrings__Novel: "Data Source=/data/novel.db"
|
|
Cors__Origins__0: "http://localhost:${WEB_PORT:-6173}"
|
|
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
|
|
volumes:
|
|
- novelly-data:/data
|
|
networks:
|
|
- novelly
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "curl -fsS http://localhost:8080/api/health || exit 1"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 20s
|
|
|
|
web:
|
|
image: ${WEB_IMAGE}:latest
|
|
restart: unless-stopped
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
networks:
|
|
- novelly
|
|
ports:
|
|
- "${WEB_PORT:-6173}:80"
|
|
|
|
# Preflight migration check, run by deploy.sh via `--profile tools run --rm migrate`
|
|
# against the newly pulled image before the running stack is touched. Excluded from
|
|
# `up -d` by the tools profile.
|
|
migrate:
|
|
image: ${API_IMAGE}:latest
|
|
command: ["dotnet", "Novelly.Api.dll", "--migrate-only"]
|
|
environment:
|
|
ConnectionStrings__Novel: "Data Source=/data/novel.db"
|
|
volumes:
|
|
- novelly-data:/data
|
|
networks:
|
|
- novelly
|
|
profiles: ["tools"]
|
|
|
|
networks:
|
|
novelly:
|
|
name: novelly-net
|
|
|
|
volumes:
|
|
novelly-data:
|
|
name: novelly-data
|