Skip to content

Commit 8548e06

Browse files
committed
chore: Implement setup-build-environment action and streamline workflows
1 parent 7ef7493 commit 8548e06

File tree

5 files changed

+102
-51
lines changed

5 files changed

+102
-51
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Setup Build Environment
2+
description: Set up Java/Maven and optionally Docker (QEMU + Buildx) with Maven cache injection
3+
inputs:
4+
java_version:
5+
description: Java version to install
6+
required: false
7+
default: '21'
8+
with_docker:
9+
description: Set up Docker (Buildx) for image builds
10+
required: false
11+
default: 'true'
12+
dockerfile:
13+
description: Path to the primary Dockerfile to use for buildkit injection (only used if with_docker is true)
14+
required: false
15+
default: 'Dockerfile'
16+
outputs:
17+
buildx_builder:
18+
description: Name of the buildx builder (only available if with_docker is true)
19+
value: ${{ steps.buildx.outputs.name }}
20+
cache-hit:
21+
description: Whether the Maven cache was hit
22+
value: ${{ steps.setup-java.outputs.cache-hit }}
23+
runs:
24+
using: composite
25+
steps:
26+
- name: Setup Java and Maven
27+
id: setup-java
28+
uses: ./.github/actions/setup-java-maven
29+
with:
30+
java_version: ${{ inputs.java_version }}
31+
32+
- name: Set up Docker Buildx
33+
if: inputs.with_docker == 'true'
34+
id: buildx
35+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 #v3.11.1
36+
37+
- name: Prepare all Dockerfiles for Maven cache mount
38+
if: inputs.with_docker == 'true'
39+
shell: bash
40+
run: |
41+
# Find and prepare all Dockerfiles in the repository
42+
find . -name "Dockerfile" -o -name "*.Dockerfile" | while read dockerfile; do
43+
sed -i "s|RUN \./mvnw |RUN --mount=type=cache,target=/root/.m2/repository ./mvnw |g" "$dockerfile"
44+
done
45+
46+
- name: Inject Maven cache into Docker build
47+
if: inputs.with_docker == 'true'
48+
uses: 'reproducible-containers/buildkit-cache-dance@5b81f4d29dc8397a7d341dba3aeecc7ec54d6361' # v3.3.0
49+
with:
50+
builder: ${{ steps.buildx.outputs.name }}
51+
dockerfile: ${{ inputs.dockerfile }}
52+
skip-extraction: ${{ steps.setup-java.outputs.cache-hit }}
53+
cache-map: |
54+
{
55+
"/home/runner/.m2/repository": "/root/.m2/repository"
56+
}

.github/workflows/_build-docker-images.yml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ jobs:
7575
uses: actions/checkout@v4
7676
with:
7777
fetch-depth: 0
78-
- name: Setup Java and Maven
79-
uses: ./.github/actions/setup-java-maven
80-
with:
81-
java_version: ${{ inputs.java_version }}
8278

8379
build_docker_images:
8480
name: Build ${{ matrix.image_stage }} for ${{ matrix.name }}
@@ -134,25 +130,12 @@ jobs:
134130
run: |
135131
echo "UID=$(id -u)" >> $GITHUB_ENV
136132
137-
- name: Set up Docker Buildx
138-
if: steps.should_skip.outputs.skip != 'true'
139-
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 #v3.11.1
140-
id: buildx
141-
142-
- name: Setup Java and Maven
143-
id: setup-java
133+
- name: Set up build environment
144134
if: steps.should_skip.outputs.skip != 'true'
145-
uses: ./.github/actions/setup-java-maven
135+
uses: ./.github/actions/setup-build-environment
146136
with:
147137
java_version: ${{ inputs.java_version }}
148-
149-
- name: Maven cache dance
150-
if: steps.should_skip.outputs.skip != 'true'
151-
uses: ./.github/actions/maven-cache-dance
152-
with:
153-
builder: ${{ steps.buildx.outputs.name }}
154138
dockerfile: 'Dockerfile'
155-
cache-hit: ${{ steps.setup-java.outputs.cache-hit }}
156139

157140
- name: Resolve Docker tag
158141
if: steps.should_skip.outputs.skip != 'true'

.github/workflows/docker-nightly-image.yml

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,59 +29,77 @@ on:
2929
default: 'schedule'
3030

3131
jobs:
32-
check-commits:
32+
prepare_environment:
33+
name: Prepare the environment variables
3334
runs-on: ubuntu-latest
3435
outputs:
35-
new_commits: ${{ steps.check.outputs.NEW_COMMITS }}
36+
docker_tag: ${{ steps.resolve-tag.outputs.tag }}
37+
steps:
38+
- name: Resolve Docker tag
39+
id: resolve-tag
40+
env:
41+
TAG_INPUT: ${{ inputs.tag || 'nightly' }}
42+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
43+
run: |
44+
echo "tag=${DOCKER_USERNAME}/openrouteservice:${TAG_INPUT}" >> $GITHUB_OUTPUT
45+
46+
check_commits:
47+
name: Check for new commits
48+
runs-on: ubuntu-latest
49+
outputs:
50+
new_commits: ${{ steps.check.outputs.new_commits }}
3651
steps:
3752
- name: Checkout
3853
uses: actions/checkout@v4
3954
with:
4055
repository: ${{ inputs.repository || 'GIScience/openrouteservice' }}
4156
ref: ${{ inputs.branch || 'main' }}
4257

