From afe357c9b6e1a1f1198bd85fd0f11618659987a9 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 27 Nov 2018 13:35:49 +0300 Subject: [PATCH] Valhalla source build in Docker --- Dockerfile | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 13 ++++++++++ etc/apt/apt.conf | 4 ++++ geos-3.7.diff | 26 ++++++++++++++++++++ home/start.sh | 11 +++++++++ 5 files changed, 116 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 etc/apt/apt.conf create mode 100644 geos-3.7.diff create mode 100755 home/start.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f67ddf4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,62 @@ +FROM debian:sid AS build +MAINTAINER Vitaliy Filippov + +ADD etc /etc + +# ca-certificates & gnupg2 needed to pull nodejs from nodesource repo +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -q \ + less wget sudo curl unzip git mc ca-certificates gnupg2 \ + build-essential cmake zlib1g-dev libprotobuf-dev libcurl4-openssl-dev pkg-config protobuf-compiler libzmq3-dev libczmq-dev \ + libgeos-dev libgeos++-dev liblua5.2-dev libspatialite-dev libsqlite3-dev lua5.2 \ + libboost-date-time-dev libboost-filesystem-dev libboost-system-dev libboost-program-options-dev libboost-python-dev && \ + (curl -L https://deb.nodesource.com/setup_8.x | bash -) && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs gyp && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +ADD geos-3.7.diff /home + +RUN mkdir /home/valhalla && \ + cd /home/valhalla && \ + git clone https://github.com/kevinkreiser/prime_server && \ + cd /home/valhalla/prime_server && \ + git submodule update --init --recursive && \ + mkdir build && cd build && cmake .. && make -j4 install && \ + tar -cf /home/valhalla/prime_server.tar -T install_manifest.txt + +RUN cd /home/valhalla && \ + git clone https://github.com/valhalla/valhalla && \ + cd /home/valhalla/valhalla && \ + git submodule update --init --recursive + +RUN cd /home/valhalla/valhalla && \ + patch -p1 < /home/geos-3.7.diff && \ + npm install node-cmake && \ + cd /home/valhalla/valhalla && mkdir build && cd build && cmake .. && make -j4 install && \ + tar -cf /home/valhalla/valhalla.tar -T install_manifest.txt && \ + cd .. && tar -cf /home/valhalla/node-valhalla.tar lib package.json + +FROM debian:sid AS run +MAINTAINER Vitaliy Filippov + +ADD etc /etc + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -q \ + less wget sudo curl unzip git mc \ + zlib1g libprotobuf17 libprotobuf-lite17 libcurl4 libzmq5 libczmq4 libgeos-3.7.0 libspatialite7 libsqlite3-0 lua5.2 liblua5.2-0 \ + libboost-date-time1.67.0 libboost-filesystem1.67.0 libboost-system1.67.0 libboost-program-options1.67.0 python && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +COPY --from=build /home/valhalla/node-valhalla.tar /home/valhalla/valhalla.tar /home/valhalla/prime_server.tar /home/valhalla/ + +RUN cd / && tar -xf /home/valhalla/valhalla.tar && tar -xf /home/valhalla/prime_server.tar && rm /home/valhalla/*.tar && ldconfig + +ADD home /home + +RUN cd /home/valhalla && valhalla_build_config --mjolnir-tile-dir ${PWD}/valhalla_tiles \ + --mjolnir-tile-extract ${PWD}/valhalla_tiles.tar \ + --mjolnir-timezone ${PWD}/valhalla_tiles/timezones.sqlite \ + --mjolnir-admin ${PWD}/valhalla_tiles/admins.sqlite > valhalla.json + +CMD /home/start.sh + +EXPOSE 8002 diff --git a/README.md b/README.md new file mode 100644 index 0000000..fdaf899 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +## Building + +``` +docker build -t valhalla . +``` + +## Running + +``` +docker run -it -d --restart always \ + -v /home/test/russia-latest.osm.pbf:/home/valhalla/data.osm.pbf \ + --name valhalla -p 8002:8002 valhalla +``` diff --git a/etc/apt/apt.conf b/etc/apt/apt.conf new file mode 100644 index 0000000..68d79bf --- /dev/null +++ b/etc/apt/apt.conf @@ -0,0 +1,4 @@ +APT::Install-Suggests false; +APT::Install-Recommends false; +Acquire::Retries 5; +Binary::apt::APT::Keep-Downloaded-Packages "false"; diff --git a/geos-3.7.diff b/geos-3.7.diff new file mode 100644 index 0000000..4b9865f --- /dev/null +++ b/geos-3.7.diff @@ -0,0 +1,26 @@ +diff --git a/src/mjolnir/valhalla_build_admins.cc b/src/mjolnir/valhalla_build_admins.cc +index 3f675a231..cc211ce42 100644 +--- a/src/mjolnir/valhalla_build_admins.cc ++++ b/src/mjolnir/valhalla_build_admins.cc +@@ -143,7 +143,9 @@ int polygondata_comparearea(const void* vp1, const void* vp2) { + std::vector GetWkts(std::unique_ptr& mline) { + std::vector wkts; + +-#if 3 == GEOS_VERSION_MAJOR && 6 <= GEOS_VERSION_MINOR ++#if 3 == GEOS_VERSION_MAJOR && 7 <= GEOS_VERSION_MINOR ++ GeometryFactory::Ptr gf = GeometryFactory::create(); ++#elif 3 == GEOS_VERSION_MAJOR && 6 <= GEOS_VERSION_MINOR + GeometryFactory::unique_ptr gf = GeometryFactory::create(); + #else + std::unique_ptr gf(new GeometryFactory()); +@@ -422,7 +424,9 @@ void BuildAdminFromPBF(const boost::property_tree::ptree& pt, + uint32_t count = 0; + uint64_t nodeid; + bool has_data; +-#if 3 == GEOS_VERSION_MAJOR && 6 <= GEOS_VERSION_MINOR ++#if 3 == GEOS_VERSION_MAJOR && 7 <= GEOS_VERSION_MINOR ++ GeometryFactory::Ptr gf = GeometryFactory::create(); ++#elif 3 == GEOS_VERSION_MAJOR && 6 <= GEOS_VERSION_MINOR + GeometryFactory::unique_ptr gf = GeometryFactory::create(); + #else + std::unique_ptr gf(new GeometryFactory()); diff --git a/home/start.sh b/home/start.sh new file mode 100755 index 0000000..e9e61df --- /dev/null +++ b/home/start.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +cd /home/valhalla + +if [ valhalla_tiles.tar -ot data.osm.pbf ]; then + rm -rf valhalla_tiles + valhalla_build_tiles -c valhalla.json data.osm.pbf + find valhalla_tiles | sort -n | tar cf valhalla_tiles.tar --no-recursion -T - +fi + +valhalla_service valhalla.json 1