mitai-jinkendo/docker-compose.yml
Lars 39a7b1be78
All checks were successful
Deploy Development / deploy (push) Successful in 57s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 14s
feat: add PostgreSQL to production setup (v9b)
Prepares production for SQLite → PostgreSQL migration:
- Add postgres service (mitai-db, port 5432)
- Add DB environment variables to backend
- Backend depends on postgres health check
- Uses startup.sh for automatic migration

Migration strategy:
1. SQLite data in /app/data/bodytrack.db is preserved (volume mounted)
2. On first start with empty PostgreSQL: automatic migration
3. Migration is safe: checks if profiles table is empty before migrating
4. After migration: all new data goes to PostgreSQL

IMPORTANT: Set DB_PASSWORD in .env before deploying!

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 12:14:25 +01:00

74 lines
1.7 KiB
YAML

services:
postgres:
image: postgres:16-alpine
container_name: mitai-db
restart: unless-stopped
environment:
POSTGRES_DB: mitai_prod
POSTGRES_USER: mitai_prod
POSTGRES_PASSWORD: ${DB_PASSWORD:-change_me_in_production}
volumes:
- mitai_postgres_data:/var/lib/postgresql/data
ports:
- "127.0.0.1:5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U mitai_prod"]
interval: 10s
timeout: 5s
retries: 5
backend:
build: ./backend
container_name: mitai-api
restart: unless-stopped
ports:
- "8002:8000"
depends_on:
postgres:
condition: service_healthy
volumes:
- bodytrack_bodytrack-data:/app/data
- bodytrack_bodytrack-photos:/app/photos
environment:
# Database
- DB_HOST=postgres
- DB_PORT=5432
- DB_NAME=mitai_prod
- DB_USER=mitai_prod
- DB_PASSWORD=${DB_PASSWORD:-change_me_in_production}
# AI
- OPENROUTER_API_KEY=${OPENROUTER_API_KEY}
- OPENROUTER_MODEL=${OPENROUTER_MODEL:-anthropic/claude-sonnet-4}
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
# Email
- SMTP_HOST=${SMTP_HOST}
- SMTP_PORT=${SMTP_PORT:-587}
- SMTP_USER=${SMTP_USER}
- SMTP_PASS=${SMTP_PASS}
- SMTP_FROM=${SMTP_FROM}
# App
- APP_URL=${APP_URL}
- DATA_DIR=/app/data
- PHOTOS_DIR=/app/photos
- ALLOWED_ORIGINS=${ALLOWED_ORIGINS:-*}
- ENVIRONMENT=production
frontend:
build: ./frontend
container_name: mitai-ui
restart: unless-stopped
ports:
- "3002:80"
depends_on:
- backend
volumes:
mitai_postgres_data:
bodytrack_bodytrack-data:
external: true
bodytrack_bodytrack-photos:
external: true