version: "3.8"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        APT_CACHE_URL: ${APT_CACHE_URL:-}
    environment:
      - ENVIRONMENT=development
      - DEBUG=true
      - LOG_LEVEL=DEBUG
      # Override database to use local postgres service
      - DATABASE_HOST=postgres
      - DATABASE_PORT=5432
      - DATABASE_USER=calminer
      - DATABASE_PASSWORD=calminer_password
      - DATABASE_NAME=calminer_db
      - DATABASE_DRIVER=postgresql
      # Development-specific settings
      - CALMINER_EXPORT_MAX_ROWS=1000
      - CALMINER_IMPORT_MAX_ROWS=10000
    volumes:
      # Mount source code for live reloading (if using --reload)
      - .:/app:ro
      # Override logs volume to local for easier access
      - ./logs:/app/logs
    ports:
      - "8003:8003"
    # Override command for development with reload
    command:
      [
        "main:app",
        "--host",
        "0.0.0.0",
        "--port",
        "8003",
        "--reload",
        "--workers",
        "1",
      ]
    depends_on:
      - postgres
    restart: unless-stopped

  postgres:
    environment:
      - POSTGRES_USER=calminer
      - POSTGRES_PASSWORD=calminer_password
      - POSTGRES_DB=calminer_db
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    restart: unless-stopped

volumes:
  postgres_data:
