version: "3.9"

services:
  station-api:
    image: registry.example.com/metrocycle/station-api:${APP_VERSION:-latest}
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      REGION_CODE: "great-lakes-west"
      SERVICE_NAME: "station-api"
      API_PORT: "8080"
      DATABASE_URL: "postgresql://metrocycle:${POSTGRES_PASSWORD}@postgres:5432/metrocycle"
      REDIS_URL: "redis://redis:6379/0"
      GBFS_PUBLIC_BASE_URL: "https://gbfs.metrocycle.example.com"
      ENABLE_REALTIME_OCCUPANCY: "true"
      LOW_BIKE_THRESHOLD: "4"
      LOW_DOCK_THRESHOLD: "3"
    depends_on:
      - postgres
      - redis
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:8080/healthz"]
      interval: 30s
      timeout: 5s
      retries: 3

  trip-ingest:
    image: registry.example.com/metrocycle/trip-ingest:${APP_VERSION:-latest}
    restart: unless-stopped
    environment:
      REGION_CODE: "great-lakes-west"
      DATABASE_URL: "postgresql://metrocycle:${POSTGRES_PASSWORD}@postgres:5432/metrocycle"
      REDIS_URL: "redis://redis:6379/1"
      MQTT_BROKER_URL: "mqtts://telemetry.metrocycle.example.com:8883"
      INGEST_BATCH_SIZE: "500"
      INGEST_FLUSH_INTERVAL_SECONDS: "15"
    depends_on:
      - postgres
      - redis

  rebalancer:
    image: registry.example.com/metrocycle/rebalancer:${APP_VERSION:-latest}
    restart: unless-stopped
    environment:
      REGION_CODE: "great-lakes-west"
      DATABASE_URL: "postgresql://metrocycle:${POSTGRES_PASSWORD}@postgres:5432/metrocycle"
      REDIS_URL: "redis://redis:6379/2"
      OPTIMIZATION_WINDOW_MINUTES: "90"
      MAX_TRUCK_ROUTE_STOPS: "18"
      WEATHER_PROVIDER: "openmeteo"
    depends_on:
      - postgres
      - redis

  postgres:
    image: postgis/postgis:16-3.4
    restart: unless-stopped
    environment:
      POSTGRES_DB: "metrocycle"
      POSTGRES_USER: "metrocycle"
      POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U metrocycle -d metrocycle"]
      interval: 20s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7.2-alpine
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - redis-data:/data

volumes:
  postgres-data:
  redis-data: