Skip to content

Commit c3f2a6c

Browse files
authored
Add CI job for building Alpine-based Docker image (#6959)
1 parent 97f676d commit c3f2a6c

File tree

4 files changed

+85
-81
lines changed

4 files changed

+85
-81
lines changed

.github/workflows/osrm-backend-docker.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66

77
jobs:
88
publish:
9+
strategy:
10+
matrix:
11+
docker-base-image: ["debian", "alpine"]
912
runs-on: ubuntu-latest
1013
steps:
1114
- name: Check out the repo
@@ -53,32 +56,29 @@ jobs:
5356
with:
5457
push: true
5558
platforms: linux/amd64,linux/arm64
56-
file: ./docker/Dockerfile
59+
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
5760
tags: ${{ steps.metadebug.outputs.tags }}
5861
build-args: |
59-
DOCKER_TAG=${{ join(steps.metadebug.outputs.tags ) }}
62+
DOCKER_TAG=${{ join(steps.metadebug.outputs.tags ) }}-${{ matrix.docker-base-image }}
6063
6164
6265
- name: Build container image - assertions
6366
uses: docker/build-push-action@v2
6467
with:
6568
push: true
6669
platforms: linux/amd64,linux/arm64
67-
file: ./docker/Dockerfile
70+
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
6871
tags: ${{ steps.metaassertions.outputs.tags }}
6972
build-args: |
70-
DOCKER_TAG=${{ join(steps.metaassertions.outputs.tags ) }}
73+
DOCKER_TAG=${{ join(steps.metaassertions.outputs.tags ) }}-${{ matrix.docker-base-image }}
7174
7275
# build and publish "normal" image as last to get it listed on top
7376
- name: Build container image - normal
7477
uses: docker/build-push-action@v2
7578
with:
7679
push: true
7780
platforms: linux/amd64,linux/arm64
78-
file: ./docker/Dockerfile
79-
tags: ${{ steps.meta.outputs.tags }}
81+
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
82+
tags: ${{ steps.meta.outputs.tags }}
8083
build-args: |
81-
DOCKER_TAG=${{ join(steps.meta.outputs.tags ) }}
82-
83-
84-
84+
DOCKER_TAG=${{ join(steps.meta.outputs.tags ) }}-${{ matrix.docker-base-image }}

.github/workflows/osrm-backend.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ jobs:
116116
npm run docs && ./scripts/error_on_dirty.sh
117117
npm audit --production
118118
119-
docker-image:
119+
docker-image-matrix:
120+
strategy:
121+
matrix:
122+
docker-base-image: ["debian", "alpine"]
120123
needs: format-taginfo-docs
121124
runs-on: ubuntu-22.04
122125
continue-on-error: false
@@ -132,7 +135,7 @@ jobs:
132135
v1-berlin-osm-pbf
133136
- name: Docker build
134137
run: |
135-
docker build -t osrm-backend-local -f docker/Dockerfile .
138+
docker build -t osrm-backend-local -f docker/Dockerfile-${{ matrix.docker-base-image }} .
136139
- name: Test Docker image
137140
run: |
138141
if [ ! -f "${PWD}/berlin-latest.osm.pbf" ]; then
@@ -734,6 +737,6 @@ jobs:
734737
735738
ci-complete:
736739
runs-on: ubuntu-22.04
737-
needs: [build-test-publish, docker-image, windows-release-node, benchmarks]
740+
needs: [build-test-publish, docker-image-matrix, windows-release-node, benchmarks]
738741
steps:
739742
- run: echo "CI complete"

docker/Dockerfile

Lines changed: 0 additions & 68 deletions
This file was deleted.

docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dockerfile-debian

docker/Dockerfile-debian

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
FROM debian:bookworm-slim as builder
2+
ARG DOCKER_TAG
3+
ARG BUILD_CONCURRENCY
4+
RUN mkdir -p /src && mkdir -p /opt
5+
6+
RUN apt-get update && \
7+
apt-get -y --no-install-recommends install ca-certificates cmake make git gcc g++ libbz2-dev libxml2-dev wget \
8+
libzip-dev libboost1.81-all-dev lua5.4 liblua5.4-dev pkg-config -o APT::Install-Suggests=0 -o APT::Install-Recommends=0
9+
10+
RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \
11+
ldconfig /usr/local/lib && \
12+
git clone --branch v2021.12.0 --single-branch https://github.com/oneapi-src/oneTBB.git && \
13+
cd oneTBB && \
14+
mkdir build && \
15+
cd build && \
16+
cmake -DTBB_TEST=OFF -DCMAKE_BUILD_TYPE=Release .. && \
17+
cmake --build . && \
18+
cmake --install .
19+
20+
COPY . /src
21+
WORKDIR /src
22+
23+
RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \
24+
export CXXFLAGS="-Wno-array-bounds -Wno-uninitialized" && \
25+
echo "Building OSRM ${DOCKER_TAG}" && \
26+
git show --format="%H" | head -n1 > /opt/OSRM_GITSHA && \
27+
echo "Building OSRM gitsha $(cat /opt/OSRM_GITSHA)" && \
28+
mkdir -p build && \
29+
cd build && \
30+
BUILD_TYPE="Release" && \
31+
ENABLE_ASSERTIONS="Off" && \
32+
BUILD_TOOLS="Off" && \
33+
case ${DOCKER_TAG} in *"-debug"*) BUILD_TYPE="Debug";; esac && \
34+
case ${DOCKER_TAG} in *"-assertions"*) BUILD_TYPE="RelWithDebInfo" && ENABLE_ASSERTIONS="On" && BUILD_TOOLS="On";; esac && \
35+
echo "Building ${BUILD_TYPE} with ENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} BUILD_TOOLS=${BUILD_TOOLS}" && \
36+
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS} -DBUILD_TOOLS=${BUILD_TOOLS} -DENABLE_LTO=On && \
37+
make -j${NPROC} install && \
38+
cd ../profiles && \
39+
cp -r * /opt && \
40+
strip /usr/local/bin/* && \
41+
rm -rf /src
42+
43+
44+
# Multistage build to reduce image size - https://docs.docker.com/engine/userguide/eng-image/multistage-build/#use-multi-stage-builds
45+
# Only the content below ends up in the image, this helps remove /src from the image (which is large)
46+
FROM debian:bookworm-slim as runstage
47+
48+
COPY --from=builder /usr/local /usr/local
49+
COPY --from=builder /opt /opt
50+
51+
RUN apt-get update && \
52+
apt-get install -y --no-install-recommends libboost-program-options1.81.0 libboost-regex1.81.0 \
53+
libboost-date-time1.81.0 libboost-chrono1.81.0 libboost-filesystem1.81.0 \
54+
libboost-iostreams1.81.0 libboost-system1.81.0 libboost-thread1.81.0 \
55+
expat liblua5.4-0 && \
56+
rm -rf /var/lib/apt/lists/* && \
57+
# add /usr/local/lib to ldconfig to allow loading libraries from there
58+
ldconfig /usr/local/lib
59+
60+
RUN /usr/local/bin/osrm-extract --help && \
61+
/usr/local/bin/osrm-routed --help && \
62+
/usr/local/bin/osrm-contract --help && \
63+
/usr/local/bin/osrm-partition --help && \
64+
/usr/local/bin/osrm-customize --help
65+
66+
WORKDIR /opt
67+
68+
EXPOSE 5000

0 commit comments

Comments
 (0)