add alpine dockerfile (#6958)

This commit is contained in:
knowname 2024-06-19 14:15:23 +02:00 committed by GitHub
parent 7ffc08be28
commit 97f676d5a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 69 additions and 1 deletions

64
docker/Dockerfile-alpine Normal file
View File

@ -0,0 +1,64 @@
FROM alpine:3.20.0 as alpine-mimalloc
RUN apk add --no-cache mimalloc
ENV LD_PRELOAD=/usr/lib/libmimalloc.so.2
ENV MIMALLOC_LARGE_OS_PAGES=1
FROM alpine-mimalloc as builder
ARG DOCKER_TAG
ARG BUILD_CONCURRENCY
RUN mkdir -p /src && mkdir -p /opt
RUN apk add --no-cache \
cmake make git clang libbz2 libxml2 \
boost-dev boost-program_options boost-filesystem boost-iostreams boost-thread \
lua5.4-dev onetbb-dev expat-dev
COPY . /src
WORKDIR /src
RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \
echo "Building OSRM ${DOCKER_TAG}" && \
git show --format="%H" | head -n1 > /opt/OSRM_GITSHA && \
echo "Building OSRM gitsha $(cat /opt/OSRM_GITSHA)" && \
mkdir -p build && \
cd build && \
BUILD_TYPE="Release" && \
ENABLE_ASSERTIONS="Off" && \
BUILD_TOOLS="Off" && \
case ${DOCKER_TAG} in *"-debug"*) BUILD_TYPE="Debug";; esac && \
case ${DOCKER_TAG} in *"-assertions"*) BUILD_TYPE="RelWithDebInfo" && ENABLE_ASSERTIONS="On" && BUILD_TOOLS="On";; esac && \
echo "Building ${BUILD_TYPE} with ENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} BUILD_TOOLS=${BUILD_TOOLS}" && \
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} -DBUILD_TOOLS=${BUILD_TOOLS} -DENABLE_LTO=On && \
make -j${NPROC} install && \
cd ../profiles && \
cp -r * /opt && \
strip /usr/local/bin/* && \
rm -rf /src
# Multistage build to reduce image size - https://docs.docker.com/engine/userguide/eng-image/multistage-build/#use-multi-stage-builds
# Only the content below ends up in the image, this helps remove /src from the image (which is large)
FROM alpine-mimalloc as runstage
COPY --from=builder /usr/local /usr/local
COPY --from=builder /opt /opt
RUN apk add --no-cache \
boost-program_options boost-regex \
boost-date_time boost-chrono boost-filesystem \
boost-iostreams boost-system boost-thread \
expat lua5.4 onetbb && \
ldconfig /usr/local/lib
RUN /usr/local/bin/osrm-extract --help && \
/usr/local/bin/osrm-routed --help && \
/usr/local/bin/osrm-contract --help && \
/usr/local/bin/osrm-partition --help && \
/usr/local/bin/osrm-customize --help
WORKDIR /opt
EXPOSE 5000

6
docker/hooks/build Normal file → Executable file
View File

@ -6,4 +6,8 @@
# ensure that "COPY . /src" is referring to the repo root, not the directory # ensure that "COPY . /src" is referring to the repo root, not the directory
# that contains the Dockerfile. # that contains the Dockerfile.
# This script gets executed with a pwd of wherever the Dockerfile is. # This script gets executed with a pwd of wherever the Dockerfile is.
docker build --build-arg BUILD_CONCURRENCY=${CONCURRENCY:-1} --build-arg DOCKER_TAG=${DOCKER_TAG} -t $IMAGE_NAME -f Dockerfile ..
DOCKER_BUILD="docker build --build-arg BUILD_CONCURRENCY=${CONCURRENCY} --build-arg DOCKER_TAG=${DOCKER_TAG:?unset} -t ${IMAGE_NAME:?unset} -f"
$DOCKER_BUILD Dockerfile ..
$DOCKER_BUILD Dockerfile-alpine ..