version: "3.9"

name: municipal-transit-planner

services:
  planner-api:
    image: ghcr.io/city-transport/transit-planner-api:2.8.4
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    ports:
      - "8080:8080"
    environment:
      APP_ENV: production
      CITY_CODE: "metroville"
      GTFS_FEED_URL: "https://data.metroville.gov/gtfs/latest.zip"
      REALTIME_TRIP_UPDATES_URL: "https://api.metroville.gov/gtfs-rt/trip-updates"
      REALTIME_VEHICLE_POSITIONS_URL: "https://api.metroville.gov/gtfs-rt/vehicles"
      DATABASE_URL: "postgresql://transit:${POSTGRES_PASSWORD}@postgres:5432/transit_planner"
      REDIS_URL: "redis://redis:6379/0"
      ROUTING_ENGINE_URL: "http://routing-engine:9090"
      LOG_LEVEL: info
      REQUEST_TIMEOUT_MS: "8000"
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:8080/health"]
      interval: 30s
      timeout: 5s
      retries: 3
    restart: unless-stopped

  routing-engine:
    image: ghcr.io/city-transport/otp-routing-engine:2.5.1
    volumes:
      - gtfs-cache:/var/lib/transit/gtfs
      - graph-cache:/var/lib/transit/graphs
    environment:
      JAVA_TOOL_OPTIONS: "-Xms2g -Xmx6g"
      GRAPH_BUILD_ON_STARTUP: "true"
      GTFS_PATH: "/var/lib/transit/gtfs/latest.zip"
      OSM_PBF_PATH: "/var/lib/transit/osm/metroville.osm.pbf"
    expose:
      - "9090"
    restart: unless-stopped

  feed-sync:
    image: ghcr.io/city-transport/gtfs-sync:1.6.2
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      GTFS_FEED_URL: "https://data.metroville.gov/gtfs/latest.zip"
      DATABASE_URL: "postgresql://transit:${POSTGRES_PASSWORD}@postgres:5432/transit_planner"
      SYNC_INTERVAL_MINUTES: "15"
      ALERT_EMAIL: "transit-ops@metroville.gov"
    volumes:
      - gtfs-cache:/data/gtfs
    restart: unless-stopped

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

  redis:
    image: redis:7.2-alpine
    command: ["redis-server", "--appendonly", "yes", "--maxmemory", "512mb", "--maxmemory-policy", "allkeys-lru"]
    volumes:
      - redis-data:/data
    restart: unless-stopped

volumes:
  postgres-data:
  redis-data:
  gtfs-cache:
  graph-cache: