Publishing multi-architecture Spring Boot images from CI
Gate native amd64 and arm64 Buildpacks images on GitHub Actions tests, generate coverage, and publish one OCI index from both builds.
I put tests, SonarCloud analysis, and container publishing into one GitHub Actions workflow. The test result gates both native Buildpacks builds, and deployment sees a new multi-architecture image only after the two builds finish.
The workflow uses Spring Boot 3.5, Kotlin 1.9, Temurin Java 21, and GitHub Actions runners ubuntu-24.04 and ubuntu-24.04-arm.
Gating the release on the test job
I used one workflow to avoid running the tests twice when a change lands in main and to bind publication to the result for the same revision. Branch pushes and pull requests exercise the project. A push to main can also publish the container after the test job succeeds.
flowchart TD
A["Push or PR"] --> B["test (Lint, Test, SonarCloud)"]
B -->|"Main passes"| C["build-image (amd64)"]
B -->|"Main passes"| D["build-image (arm64)"]
C --> E["Publish OCI index"]
D --> E
The build declares needs: test and has a condition for the main-branch push. The manifest job waits for both architectures. Each run uses a concurrency group so a subsequent push can cancel stale work. I set explicit permissions for reading the checkout and for the checks and reports that the workflow writes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# .github/workflows/ci-cd.yaml (triggers and concurrency)
name: CI/CD Pipeline
on:
push:
branches:
- '**'
pull_request:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
issues: read
checks: write
pull-requests: write
Fork pull requests run with different permissions and normally have no access to repository secrets. Keep verification steps useful in that environment even when a coverage upload or registry login is unavailable.
Running tests against Redis and reporting coverage
The test job starts redis:8-alpine as a GitHub Actions service and waits for its health check. It runs ktlintCheck for formatting, then test jacocoTestReport for the application tests and coverage XML. The job also extracts VERSION and SHORT_SHA once and exposes them as outputs so the publish job labels the same revision.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# .github/workflows/ci-cd.yaml (test job)
jobs:
test:
name: Lint, Test & SonarCloud
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.project-version.outputs.version }}
short_sha: ${{ steps.project-version.outputs.short_sha }}
services:
redis:
image: redis:8-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: gradle/actions/wrapper-validation@v6
- name: Set up JDK 21
uses: actions/setup-java@v6
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v6
- name: Extract project version and short SHA
id: project-version
run: |
VERSION=$(./gradlew properties -q | grep '^version:' | awk '{print $2}')
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
- name: Check Lint
run: ./gradlew ktlintCheck
- name: Run Tests & JaCoCo Report
run: ./gradlew -Dspring.profiles.active=test test jacocoTestReport
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: ${{ always() }}
with:
files: build/test-results/**/*.xml
- name: Report to SonarCloud
run: |
if [ -n "$SONAR_TOKEN" ]; then
./gradlew sonar
else
echo "SONAR_TOKEN is not set; skipping SonarCloud analysis."
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
The test report has an always() condition to make failures visible in GitHub Checks. The SonarCloud step checks for a configured SONAR_TOKEN so an ordinary fork PR can still run the tests without that credential. The Gradle configuration points the scanner at the JaCoCo XML and the relevant test and production output directories.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// build.gradle.kts (JaCoCo and SonarCloud configuration)
tasks.withType<JacocoReport> {
reports {
xml.required.set(true)
html.required.set(true)
}
}
sonar {
properties {
property("sonar.projectKey", "cmsong111_Wanted-PreOnBoarding-Backend-Challenge")
property("sonar.organization", "cmsong111")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.language", "kotlin")
property("sonar.sources", "src/main/kotlin")
property("sonar.tests", "src/test/kotlin")
property("sonar.java.binaries", "build/classes/kotlin/main")
property("sonar.java.test.binaries", "build/classes/kotlin/test")
property("sonar.junit.reportPaths", "build/test-results/test")
property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco/test/jacocoTestReport.xml")
property(
"sonar.exclusions",
"**/presentation/request/**, **/presentation/response/**, **/config/**",
)
}
}
Building both architectures natively
bootBuildImage packages the Spring Boot application with Cloud Native Buildpacks. Builders provide runtime layers and JVM memory configuration, so the project does not need to maintain a Dockerfile for those choices. Rebuild with an updated builder and run image to pick up their fixes.
The task defaults to a fixed timestamp for reproducibility. I set createdDate = "now" so the image metadata shows when the workflow built it. That choice means repeated builds can produce different metadata even when their inputs otherwise match. Spring Boot Buildpacks options
1
2
3
4
5
6
// build.gradle.kts (BootBuildImage configuration)
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
tasks.withType<BootBuildImage>().configureEach {
createdDate = "now"
}
| Approach | Build execution | Operational cost |
|---|---|---|
| QEMU emulation | One host emulates the other architecture | A simpler runner setup, with extra time and potential builder compatibility issues |
| Native architecture matrix | Each buildpack runs on a matching runner | Two build jobs and a separate index publication job |
The matrix uses ubuntu-24.04 for amd64 and ubuntu-24.04-arm for arm64. Each job pushes a fixed intermediate tag, build-amd64 or build-arm64, to avoid accumulating per-commit staging tags. The manifest job combines the two platform images with docker buildx imagetools create. It publishes the result under latest, the application version, and the short commit SHA.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# .github/workflows/ci-cd.yaml (multi-architecture build and index publishing)
build-image:
name: Build & Push Image (${{ matrix.arch }})
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
runner: ubuntu-24.04
- arch: arm64
runner: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: gradle/actions/wrapper-validation@v6
- name: Set up JDK 21
uses: actions/setup-java@v6
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v6
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & Push Boot Image (${{ matrix.arch }})
env:
IMAGE_TAG: cmsong111/portfolio-server:build-${{ matrix.arch }}
run: |
./gradlew bootBuildImage --imageName="$IMAGE_TAG"
docker push "$IMAGE_TAG"
publish-manifest:
name: Publish Multi-Arch Manifest
needs: [test, build-image]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
steps:
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create & Push Multi-Arch Manifest
env:
VERSION: ${{ needs.test.outputs.version }}
SHORT_SHA: ${{ needs.test.outputs.short_sha }}
run: |
docker buildx imagetools create \
-t "cmsong111/portfolio-server:latest" \
-t "cmsong111/portfolio-server:${VERSION}" \
-t "cmsong111/portfolio-server:${SHORT_SHA}" \
"cmsong111/portfolio-server:build-amd64" \
"cmsong111/portfolio-server:build-arm64"
The fixed intermediate tags are mutable. If another workflow can push to the same tags concurrently, the assembled index can mix revisions. Serialize publication for the repository or pass immutable digest references from the architecture jobs when you need that guarantee. Docker buildx imagetools create
Diagnosing SonarCloud and credential failures
A shallow checkout hides the history SonarCloud uses for blame and new-code calculations. I use fetch-depth: 0 where the scanner runs. Enabling both SonarCloud Automatic Analysis and the CI scanner produces a different failure.
1
2
ERROR: You are running CI analysis while Automatic Analysis is enabled.
Please consider disabling one or the other.
To use JaCoCo XML from this workflow, switch the project to CI-based analysis in SonarCloud’s analysis settings. An enabled Automatic Analysis configuration conflicts with the CI scan.
| Storage | Name | Purpose |
|---|---|---|
| GitHub Actions variable | DOCKERHUB_USERNAME | Login account |
| GitHub Actions secret | DOCKERHUB_TOKEN | Registry access token |
| GitHub Actions secret | SONAR_TOKEN | SonarCloud authentication |
A deployment that watches latest sees a new multi-platform index after the manifest job publishes it. Each architecture pulls its own matching image. Keep a versioned or commit-tagged reference available for a rollback.
Checking the pipeline before deployment
- Confirm a failing test blocks the matrix and the publish job.
- Check that a fork PR can run unprivileged validation without registry or scanning credentials.
- Inspect the index and confirm it lists both platforms for the expected revision.
- Confirm the platform-specific images are usable before setting deployment to track
latest.
