build osrm arm64

This commit is contained in:
Shautvast 2026-03-30 13:01:47 +02:00
parent e99114b7b7
commit fd8c8d0aa4
4 changed files with 80 additions and 8 deletions

View file

@ -60,7 +60,8 @@ podman compose run --rm importer /app/scripts/03_import_pois.sh
podman compose run --rm importer /app/scripts/04_import_geocoding.sh podman compose run --rm importer /app/scripts/04_import_geocoding.sh
# Step 5: Preprocess OSRM routing graphs — run on the HOST, not in the container # Step 5: Preprocess OSRM routing graphs — run on the HOST, not in the container
# (OSRM tools only exist inside the osrm/osrm-backend image) # Builds a local ARM64 OSRM image on first run (~30-60 min), then preprocesses
# car/foot/bicycle profiles. Subsequent runs skip the image build.
bash backend/scripts/05_import_routing_host.sh ~/dev/maps/data bash backend/scripts/05_import_routing_host.sh ~/dev/maps/data
# Step 6: Register offline regions in the database # Step 6: Register offline regions in the database
@ -145,6 +146,8 @@ podman compose up -d postgres
**Exec format error on Pi** — The postgres image is built locally from `postgis.Dockerfile` using `arm64v8/postgres` as base. Run `podman compose build postgres` to rebuild it. **Exec format error on Pi** — The postgres image is built locally from `postgis.Dockerfile` using `arm64v8/postgres` as base. Run `podman compose build postgres` to rebuild it.
**OSRM exec format error** — `osrm/osrm-backend` is amd64-only. The project uses `osrm-arm64.Dockerfile` to build a native ARM64 image. Run `podman compose build osrm-driving` (builds once, shared by all three OSRM services) or let `05_import_routing_host.sh` build it automatically.
--- ---
## Attribution ## Attribution

View file

@ -72,25 +72,40 @@ services:
- "2322:2322" - "2322:2322"
osrm-driving: osrm-driving:
image: docker.io/osrm/osrm-backend:latest build:
context: .
dockerfile: osrm-arm64.Dockerfile
networks: networks:
- maps-net - maps-net
ports: ports:
- "5000:5000" - "5000:5000"
volumes:
- ../data/osrm/car:/data
command: osrm-routed --algorithm mld /data/region.osrm
osrm-walking: osrm-walking:
image: docker.io/osrm/osrm-backend:latest build:
context: .
dockerfile: osrm-arm64.Dockerfile
networks: networks:
- maps-net - maps-net
ports: ports:
- "5001:5000" - "5001:5000"
volumes:
- ../data/osrm/foot:/data
command: osrm-routed --algorithm mld /data/region.osrm
osrm-cycling: osrm-cycling:
image: docker.io/osrm/osrm-backend:latest build:
context: .
dockerfile: osrm-arm64.Dockerfile
networks: networks:
- maps-net - maps-net
ports: ports:
- "5002:5000" - "5002:5000"
volumes:
- ../data/osrm/bicycle:/data
command: osrm-routed --algorithm mld /data/region.osrm
importer: importer:
build: build:

View file

