|
| 1 | +FROM alpine:3.20.0 as alpine-mimalloc |
| 2 | + |
| 3 | +RUN apk add --no-cache mimalloc |
| 4 | + |
| 5 | +ENV LD_PRELOAD=/usr/lib/libmimalloc.so.2 |
| 6 | +ENV MIMALLOC_LARGE_OS_PAGES=1 |
| 7 | + |
| 8 | + |
| 9 | +FROM alpine-mimalloc as builder |
| 10 | +ARG DOCKER_TAG |
| 11 | +ARG BUILD_CONCURRENCY |
| 12 | +RUN mkdir -p /src && mkdir -p /opt |
| 13 | + |
| 14 | +RUN apk add --no-cache \ |
| 15 | + cmake make git clang libbz2 libxml2 \ |
| 16 | + boost-dev boost-program_options boost-filesystem boost-iostreams boost-thread \ |
| 17 | + lua5.4-dev onetbb-dev expat-dev |
| 18 | + |
| 19 | +COPY . /src |
| 20 | +WORKDIR /src |
| 21 | + |
| 22 | +RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \ |
| 23 | + echo "Building OSRM ${DOCKER_TAG}" && \ |
| 24 | + git show --format="%H" | head -n1 > /opt/OSRM_GITSHA && \ |
| 25 | + echo "Building OSRM gitsha $(cat /opt/OSRM_GITSHA)" && \ |
| 26 | + mkdir -p build && \ |
| 27 | + cd build && \ |
| 28 | + BUILD_TYPE="Release" && \ |
| 29 | + ENABLE_ASSERTIONS="Off" && \ |
| 30 | + BUILD_TOOLS="Off" && \ |
| 31 | + case ${DOCKER_TAG} in *"-debug"*) BUILD_TYPE="Debug";; esac && \ |
| 32 | + case ${DOCKER_TAG} in *"-assertions"*) BUILD_TYPE="RelWithDebInfo" && ENABLE_ASSERTIONS="On" && BUILD_TOOLS="On";; esac && \ |
| 33 | + echo "Building ${BUILD_TYPE} with ENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} BUILD_TOOLS=${BUILD_TOOLS}" && \ |
| 34 | + cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} -DBUILD_TOOLS=${BUILD_TOOLS} -DENABLE_LTO=On && \ |
| 35 | + make -j${NPROC} install && \ |
| 36 | + cd ../profiles && \ |
| 37 | + cp -r * /opt && \ |
| 38 | + strip /usr/local/bin/* && \ |
| 39 | + rm -rf /src |
| 40 | + |
| 41 | + |
| 42 | +# Multistage build to reduce image size - https://docs.docker.com/engine/userguide/eng-image/multistage-build/#use-multi-stage-builds |
| 43 | +# Only the content below ends up in the image, this helps remove /src from the image (which is large) |
| 44 | +FROM alpine-mimalloc as runstage |
| 45 | + |
| 46 | +COPY --from=builder /usr/local /usr/local |
| 47 | +COPY --from=builder /opt /opt |
| 48 | + |
| 49 | +RUN apk add --no-cache \ |
| 50 | + boost-program_options boost-regex \ |
| 51 | + boost-date_time boost-chrono boost-filesystem \ |
| 52 | + boost-iostreams boost-system boost-thread \ |
| 53 | + expat lua5.4 onetbb && \ |
| 54 | + ldconfig /usr/local/lib |
| 55 | + |
| 56 | +RUN /usr/local/bin/osrm-extract --help && \ |
| 57 | + /usr/local/bin/osrm-routed --help && \ |
| 58 | + /usr/local/bin/osrm-contract --help && \ |
| 59 | + /usr/local/bin/osrm-partition --help && \ |
| 60 | + /usr/local/bin/osrm-customize --help |
| 61 | + |
| 62 | +WORKDIR /opt |
| 63 | + |
| 64 | +EXPOSE 5000 |
0 commit comments