version: "3.8"
services:
  app:
    build: .
    ports:
      - "5556:5556"
    volumes:
      - ./data:/app/data
      - ./src/web:/app/src/web
      - ./config:/app/config:ro
    environment:
      - DATABASE_URL=sqlite:///./data/enduro.db
      - DATA_PATH=/app/data/centralfederal.sqlite
      - TILES_DIR=/app/data/terrain
      - TERRAIN_DIR=/app/data/terrain
      - STATIC_DIR=/app/src/web
      - OSRM_URL=http://172.22.0.1:5559
      - PORT=5556
      - GPS_TRACKS_DB_PATH=/app/data/gps_tracks.sqlite
      - GPS_SOURCES_CONFIG=/app/config/gps_sources.yaml
      - GPS_REGIONS_CONFIG=/app/config/gps_regions.yaml
    healthcheck:
      test:
        - "CMD"
        - "python"
        - "-c"
        - "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:5556/api/health', timeout=3).status == 200 else 1)"
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 20s

  gps-collector:
    build: .
    profiles: ["batch"]
    volumes:
      - ./data:/app/data
      - ./config:/app/config:ro
      - /var/log/enduro-trails:/var/log/enduro-trails
    environment:
      - GPS_TRACKS_DB_PATH=/app/data/gps_tracks.sqlite
      - GPS_SOURCES_CONFIG=/app/config/gps_sources.yaml
      - GPS_REGIONS_CONFIG=/app/config/gps_regions.yaml
    command: ["python", "-m", "scripts.gps_collect"]
    restart: "no"
