version: "3.9"

networks:
  frontend:
    external: true

services:
  routes_api:
    build:
      context: .
      dockerfile: Dockerfile
    image: routes-api:latest
    container_name: routes_api
    restart: unless-stopped
    environment:
      - UVICORN_WORKERS=2
      - REDIS_URL=redis://:${REDIS_PASSWORD}@routes_redis:6379/0
      # Optional: Set cache TTL in seconds (default: 300 = 5 min, 86400 = 24h)
      # Uncomment and set in .env file: REDIS_CACHE_TTL_SECONDS=86400
      # - REDIS_CACHE_TTL_SECONDS=${REDIS_CACHE_TTL_SECONDS}
      # Google Maps API key for accurate road distance calculation (actualkms)
      # Set in .env file: GOOGLE_MAPS_API_KEY=your_api_key_here
      - GOOGLE_MAPS_API_KEY=${GOOGLE_MAPS_API_KEY}
      # nearledb (read-only) — source for empirical ETA learning
      - DB_HOST=${DB_HOST}
      - DB_PORT=${DB_PORT}
      - DB_NAME=${DB_NAME}
      - DB_USER=${DB_USER}
      - DB_PASSWORD=${DB_PASSWORD}
    labels:
      - traefik.enable=true
      - traefik.http.routers.routes_api.rule=Host(`routes.workolik.com`)
      - traefik.http.routers.routes_api.entrypoints=websecure
      - traefik.http.routers.routes_api.tls.certresolver=letsencrypt
      - traefik.http.services.routes_api.loadbalancer.server.port=8002
      - traefik.docker.network=frontend
    volumes:
      - ./ml_data:/app/ml_data
      - ./rider_history.pkl:/app/rider_history.pkl
      - ./rider_active_state.pkl:/app/rider_active_state.pkl
      - ./delivery_details.csv:/app/delivery_details.csv:ro
      - ./delivery_corrections.csv:/app/delivery_corrections.csv:ro
    networks:
      - frontend
