services:
  db:
    image: postgres:17
    container_name: amnezia_panel_db
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-amnezia}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-amnezia}
      POSTGRES_DB: ${POSTGRES_DB:-amnezia_panel}
    volumes:
      - amnezia_pgdata:/var/lib/postgresql/data
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-amnezia} -d ${POSTGRES_DB:-amnezia_panel}"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 20s

  amnezia_panel:
    build:
      context: .
      dockerfile: Dockerfile
    image: amnezia-panel:local
    container_name: amnezia_panel
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "${APP_PORT:-5000}:5000"
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER:-amnezia}:${POSTGRES_PASSWORD:-amnezia}@db:5432/${POSTGRES_DB:-amnezia_panel}
      SECRET_KEY: ${SECRET_KEY:-}
      APP_PORT: "5000"
    volumes:
      - amnezia_data:/app/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:5000/docs >/dev/null || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

volumes:
  amnezia_data:
  amnezia_pgdata:
