services:
  postgres:
    image: postgres:17
    environment:
      POSTGRES_DB: gnexus_creds
      POSTGRES_USER: gnexus_creds
      POSTGRES_PASSWORD: gnexus_creds
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U gnexus_creds -d gnexus_creds"]
      interval: 5s
      timeout: 3s
      retries: 20

  app:
    build: .
    depends_on:
      postgres:
        condition: service_healthy
    env_file:
      - .env
    environment:
      GNEXUS_CREDS_DATABASE_URL: postgresql+psycopg://gnexus_creds:gnexus_creds@postgres:5432/gnexus_creds
    ports:
      - "8000:8000"
    volumes:
      - backups:/app/backups
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/ready"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s

volumes:
  postgres-data:
  backups:
