Skip to content

Commit 97f676d

Browse files
authored
add alpine dockerfile (#6958)
1 parent 7ffc08b commit 97f676d

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

docker/Dockerfile-alpine

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

docker/hooks/build

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
# ensure that "COPY . /src" is referring to the repo root, not the directory
77
# that contains the Dockerfile.
88
# This script gets executed with a pwd of wherever the Dockerfile is.
9-
docker build --build-arg BUILD_CONCURRENCY=${CONCURRENCY:-1} --build-arg DOCKER_TAG=${DOCKER_TAG} -t $IMAGE_NAME -f Dockerfile ..
9+
10+
DOCKER_BUILD="docker build --build-arg BUILD_CONCURRENCY=${CONCURRENCY} --build-arg DOCKER_TAG=${DOCKER_TAG:?unset} -t ${IMAGE_NAME:?unset} -f"
11+
12+
$DOCKER_BUILD Dockerfile ..
13+
$DOCKER_BUILD Dockerfile-alpine ..

0 commit comments

Comments
 (0)