name: openmonetis

services:
  db:
    image: postgres:18-alpine
    container_name: openmonetis_postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-openmonetis}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-openmonetis_dev_password}
      POSTGRES_DB: ${POSTGRES_DB:-openmonetis_db}
      POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
      PGDATA: /var/lib/postgresql/data
    ports:
      - "${DB_PORT:-5432}:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-openmonetis} -d ${POSTGRES_DB:-openmonetis_db}"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s

  app:
    image: felipegcoutinho/openmonetis:latest
    container_name: openmonetis_app
    restart: unless-stopped
    ports:
      - "${APP_PORT:-3000}:3000"
    env_file:
      - path: .env
        required: false
    environment:
      NODE_ENV: production
      DATABASE_URL: ${DATABASE_URL:-postgresql://openmonetis:openmonetis_dev_password@db:5432/openmonetis_db}
      BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET:-}
      BETTER_AUTH_URL: ${BETTER_AUTH_URL:-http://localhost:3000}
    depends_on:
      db:
        condition: service_healthy
        required: false
    healthcheck:
      test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://127.0.0.1:3000/api/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

volumes:
  postgres_data:
    driver: local
