# Productier Backend Remote Deployment
# Usage: docker compose -f docker-compose.remote.yml --env-file remote.env up -d
#
# Prerequisites:
# 1. Copy remote.env to .env and configure all required values
# 2. Ensure PostgreSQL database is accessible
# 3. Ensure auth service is running and accessible at AUTH_SERVICE_URL

services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
    image: productier-api:latest
    restart: unless-stopped
    init: true
    read_only: true
    security_opt:
      - no-new-privileges:true
    tmpfs:
      - /tmp
    ports:
      - "${API_PORT:-8080}:8080"
    environment:
      APP_ENV: ${APP_ENV:-production}
      API_PORT: 8080
      API_SHUTDOWN_TIMEOUT: ${API_SHUTDOWN_TIMEOUT:-15s}
      DATABASE_URL: ${DATABASE_URL:?DATABASE_URL is required}
      AUTH_SERVICE_URL: ${AUTH_SERVICE_URL:?AUTH_SERVICE_URL is required}
      CORS_ALLOW_ORIGINS: ${CORS_ALLOW_ORIGINS:?CORS_ALLOW_ORIGINS is required}
      BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET:?BETTER_AUTH_SECRET is required}
      MAIL_ENCRYPTION_KEY: ${MAIL_ENCRYPTION_KEY:?MAIL_ENCRYPTION_KEY is required}
      FILE_STORAGE_PROVIDER: ${FILE_STORAGE_PROVIDER:-local}
      FILE_STORAGE_DIR: ${FILE_STORAGE_DIR:-/tmp/uploads}
      DB_MIGRATIONS_DIR: /app/migrations
      # S3 storage (if FILE_STORAGE_PROVIDER=s3)
      S3_ENDPOINT: ${S3_ENDPOINT:-}
      S3_REGION: ${S3_REGION:-us-east-1}
      S3_BUCKET: ${S3_BUCKET:-productier}
      S3_ACCESS_KEY: ${S3_ACCESS_KEY:-}
      S3_SECRET_KEY: ${S3_SECRET_KEY:-}
      S3_USE_PATH_STYLE: ${S3_USE_PATH_STYLE:-false}
      # Optional metrics auth
      METRICS_AUTH_TOKEN: ${METRICS_AUTH_TOKEN:-}
    volumes:
      # Persist uploads if using local storage
      - uploads-data:${FILE_STORAGE_DIR:-/tmp/uploads}
    healthcheck:
      test: ["CMD", "wget", "-q", "-O", "-", "http://127.0.0.1:8080/v1/health"]
      interval: 15s
      timeout: 5s
      retries: 20
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "5"

volumes:
  uploads-data: