Skip to content

Commit 455ebc3

Browse files
committed
refactor: Streamline Docker build workflow and remove unused Maven dependency preparation
1 parent 4534615 commit 455ebc3

File tree

1 file changed

+29
-138
lines changed

1 file changed

+29
-138
lines changed

.github/workflows/docker-build-and-test.yml

Lines changed: 29 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ on:
99
env:
1010
TEST_IMAGE_NAME: 'local/openrouteservice:test'
1111
TEST_minimal_IMAGE_NAME: 'local/openrouteservice:test-minimal'
12-
BUILD_PLATFORMS: 'linux/amd64,linux/arm64'
1312

1413

1514
jobs:
16-
# This way the env variables are accessible in the individual jobs
1715
prepare_environment:
1816
name: Prepare the environment variables
1917
runs-on: ubuntu-latest
2018
outputs:
2119
test_image_name: ${{ env.TEST_IMAGE_NAME }}
2220
test_minimal_image_name: ${{ env.TEST_minimal_IMAGE_NAME }}
23-
build_platforms: ${{ env.BUILD_PLATFORMS }}
2421
dockerfile_hash: ${{ steps.dockerfile-hash.outputs.hash }}
22+
should_skip_arm64: ${{ steps.should_skip_arm64.outputs.skip }}
2523
steps:
2624
- name: Checkout
2725
uses: actions/checkout@v4
@@ -30,132 +28,29 @@ jobs:
3028
run: |
3129
HASH=$(sha256sum Dockerfile | cut -d' ' -f1 | cut -c1-8)
3230
echo "hash=$HASH" >> $GITHUB_OUTPUT
31+
- name: Check if should skip ARM64 (draft PR)
32+
id: should_skip_arm64
33+
run: |
34+
SKIP="false"
35+
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.draft }}" == "true" ]]; then
36+
SKIP="true"
37+
fi
38+
echo "skip=$SKIP" >> $GITHUB_OUTPUT
3339
- run: |
3440
echo "Publish environment variables"
35-
prepare_maven_dependencies:
36-
name: Prepare Maven dependencies for ${{ matrix.name }}
37-
runs-on: ${{ matrix.runner }}
38-
needs:
39-
- prepare_environment
40-
strategy:
41-
matrix:
42-
include:
43-
- platform: linux/amd64
44-
name: linux-amd64
45-
runner: ubuntu-latest
46-
- platform: linux/arm64
47-
name: linux-arm64
48-
runner: ubuntu-24.04-arm
49-
steps:
50-
- name: Checkout
51-
uses: actions/checkout@v4
52-
with:
53-
fetch-depth: 0
54-
- name: Set up JDK 21
55-
uses: actions/setup-java@v4
56-
id: setup-java
57-
with:
58-
distribution: 'temurin'
59-
java-version: '21'
60-
cache: 'maven'
61-
- name: Download Maven dependencies
62-
if: steps.setup-java.outputs.cache-hit != 'true'
63-
run: |
64-
./mvnw package -q dependency:resolve dependency:resolve-plugins -Dmaven.test.skip=true > /dev/null || true
41+
6542
build_docker_images:
66-
name: Build ${{ matrix.image_stage }} for ${{ matrix.name }}
67-
runs-on: ${{ matrix.runner }}
43+
name: Build Docker images
6844
needs:
6945
- prepare_environment
70-
- prepare_maven_dependencies
71-
strategy:
72-
matrix:
73-
include:
74-
- platform: linux/amd64
75-
name: linux-amd64
76-
runner: ubuntu-latest
77-
image_stage: publish
78-
skip_on_draft_pr: false
79-
tags: ${{ needs.prepare_environment.outputs.test_image_name }}
80-
- platform: linux/arm64
81-
name: linux-arm64
82-
runner: ubuntu-24.04-arm
83-
image_stage: publish
84-
skip_on_draft_pr: true
85-
tags: ${{ needs.prepare_environment.outputs.test_image_name }}
86-
- platform: linux/amd64
87-
name: linux-amd64
88-
runner: ubuntu-latest
89-
image_stage: minimal
90-
skip_on_draft_pr: false
91-
tags: ${{ needs.prepare_environment.outputs.test_minimal_image_name }}
92-
- platform: linux/arm64
93-
name: linux-arm64
94-
runner: ubuntu-24.04-arm
95-
image_stage: minimal
96-
skip_on_draft_pr: true
97-
tags: ${{ needs.prepare_environment.outputs.test_minimal_image_name }}
98-
steps:
99-
- name: Checkout
100-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
101-
uses: actions/checkout@v4
102-
with:
103-
fetch-depth: 0
104-
- name: Get and save the UID
105-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
106-
run: |
107-
echo "UID=$(id -u)" >> $GITHUB_ENV
108-
- name: Set up Docker Buildx
109-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
110-
uses: docker/setup-buildx-action@v3
111-
id: setup-buildx
112-
- name: Set up JDK 21
113-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
114-
uses: actions/setup-java@v4
115-
id: setup-java
116-
with:
117-
distribution: 'temurin'
118-
java-version: '21'
119-
cache: 'maven'
120-
- name: Prepare Dockerfile for Maven cache
121-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
122-
run: |
123-
sed -i "s|RUN \./mvnw |RUN --mount=type=cache,target=/root/.m2/repository ./mvnw |g" Dockerfile
124-
- name: Inject Maven cache into Docker build
125-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
126-
uses: 'reproducible-containers/buildkit-cache-dance@5b81f4d29dc8397a7d341dba3aeecc7ec54d6361' # v3.3.0
127-
with:
128-
builder: ${{ steps.setup-buildx.outputs.name }}
129-
dockerfile: Dockerfile
130-
skip-extraction: ${{ steps.setup-java.outputs.cache-hit }}
131-
cache-map: |
132-
{
133-
"/home/runner/.m2/repository": "/root/.m2/repository"
134-
}
135-
- name: Build ${{ matrix.image_stage }} image stage for ${{ matrix.name }}
136-
uses: docker/build-push-action@v6
137-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
138-
with:
139-
context: .
140-
build-args: MAVEN_OPTS=-Dmaven.repo.local=/root/.m2/repository
141-
target: ${{ matrix.image_stage }}
142-
push: false
143-
load: false
144-
tags: ${{ matrix.tags }}
145-
platforms: "${{ matrix.platform }}"
146-
cache-from: type=gha
147-
cache-to: type=gha,mode=max
148-
outputs: type=docker,dest=${{ runner.temp }}/image-${{ matrix.name }}-${{ matrix.image_stage }}.tar
149-
- name: Upload image artifact
150-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
151-
uses: actions/upload-artifact@v4
152-
with:
153-
name: image-${{ matrix.name }}-${{ matrix.image_stage }}-${{ needs.prepare_environment.outputs.dockerfile_hash }}-artifact
154-
path: ${{ runner.temp }}/image-${{ matrix.name }}-${{ matrix.image_stage }}.tar
155-
retention-days: 1
156-
if-no-files-found: error
157-
compression-level: 0
158-
overwrite: true
46+
uses: ./.github/reusable/build-docker-images.yml
47+
with:
48+
push: false
49+
tags_publish_amd64: ${{ needs.prepare_environment.outputs.test_image_name }}
50+
tags_publish_arm64: ${{ needs.prepare_environment.outputs.test_image_name }}
51+
tags_minimal_amd64: ${{ needs.prepare_environment.outputs.test_minimal_image_name }}
52+
tags_minimal_arm64: ${{ needs.prepare_environment.outputs.test_minimal_image_name }}
53+
skip_arm64: ${{ needs.prepare_environment.outputs.should_skip_arm64 == 'true' }}
15954
docker_image_tests:
16055
name: Test ${{ matrix.name }} - publish image
16156
runs-on: ${{ matrix.runner }}
@@ -169,38 +64,36 @@ jobs:
16964
name: linux-amd64
17065
health_wait_time: 260
17166
image_stage: publish
172-
skip_on_draft_pr: false
17367
runner: ubuntu-latest
17468
- platform: linux/arm64
17569
name: linux-arm64
17670
health_wait_time: 260
177-
skip_on_draft_pr: true
17871
image_stage: publish
17972
runner: ubuntu-24.04-arm
18073
steps:
18174
- name: Checkout
182-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
75+
if: matrix.name == 'linux-amd64' || needs.prepare_environment.outputs.should_skip_arm64 == 'false'
18376
uses: actions/checkout@v4
18477
with:
18578
fetch-depth: 0
18679
- name: Download image artifact
187-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
80+
if: matrix.name == 'linux-amd64' || needs.prepare_environment.outputs.should_skip_arm64 == 'false'
18881
uses: actions/download-artifact@v4
18982
with:
19083
name: image-${{ matrix.name }}-${{ matrix.image_stage }}-${{ needs.prepare_environment.outputs.dockerfile_hash }}-artifact
19184
path: ${{ runner.temp }}
19285
- name: Set up Docker Buildx
193-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
86+
if: matrix.name == 'linux-amd64' || needs.prepare_environment.outputs.should_skip_arm64 == 'false'
19487
uses: docker/setup-buildx-action@v3
19588
- name: Load image
196-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
89+
if: matrix.name == 'linux-amd64' || needs.prepare_environment.outputs.should_skip_arm64 == 'false'
19790
run: |
19891
docker load --input ${{ runner.temp }}/image-${{ matrix.name }}-${{ matrix.image_stage }}.tar
19992
- name: Get and save the UID
20093
run: |
20194
echo "UID=$(id -u)" >> $GITHUB_ENV
20295
- name: Start container from previously build image and wait for successful checks
203-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
96+
if: matrix.name == 'linux-amd64' || needs.prepare_environment.outputs.should_skip_arm64 == 'false'
20497
run: |
20598
mkdir -p $(pwd)/ors-docker/graphs $(pwd)/ors-docker/config $(pwd)/ors-docker/elevation_cache
20699
chown -R $UID $(pwd)/ors-docker/graphs $(pwd)/ors-docker/config $(pwd)/ors-docker $(pwd)/ors-docker/elevation_cache
@@ -251,37 +144,35 @@ jobs:
251144
- platform: linux/amd64
252145
name: linux-amd64
253146
image_stage: minimal
254-
skip_on_draft_pr: false
255147
runner: ubuntu-latest
256148
wait_time: 180
257149
- platform: linux/arm64
258150
name: linux-arm64
259-
skip_on_draft_pr: true
260151
image_stage: minimal
261152
runner: ubuntu-24.04-arm
262153
wait_time: 180
263154
steps:
264155
- name: Checkout
265-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
156+
if: matrix.name == 'linux-amd64' || needs.prepare_environment.outputs.should_skip_arm64 == 'false'
266157
uses: actions/checkout@v4
267158
with:
268159
fetch-depth: 0
269160
- name: Download image artifact
270-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
161+
if: matrix.name == 'linux-amd64' || needs.prepare_environment.outputs.should_skip_arm64 == 'false'
271162
uses: actions/download-artifact@v4
272163
with:
273164
name: image-${{ matrix.name }}-${{ matrix.image_stage }}-${{ needs.prepare_environment.outputs.dockerfile_hash }}-artifact
274165
path: ${{ runner.temp }}
275166
- name: Load image
276-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
167+
if: matrix.name == 'linux-amd64' || needs.prepare_environment.outputs.should_skip_arm64 == 'false'
277168
run: |
278169
docker load --input ${{ runner.temp }}/image-${{ matrix.name }}-${{ matrix.image_stage }}.tar
279170
- name: Get and save the UID
280-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
171+
if: matrix.name == 'linux-amd64' || needs.prepare_environment.outputs.should_skip_arm64 == 'false'
281172
run: |
282173
echo "UID=$(id -u)" >> $GITHUB_ENV
283174
- name: Test minimal image with graph build
284-
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.draft == true && matrix.skip_on_draft_pr) }}
175+
if: matrix.name == 'linux-amd64' || needs.prepare_environment.outputs.should_skip_arm64 == 'false'
285176
run: |
286177
mkdir -p $(pwd)/ors-docker/elevation_cache
287178
chown -R $UID $(pwd)/ors-docker/elevation_cache

0 commit comments

Comments
 (0)