services:
  postgres:
    image: postgres:16
    container_name: satellite-provider-postgres
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: satelliteprovider
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

  api:
    platform: linux/amd64
    build:
      context: .
      dockerfile: SatelliteProvider.Api/Dockerfile
    container_name: satellite-provider-api
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:8080
      - ASPNETCORE_Kestrel__Certificates__Default__Path=/app/certs/api.pfx
      - ASPNETCORE_Kestrel__Certificates__Default__Password=satellite-dev-cert
      - ConnectionStrings__DefaultConnection=Host=postgres;Port=5432;Database=satelliteprovider;Username=postgres;Password=postgres
      - MapConfig__ApiKey=${GOOGLE_MAPS_API_KEY}
      - JWT_SECRET=${JWT_SECRET}
      - JWT_ISSUER=${JWT_ISSUER}
      - JWT_AUDIENCE=${JWT_AUDIENCE}
    volumes:
      - ./tiles:/app/tiles
      - ./ready:/app/ready
      - ./logs:/app/logs
      - ./certs/api.pfx:/app/certs/api.pfx:ro
    depends_on:
      postgres:
        condition: service_healthy

  integration-tests:
    build:
      context: .
      dockerfile: SatelliteProvider.IntegrationTests/Dockerfile
    container_name: satellite-provider-integration-tests
    environment:
      - API_URL=https://api:8080
      - INTEGRATION_TESTS_MODE=${INTEGRATION_TESTS_MODE:-full}
      - INTEGRATION_KEEP_STATE=${INTEGRATION_KEEP_STATE:-}
      - ASPNETCORE_ENVIRONMENT=Testing
      - DB_CONNECTION_STRING=Host=postgres;Port=5432;Database=satelliteprovider;Username=postgres;Password=postgres
      - JWT_SECRET=${JWT_SECRET}
      - JWT_ISSUER=${JWT_ISSUER}
      - JWT_AUDIENCE=${JWT_AUDIENCE}
    volumes:
      - ./ready:/app/ready
      - ./tiles:/app/tiles
      - ./certs/api.crt:/usr/local/share/ca-certificates/satellite-provider-dev.crt:ro
    entrypoint:
      - /bin/sh
      - -c
      - update-ca-certificates >/dev/null 2>&1 && exec dotnet /app/SatelliteProvider.IntegrationTests.dll
    depends_on:
      api:
        condition: service_started
      postgres:
        condition: service_healthy
    restart: "no"

volumes:
  postgres_data:
