Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.42k stars 3.4k forks source link

creating an OSRM container that includes the routing data #7070

Open its-dibo opened 18 hours ago

its-dibo commented 18 hours ago

I want to create a container that includes ready-made data for OSRM routing

the image building process goes through these steps

1- download the pbf files for the desired city 2- download the profile, typically car.lua 3- extract & partition the data 4- start the routing server

and here is my Dockerfile

FROM osrm/osrm-backend:latest

ENV OSM_DATA_PATH=/osm_data
ENV OSRM_Region=africa/egypt
ENV profile=car

WORKDIR $OSM_DATA_PATH

# https://superuser.com/a/1830197/2368152
RUN echo "deb [trusted=yes] http://archive.debian.org/debian stretch main non-free contrib" > /etc/apt/sources.list \
    echo "deb-src [trusted=yes] http://archive.debian.org/debian stretch main non-free contrib" >> /etc/apt/sources.list \
    echo "deb [trusted=yes] http://archive.debian.org/debian-security stretch/updates main non-free contrib" >> /etc/apt/sources.list

RUN apt-get update \
    && apt-get install -y \
    wget \
    lua5.2 \
    # to use LuaRocks 
    lua5.2-dev \
    # The Lua package manager
    # to download and manage the dependencies of lua profiles
    luarocks \
    unzip \
    build-essential \ 
    git \   
    && apt-get clean

# download OSRM data
RUN wget -O ${OSRM_Region}-latest.osm.pbf https://download.geofabrik.de/${OSRM_Region}-latest.osm.pbf

# download profiles
RUN mkdir profiles
RUN wget -O profiles/$profile.lua https://github.com/Project-OSRM/osrm-backend/raw/master/profiles/car.lua

# Create the car-dependencies.rockspec file, 
# to download the dependencies of car.lua using luarocks
# or install dependencies directly `RUN luarocks install lua-cjson`
RUN cat <<EOF > $profile-dependencies-1.0-1.rockspec
package = "$profile-dependencies"
version = "1.0-1"
description = {
    summary = "Dependencies for $profile.lua",
    detailed = "This rockspec installs dependencies required by $profile.lua for OSRM routing",
    license = "MIT",
    homepage = "",
}
source = {
    url = "file://profiles/car.lua"
}
dependencies = {
-- I don't know what dependencies  should I install here
}
build = {
    type = "none"
}
EOF

# Use LuaRocks to install dependencies
RUN luarocks install $profile-dependencies-1.0-1.rockspec

RUN for pbf_file in *.pbf; do \
    echo ">>> Processing $pbf_file"; \
    # extracts routing data from the .pbf file using car.lua profile for vehicle routing
    osrm-extract "$pbf_file" -p profiles/$profile.lua --threads 4 && \
    # splits the graph into small chunks for faster processing during queries
    osrm-partition "$pbf_file.osrm" && \
    # customizes the graph with additional routing-related customizations such as turn penalties, etc., based on the profile.
    osrm-customize "$pbf_file.osrm"; \
    done

CMD sh -c "osrm-routed $OSRM_Region-latest.osrm --port 5000"

when building the image using docker build . I got:

[+] Building 48.8s (15/15) FINISHED                                                                              docker:default
 => [internal] load build definition from Dockerfile                                                                       0.0s
 => => transferring dockerfile: 2.69kB                                                                                     0.0s
 => WARN: JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals (l  0.0s
 => [internal] load metadata for docker.io/osrm/osrm-backend:latest                                                        0.0s
 => [internal] load .dockerignore                                                                                          0.0s
 => => transferring context: 471B                                                                                          0.0s
 => [ 1/11] FROM docker.io/osrm/osrm-backend:latest@sha256:af5d4a83fb90086a43b1ae2ca22872e6768766ad5fcbb07a29ff90ec644ee4  1.3s
 => => resolve docker.io/osrm/osrm-backend:latest@sha256:af5d4a83fb90086a43b1ae2ca22872e6768766ad5fcbb07a29ff90ec644ee409  1.3s
 => [auth] osrm/osrm-backend:pull token for registry-1.docker.io                                                           0.0s
 => CACHED [ 2/11] WORKDIR /osm_data                                                                                       0.0s
 => CACHED [ 3/11] RUN echo "deb [trusted=yes] http://archive.debian.org/debian stretch main non-free contrib" > /etc/apt  0.0s
 => CACHED [ 4/11] RUN apt-get update     && apt-get install -y     wget     lua5.2     lua5.2-dev     luarocks     unzip  0.0s
 => [ 5/11] RUN mkdir $(dirname "africa/egypt")                                                                            0.4s
 => [ 6/11] RUN wget -O africa/egypt-latest.osm.pbf https://download.geofabrik.de/africa/egypt-latest.osm.pbf             36.5s
 => [ 7/11] RUN mkdir profiles                                                                                             0.6s 
 => [ 8/11] RUN wget -O profiles/car.lua https://github.com/Project-OSRM/osrm-backend/raw/master/profiles/car.lua          7.2s 
 => [ 9/11] RUN cat <<EOF > car-dependencies-1.0-1.rockspec                                                                0.5s 
 => [10/11] RUN luarocks install car-dependencies-1.0-1.rockspec                                                           0.7s 
 => ERROR [11/11] RUN for pbf_file in $(find . -type f -name "*.pbf"); do     echo ">>> Processing $pbf_file";     osrm-e  1.2s 
------                                                                                                                          
 > [11/11] RUN for pbf_file in $(find . -type f -name "*.pbf"); do     echo ">>> Processing $pbf_file";     osrm-extract "$pbf_file" -p profiles/car.lua --threads 4 &&     osrm-partition "$pbf_file.osrm" &&     osrm-customize "$pbf_file.osrm";     done:   
0.495 >>> Processing ./africa/egypt-latest.osm.pbf                                                                              
0.742 [info] Parsed 0 location-dependent features with 0 GeoJSON polygons                                                       
0.742 [info] Using script profiles/car.lua                                                                                      
0.743 [info] Input file: egypt-latest.osm.pbf
0.743 [info] Profile: car.lua
0.743 [info] Threads: 4
0.744 [info] Parsing in progress..
0.753 [info] input file generated by osmium/1.14.0
0.757 [info] timestamp: 2024-11-16T21:21:14Z
0.760 terminate called after throwing an instance of 'sol::error'
0.760   what():  lua: error: profiles/car.lua:5: module 'lib/set' not found:
0.760   no field package.preload['lib/set']
0.760   no file '/osm_data/profiles/lib/set.lua'
0.760   no file '/usr/local/share/lua/5.2/lib/set.lua'
0.760   no file '/usr/local/share/lua/5.2/lib/set/init.lua'
0.760   no file '/usr/local/lib/lua/5.2/lib/set.lua'
0.760   no file '/usr/local/lib/lua/5.2/lib/set/init.lua'
0.760   no file '/usr/share/lua/5.2/lib/set.lua'
0.760   no file '/usr/share/lua/5.2/lib/set/init.lua'
0.760   no file './lib/set.lua'
0.760   no file '/usr/local/lib/lua/5.2/lib/set.so'
0.760   no file '/usr/lib/x86_64-linux-gnu/lua/5.2/lib/set.so'
0.760   no file '/usr/lib/lua/5.2/lib/set.so'
0.760   no file '/usr/local/lib/lua/5.2/loadall.so'
0.760   no file './lib/set.so'
1.197 Aborted (core dumped)
------

 1 warning found (use docker --debug to expand):
 - JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals (line 80)
Dockerfile:70
--------------------
  69 |     
  70 | >>> RUN for pbf_file in $(find . -type f -name "*.pbf"); do \
  71 | >>>     echo ">>> Processing $pbf_file"; \
  72 | >>>     # extracts routing data from the .pbf file using car.lua profile for vehicle routing
  73 | >>>     osrm-extract "$pbf_file" -p profiles/$profile.lua --threads 4 && \
  74 | >>>     # splits the graph into small chunks for faster processing during queries
  75 | >>>     osrm-partition "$pbf_file.osrm" && \
  76 | >>>     # customizes the graph with additional routing-related customizations such as turn penalties, etc., based on the profile.
  77 | >>>     osrm-customize "$pbf_file.osrm"; \
  78 | >>>     done
  79 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c for pbf_file in $(find . -type f -name \"*.pbf\"); do     echo \">>> Processing $pbf_file\";     osrm-extract \"$pbf_file\" -p profiles/$profile.lua --threads 4 &&     osrm-partition \"$pbf_file.osrm\" &&     osrm-customize \"$pbf_file.osrm\";     done" did not complete successfully: exit code: 134