- admin.py: remove unused get_current_user import - feed.py, flock.py, other.py: add IntegrityError handling on POST/PUT endpoints; duplicate submissions now return 409 instead of crashing with a 500 error - stats.py: extract magic numbers into named module-level constants (DAYS_ROLLING, DAYS_SHORT, PRECISION_AVG, PRECISION_HEN, PRECISION_COST); add return type annotations to _total_feed_cost and _total_other_cost; normalize both helpers to always return Decimal so budget_stats no longer needs Decimal(str(...)) workarounds; simplify _cpe/_cpd helpers - dashboard.js: read --green CSS variable at runtime instead of hardcoding the hex value so chart color stays in sync with the stylesheet - docker-compose.yml: add healthcheck to api service (polls /api/health every 30s) so Docker knows when the API is unhealthy; add password strength guidance comment above the db service Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
86 lines
3.2 KiB
YAML
86 lines
3.2 KiB
YAML
services:
|
|
|
|
# ── MySQL ────────────────────────────────────────────────────────────────────
|
|
# MYSQL_ROOT_PASSWORD and MYSQL_PASSWORD should each be 20+ random characters.
|
|
# Generate with: openssl rand -hex 16
|
|
db:
|
|
image: mysql:8.0
|
|
restart: unless-stopped
|
|
env_file: .env
|
|
logging:
|
|
driver: json-file
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
environment:
|
|
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
|
|
MYSQL_DATABASE: ${MYSQL_DATABASE}
|
|
MYSQL_USER: ${MYSQL_USER}
|
|
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
|
|
volumes:
|
|
- mysql_data:/var/lib/mysql # persistent data
|
|
- ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql:ro # run once on first start
|
|
healthcheck:
|
|
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD}"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 30s
|
|
networks:
|
|
- backend
|
|
|
|
# ── FastAPI ──────────────────────────────────────────────────────────────────
|
|
api:
|
|
build: ./backend
|
|
restart: unless-stopped
|
|
env_file: .env
|
|
logging:
|
|
driver: json-file
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
environment:
|
|
DATABASE_URL: mysql+pymysql://${MYSQL_USER}:${MYSQL_PASSWORD}@db/${MYSQL_DATABASE}
|
|
ADMIN_USERNAME: ${ADMIN_USERNAME}
|
|
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
|
JWT_SECRET: ${JWT_SECRET}
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/health')"]
|
|
interval: 30s
|
|
timeout: 5s
|
|
retries: 3
|
|
start_period: 15s
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy # wait for MySQL to be ready before starting
|
|
networks:
|
|
- backend
|
|
|
|
# ── Nginx ────────────────────────────────────────────────────────────────────
|
|
nginx:
|
|
image: nginx:alpine
|
|
restart: unless-stopped
|
|
logging:
|
|
driver: json-file
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
ports:
|
|
- "8056:80"
|
|
volumes:
|
|
- ./nginx/html:/usr/share/nginx/html:ro # static files — edit locally, live immediately
|
|
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro # nginx config
|
|
depends_on:
|
|
- api
|
|
networks:
|
|
- backend
|
|
|
|
# ── Volumes ───────────────────────────────────────────────────────────────────
|
|
volumes:
|
|
mysql_data: # survives container restarts and rebuilds
|
|
|
|
# ── Networks ──────────────────────────────────────────────────────────────────
|
|
networks:
|
|
backend:
|
|
driver: bridge
|