diff --git a/README2.MD b/README2.MD new file mode 100644 index 00000000000..e48b18813b6 --- /dev/null +++ b/README2.MD @@ -0,0 +1,103 @@ +# Docker Compose Setup for Project OSRM + +This directory contains a **Docker Compose configuration** to simplify running [Project OSRM](https://github.com/Project-OSRM/osrm-backend). + +With this way: + +* Only use docker compose up -d   +* It launches a **frontend service** with health checks. +* Don't need to ensure services start in the correct order. + +--- + +## Directory Structure + +``` +osrm-backend/ +├── docker-compose.yml +├── prepare_osrm.sh +``` + +--- + +## Quick Start + +### Clone this repository + +```bash +git clone https://github.com/elshan2000/osrm-backend.git +cd osrm-backend +``` + +### + + +## How It Works + +### Init Service + +* Checks for the marker file `osrm_is_created`. +* If not present, runs: + + * `osrm-extract` + * `osrm-partition` + * `osrm-customize` +* Creates the marker file. +* Exits after preparation. + +### Backend Service + +* Depends on the **frontend healthcheck**. +* Starts `osrm-routed` serving prepared data. + +### Frontend Service + +* Periodically checks for the presence of the marker file `osrm_is_created`. +* Reports `healthy` when the preparation is complete. +* This readiness allows the backend service to start safely. + +--- + +## Health Check Logic + +The **frontend** container performs a health check by verifying: + +``` +/data/osrm_is_created +``` + +Once the file exists, the health check reports `healthy`. This ensures that: + + Data preparation is complete before routing starts. + +--- + +## Clean Up + +To stop and remove all containers: + +```bash +docker compose down +``` + +To force re-preparation of the data (for example, if you want to regenerate `.osrm` files): + +```bash +docker compose down +rm ./data/osrm_is_created +docker compose up -d +``` + +--- + +## Contribution + +This Docker Compose configuration was contributed by [elshan2000](https://github.com/elshan2000). + +Feel free to open issues or submit improvements! + +--- + +## License + +This project follows the [Project OSRM](https://github.com/Project-OSRM/osrm-backend) license (BSD-2-Clause). diff --git a/docker_comopse/docker-compose.yml b/docker_comopse/docker-compose.yml new file mode 100644 index 00000000000..d72f48ec132 --- /dev/null +++ b/docker_comopse/docker-compose.yml @@ -0,0 +1,66 @@ +services: + osrm-extract_partition_customize: + image: ghcr.io/project-osrm/osrm-backend:v6.0.0 + volumes: + - /mnt/graid/projects/osrm:/data + - ./prepare_osrm.sh:/prepare_osrm.sh + command: /prepare_osrm.sh + + restart: "no" + networks: + - osrm_osrm-network + + + osrm-routed: + hostname: osrm-routed + image: ghcr.io/project-osrm/osrm-backend:v6.0.0 + ports: + #- "5050:5000" + volumes: + - /mnt/graid/projects/osrm:/data + command: > + osrm-routed + --algorithm mld + --max-matching-size 100 + --max-trip-size 100 + --max-table-size 100 + --max-nearest-size 100 + --max-alternatives 3 + --ip 0.0.0.0 + --port 5000 + /data/iran-latest.osrm + networks: + - nginx-network + - osrm_osrm-network + restart: always + + depends_on: + osrm-frontend: + condition: service_healthy + + osrm-frontend: + hostname: osrm-frontend + image: osrm/osrm-frontend + #ports: + # - "9966:9966" + restart: always + environment: + # - OSRM_BACKEND_URL=https://osrmapi.buluttakin.com:443 + - OSRM_BACKEND_URL=osrm-routed:5000 + networks: + - nginx-network + - osrm_osrm-network + volumes: + - /mnt/graid/projects/osrm:/data + healthcheck: + test: ["CMD", "test", "-f", "/data/osrm_map_generated"] + interval: 6s + timeout: 600s + retries: 60000 + + +networks: + nginx-network: + external: true + osrm_osrm-network: + driver: bridge diff --git a/docker_comopse/prepare_osrm.sh b/docker_comopse/prepare_osrm.sh new file mode 100755 index 00000000000..8092a9fe728 --- /dev/null +++ b/docker_comopse/prepare_osrm.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ -f /data/osrm_map_generated ]; then + echo "OSRM data already prepared, skipping." +else + echo "OSRM data not found, preparing..." + osrm-extract -p /opt/car.lua /data/iran-latest.osm.pbf && + osrm-partition /data/iran-latest.osrm && + osrm-customize /data/iran-latest.osrm && + touch /data/osrm_map_generated +fi +