# Open Mapping Backend Services
# Deploy to: /opt/apps/open-mapping/ on Netcup RS 8000

version: '3.8'

services:
  # OSRM - Open Source Routing Machine
  osrm:
    image: osrm/osrm-backend:v5.27.1
    container_name: open-mapping-osrm
    restart: unless-stopped
    volumes:
      - ./data/osrm:/data:ro
    command: osrm-routed --algorithm mld /data/germany-latest.osrm --max-table-size 10000
    ports:
      - "5000:5000"
    networks:
      - traefik-public
      - open-mapping-internal
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.osrm.rule=Host(`routing.jeffemmett.com`) && PathPrefix(`/osrm`)"
      - "traefik.http.routers.osrm.middlewares=osrm-stripprefix"
      - "traefik.http.middlewares.osrm-stripprefix.stripprefix.prefixes=/osrm"
      - "traefik.http.services.osrm.loadbalancer.server.port=5000"

  # Valhalla - Extended Routing
  valhalla:
    image: ghcr.io/gis-ops/docker-valhalla/valhalla:latest
    container_name: open-mapping-valhalla
    restart: unless-stopped
    volumes:
      - ./data/valhalla:/custom_files
    environment:
      - tile_urls=https://download.geofabrik.de/europe/germany-latest.osm.pbf
      - use_tiles_ignore_pbf=True
      - build_elevation=True
      - build_admins=True
      - build_time_zones=True
    ports:
      - "8002:8002"
    networks:
      - traefik-public
      - open-mapping-internal
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.valhalla.rule=Host(`routing.jeffemmett.com`) && PathPrefix(`/valhalla`)"
      - "traefik.http.services.valhalla.loadbalancer.server.port=8002"
    deploy:
      resources:
        limits:
          memory: 8G

  # TileServer GL - Vector Tiles
  tileserver:
    image: maptiler/tileserver-gl:v4.6.5
    container_name: open-mapping-tiles
    restart: unless-stopped
    volumes:
      - ./data/tiles:/data:ro
    ports:
      - "8080:8080"
    networks:
      - traefik-public
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.tiles.rule=Host(`tiles.jeffemmett.com`)"
      - "traefik.http.services.tiles.loadbalancer.server.port=8080"

  # VROOM - Route Optimization
  vroom:
    image: vroomvrp/vroom-docker:v1.14.0
    container_name: open-mapping-vroom
    restart: unless-stopped
    environment:
      - VROOM_ROUTER=osrm
      - OSRM_URL=http://osrm:5000
    ports:
      - "3000:3000"
    networks:
      - traefik-public
      - open-mapping-internal
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.vroom.rule=Host(`routing.jeffemmett.com`) && PathPrefix(`/optimize`)"
      - "traefik.http.services.vroom.loadbalancer.server.port=3000"
    depends_on:
      - osrm

networks:
  traefik-public:
    external: true
  open-mapping-internal:
    driver: bridge