43-
- name: Check for new commits since 24 h ago
58+
- name: Check for new commits since 24 hours ago
4459
id: check
4560
run: |
46-
export LOG_LINES=$(git log --oneline --since '24 hours ago')
47-
export NUM_LINES=$(echo "$LOG_LINES" | grep -c .)
61+
LOG_LINES=$(git log --oneline --since '24 hours ago')
62+
NUM_LINES=$(echo "$LOG_LINES" | grep -c .)
4863
if [ "$NUM_LINES" -eq "0" ]; then
49-
export NEW_COMMITS="false"
64+
NEW_COMMITS="false"
5065
else
51-
export NEW_COMMITS="true"
66+
NEW_COMMITS="true"
5267
fi
53-
echo "NEW_COMMITS=$NEW_COMMITS" >> "$GITHUB_OUTPUT"
68+
echo "new_commits=$NEW_COMMITS" >> "$GITHUB_OUTPUT"
5469
55-
build:
56-
needs: check-commits
70+
build_and_push:
71+
name: Build and push nightly image
72+
needs:
73+
- prepare_environment
74+
- check_commits
5775
runs-on: ubuntu-latest
58-
if: inputs.ignore-24h-commit-check || needs.check-commits.outputs.new_commits == 'true'
76+
if: inputs.ignore-24h-commit-check || needs.check_commits.outputs.new_commits == 'true'
5977
steps:
6078
- name: Checkout
6179
uses: actions/checkout@v4
6280
with:
6381
repository: ${{ inputs.repository || 'GIScience/openrouteservice' }}
6482
ref: ${{ inputs.branch || 'main' }}
6583

66-
- name: Set up QEMU
67-
uses: docker/setup-qemu-action@v3.0.0
68-
69-
- name: Set up Docker Buildx
70-
uses: docker/setup-buildx-action@v3.0.0
84+
- name: Set up build environment
85+
uses: ./.github/actions/setup-build-environment
86+
with:
87+
dockerfile: 'Dockerfile'
7188

7289
- name: Login to DockerHub
73-
uses: docker/login-action@v3.0.0
90+
uses: docker/login-action@v3
7491
with:
7592
username: ${{ secrets.DOCKER_USERNAME }}
7693
password: ${{ secrets.DOCKER_PASSWORD }}
7794

78-
- name: Build and push
79-
uses: docker/build-push-action@v5.1.0
95+
- name: Build and push image
96+
uses: docker/build-push-action@v6
8097
with:
8198
context: .
99+
build-args: MAVEN_OPTS=-Dmaven.repo.local=/root/.m2/repository
82100
platforms: linux/amd64,linux/arm64/v8
83101
provenance: false
84102
push: true
85103
cache-from: type=gha
86104
cache-to: type=gha,mode=max
87-
tags: ${{ secrets.DOCKER_USERNAME }}/openrouteservice:${{ inputs.tag || 'nightly' }}
105+
tags: ${{ needs.prepare_environment.outputs.docker_tag }}

.github/workflows/run_maven_tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ jobs:
1717
- uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
20-
- name: Setup Java and Maven
21-
uses: ./.github/actions/setup-java-maven
20+
- name: Setup build environment
21+
uses: ./.github/actions/setup-build-environment
22+
with:
23+
with_docker: 'false'
2224
- name: Cache SonarCloud packages
2325
uses: actions/cache@v4
2426
with:

.github/workflows/vulnerability-scanning.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,10 @@ jobs:
8686
steps:
8787
- name: Checkout repository
8888
uses: actions/checkout@v4
89-
- name: Set up Docker Buildx
90-
uses: docker/setup-buildx-action@v3
91-
id: buildx
92-
- name: Setup Java and Maven
93-
id: setup-java
94-
uses: ./.github/actions/setup-java-maven
95-
- name: inject maven-build-cache into docker
96-
uses: ./.github/actions/maven-cache-dance
89+
- name: Set up build environment
90+
uses: ./.github/actions/setup-build-environment
9791
with:
98-
builder: ${{ steps.buildx.outputs.name }}
9992
dockerfile: 'Dockerfile'
100-
cache-hit: ${{ steps.setup-java.outputs.cache-hit }}
10193
- name: Build image for ${{ matrix.platform }}
10294
uses: docker/build-push-action@v6
10395
with:

0 commit comments

Comments
 (0)