@ -0,0 +1,41 @@
FROM docker.io/arm64v8/debian:bookworm AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential cmake git pkg-config \
libboost-all-dev libtbb-dev liblua5.4-dev \
libxml2-dev libzip-dev libbz2-dev \
&& rm -rf /var/lib/apt/lists/*
ARG OSRM_VERSION=v5.27.1
RUN git clone --depth=1 --branch ${OSRM_VERSION} \
https://github.com/Project-OSRM/osrm-backend.git /osrm
RUN cd /osrm && mkdir build && cd build && \
cmake .. -DCMAKE_BUILD_TYPE=Release && \
make -j$(nproc) osrm-extract osrm-partition osrm-customize osrm-routed && \
make install
# ---- runtime ----
FROM docker.io/arm64v8/debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
libboost-filesystem1.81.0 \
libboost-iostreams1.81.0 \
libboost-regex1.81.0 \
libboost-date-time1.81.0 \
libboost-thread1.81.0 \
libboost-program-options1.81.0 \
libtbb12 liblua5.4-0 libxml2 libzip4 libbz2-1.0 \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/bin/osrm-extract \
/usr/local/bin/osrm-partition \
/usr/local/bin/osrm-customize \
/usr/local/bin/osrm-routed \
/usr/local/bin/
# Lua profiles (car.lua, foot.lua, bicycle.lua, etc.)
COPY --from=builder /osrm/profiles/ /opt/
WORKDIR /data
EXPOSE 5000

View file

@ -1,13 +1,17 @@
#!/bin/bash #!/bin/bash
# scripts/05_import_routing_host.sh # scripts/05_import_routing_host.sh
# Run this directly on the Pi host (not inside the importer container). # Run this directly on the Pi host (not inside the importer container).
# OSRM tools only exist inside the osrm/osrm-backend image. # Builds a local ARM64 OSRM image if it doesn't exist, then preprocesses
# routing graphs for car, foot, and bicycle profiles.
set -euo pipefail set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKEND_DIR="$(dirname "$SCRIPT_DIR")"
DATA_DIR="${1:-$HOME/dev/maps/data}" DATA_DIR="${1:-$HOME/dev/maps/data}"
OSRM_DIR="${DATA_DIR}/osrm" OSRM_DIR="${DATA_DIR}/osrm"
PBF_FILE="${DATA_DIR}/osm/region.osm.pbf" PBF_FILE="${DATA_DIR}/osm/region.osm.pbf"
OSRM_IMAGE="maps-osrm-arm64:latest"
if [ ! -f "$PBF_FILE" ]; then if [ ! -f "$PBF_FILE" ]; then
echo "ERROR: PBF file not found at $PBF_FILE" echo "ERROR: PBF file not found at $PBF_FILE"
@ -15,6 +19,15 @@ if [ ! -f "$PBF_FILE" ]; then
exit 1 exit 1
fi fi
# Build the ARM64 OSRM image if not already present
if ! podman image exists "$OSRM_IMAGE"; then
echo "=== Building ARM64 OSRM image (one-time, ~30-60 min on Pi) ==="
podman build \
-f "${BACKEND_DIR}/osrm-arm64.Dockerfile" \
-t "$OSRM_IMAGE" \
"$BACKEND_DIR"
fi
for PROFILE in car foot bicycle; do for PROFILE in car foot bicycle; do
PROFILE_DIR="${OSRM_DIR}/${PROFILE}" PROFILE_DIR="${OSRM_DIR}/${PROFILE}"
mkdir -p "$PROFILE_DIR" mkdir -p "$PROFILE_DIR"
@ -24,17 +37,17 @@ for PROFILE in car foot bicycle; do
podman run --rm \ podman run --rm \
-v "${PROFILE_DIR}:/data" \ -v "${PROFILE_DIR}:/data" \
docker.io/osrm/osrm-backend:latest \ "$OSRM_IMAGE" \
osrm-extract -p "/opt/${PROFILE}.lua" /data/region.osm.pbf osrm-extract -p "/opt/${PROFILE}.lua" /data/region.osm.pbf
podman run --rm \ podman run --rm \
-v "${PROFILE_DIR}:/data" \ -v "${PROFILE_DIR}:/data" \
docker.io/osrm/osrm-backend:latest \ "$OSRM_IMAGE" \
osrm-partition /data/region.osrm osrm-partition /data/region.osrm
podman run --rm \ podman run --rm \
-v "${PROFILE_DIR}:/data" \ -v "${PROFILE_DIR}:/data" \
docker.io/osrm/osrm-backend:latest \ "$OSRM_IMAGE" \
osrm-customize /data/region.osrm osrm-customize /data/region.osrm
echo "OSRM $PROFILE profile ready." echo "OSRM $PROFILE profile ready."