From c3f2a6cdb929b2dfd1afa770520dd845473c8de0 Mon Sep 17 00:00:00 2001 From: knowname Date: Thu, 20 Jun 2024 09:08:57 +0200 Subject: [PATCH] Add CI job for building Alpine-based Docker image (#6959) --- .github/workflows/osrm-backend-docker.yml | 20 +++---- .github/workflows/osrm-backend.yml | 9 ++- docker/Dockerfile | 69 +---------------------- docker/Dockerfile-debian | 68 ++++++++++++++++++++++ 4 files changed, 85 insertions(+), 81 deletions(-) mode change 100644 => 120000 docker/Dockerfile create mode 100644 docker/Dockerfile-debian diff --git a/.github/workflows/osrm-backend-docker.yml b/.github/workflows/osrm-backend-docker.yml index e0cf8939d..499731f90 100644 --- a/.github/workflows/osrm-backend-docker.yml +++ b/.github/workflows/osrm-backend-docker.yml @@ -6,6 +6,9 @@ on: jobs: publish: + strategy: + matrix: + docker-base-image: ["debian", "alpine"] runs-on: ubuntu-latest steps: - name: Check out the repo @@ -53,10 +56,10 @@ jobs: with: push: true platforms: linux/amd64,linux/arm64 - file: ./docker/Dockerfile + file: ./docker/Dockerfile-${{ matrix.docker-base-image }} tags: ${{ steps.metadebug.outputs.tags }} build-args: | - DOCKER_TAG=${{ join(steps.metadebug.outputs.tags ) }} + DOCKER_TAG=${{ join(steps.metadebug.outputs.tags ) }}-${{ matrix.docker-base-image }} - name: Build container image - assertions @@ -64,10 +67,10 @@ jobs: with: push: true platforms: linux/amd64,linux/arm64 - file: ./docker/Dockerfile + file: ./docker/Dockerfile-${{ matrix.docker-base-image }} tags: ${{ steps.metaassertions.outputs.tags }} build-args: | - DOCKER_TAG=${{ join(steps.metaassertions.outputs.tags ) }} + DOCKER_TAG=${{ join(steps.metaassertions.outputs.tags ) }}-${{ matrix.docker-base-image }} # build and publish "normal" image as last to get it listed on top - name: Build container image - normal @@ -75,10 +78,7 @@ jobs: with: push: true platforms: linux/amd64,linux/arm64 - file: ./docker/Dockerfile - tags: ${{ steps.meta.outputs.tags }} + file: ./docker/Dockerfile-${{ matrix.docker-base-image }} + tags: ${{ steps.meta.outputs.tags }} build-args: | - DOCKER_TAG=${{ join(steps.meta.outputs.tags ) }} - - - + DOCKER_TAG=${{ join(steps.meta.outputs.tags ) }}-${{ matrix.docker-base-image }} diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index 98c6fbd0f..ca77f6e82 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -116,7 +116,10 @@ jobs: npm run docs && ./scripts/error_on_dirty.sh npm audit --production - docker-image: + docker-image-matrix: + strategy: + matrix: + docker-base-image: ["debian", "alpine"] needs: format-taginfo-docs runs-on: ubuntu-22.04 continue-on-error: false @@ -132,7 +135,7 @@ jobs: v1-berlin-osm-pbf - name: Docker build run: | - docker build -t osrm-backend-local -f docker/Dockerfile . + docker build -t osrm-backend-local -f docker/Dockerfile-${{ matrix.docker-base-image }} . - name: Test Docker image run: | if [ ! -f "${PWD}/berlin-latest.osm.pbf" ]; then @@ -734,6 +737,6 @@ jobs: ci-complete: runs-on: ubuntu-22.04 - needs: [build-test-publish, docker-image, windows-release-node, benchmarks] + needs: [build-test-publish, docker-image-matrix, windows-release-node, benchmarks] steps: - run: echo "CI complete" diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index ca4ae165d..000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,68 +0,0 @@ -FROM debian:bookworm-slim as builder -ARG DOCKER_TAG -ARG BUILD_CONCURRENCY -RUN mkdir -p /src && mkdir -p /opt - -RUN apt-get update && \ - apt-get -y --no-install-recommends install ca-certificates cmake make git gcc g++ libbz2-dev libxml2-dev wget \ - libzip-dev libboost1.81-all-dev lua5.4 liblua5.4-dev pkg-config -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 - -RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \ - ldconfig /usr/local/lib && \ - git clone --branch v2021.12.0 --single-branch https://github.com/oneapi-src/oneTBB.git && \ - cd oneTBB && \ - mkdir build && \ - cd build && \ - cmake -DTBB_TEST=OFF -DCMAKE_BUILD_TYPE=Release .. && \ - cmake --build . && \ - cmake --install . - -COPY . /src -WORKDIR /src - -RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \ - export CXXFLAGS="-Wno-array-bounds -Wno-uninitialized" && \ - 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 debian:bookworm-slim as runstage - -COPY --from=builder /usr/local /usr/local -COPY --from=builder /opt /opt - -RUN apt-get update && \ - apt-get install -y --no-install-recommends libboost-program-options1.81.0 libboost-regex1.81.0 \ - libboost-date-time1.81.0 libboost-chrono1.81.0 libboost-filesystem1.81.0 \ - libboost-iostreams1.81.0 libboost-system1.81.0 libboost-thread1.81.0 \ - expat liblua5.4-0 && \ - rm -rf /var/lib/apt/lists/* && \ -# add /usr/local/lib to ldconfig to allow loading libraries from there - 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 diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 120000 index 000000000..4407bedc5 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1 @@ +Dockerfile-debian \ No newline at end of file diff --git a/docker/Dockerfile-debian b/docker/Dockerfile-debian new file mode 100644 index 000000000..ca4ae165d --- /dev/null +++ b/docker/Dockerfile-debian @@ -0,0 +1,68 @@ +FROM debian:bookworm-slim as builder +ARG DOCKER_TAG +ARG BUILD_CONCURRENCY +RUN mkdir -p /src && mkdir -p /opt + +RUN apt-get update && \ + apt-get -y --no-install-recommends install ca-certificates cmake make git gcc g++ libbz2-dev libxml2-dev wget \ + libzip-dev libboost1.81-all-dev lua5.4 liblua5.4-dev pkg-config -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 + +RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \ + ldconfig /usr/local/lib && \ + git clone --branch v2021.12.0 --single-branch https://github.com/oneapi-src/oneTBB.git && \ + cd oneTBB && \ + mkdir build && \ + cd build && \ + cmake -DTBB_TEST=OFF -DCMAKE_BUILD_TYPE=Release .. && \ + cmake --build . && \ + cmake --install . + +COPY . /src +WORKDIR /src + +RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \ + export CXXFLAGS="-Wno-array-bounds -Wno-uninitialized" && \ + 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 debian:bookworm-slim as runstage + +COPY --from=builder /usr/local /usr/local +COPY --from=builder /opt /opt + +RUN apt-get update && \ + apt-get install -y --no-install-recommends libboost-program-options1.81.0 libboost-regex1.81.0 \ + libboost-date-time1.81.0 libboost-chrono1.81.0 libboost-filesystem1.81.0 \ + libboost-iostreams1.81.0 libboost-system1.81.0 libboost-thread1.81.0 \ + expat liblua5.4-0 && \ + rm -rf /var/lib/apt/lists/* && \ +# add /usr/local/lib to ldconfig to allow loading libraries from there + 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