Skip to content

Commit 675d6d7

Browse files
committed
#369 Use Git SHA as unique Docker tag
Building a multi-platform Docker image only works in cooperation with a remote registry, which implies a push. The image is not directly available in the local image store. A pull is necessary to make it locally available. For the GitHub Action test it was necessary to use the Git SHA as unique identifier for the system to be tested (its testing the Docker image which is used as GitHub action). Other identifiers provided no clear distinction as there could be other/older images with the same tag in the remote registry.
1 parent 89d686c commit 675d6d7

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

.github/workflows/build-artifacts.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
required: true
77
type: string
88
default: '17'
9+
push-docker-sha:
10+
required: false
11+
type: boolean
12+
default: false
913
run-sonar:
1014
required: false
1115
type: boolean
@@ -21,6 +25,9 @@ env:
2125

2226
jobs:
2327
build:
28+
env:
29+
DOCKER_USERNAME: ${{ github.repository_owner }}
30+
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
2431
runs-on: ubuntu-latest
2532
steps:
2633
- name: Check out
@@ -57,6 +64,14 @@ jobs:
5764
- name: Execute Gradle build
5865
run: ./gradlew clean check integrationTest build --scan --stacktrace
5966

67+
- name: Push Docker with Git SHA as tag for subsequent tests
68+
if: ${{ inputs.push-docker-sha }}
69+
run: |
70+
./gradlew dockerPush -Ddocker.image.additional.tags=${{ github.sha }}
71+
docker pull "ghcr.io/aim42/hsc:${{ github.sha }}"
72+
echo "Docker Images:"
73+
docker images
74+
6075
- name: Cache SonarCloud packages
6176
uses: actions/cache@v4
6277
if: ${{ inputs.run-sonar }}
@@ -82,6 +97,8 @@ jobs:
8297
- name: Collect state upon failure
8398
if: failure()
8499
run: |
100+
echo "Docker Images:"
101+
docker images
85102
echo "Git:"
86103
git status
87104
echo "Env:"

.github/workflows/gradle-build.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ on:
1515

1616
jobs:
1717
build-artifacts:
18+
permissions:
19+
packages: write
20+
contents: read
1821
uses: ./.github/workflows/build-artifacts.yml
1922
with:
2023
# SonarQube requires JDK 17 or higher
2124
java-version: '17'
2225
run-sonar: ${{ github.repository == 'aim42/htmlSanityCheck' }}
26+
push-docker-sha: true
2327
secrets:
2428
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
2529

@@ -33,9 +37,11 @@ jobs:
3337

3438
- name: Prepare Docker image for test
3539
run: |
36-
tag=$(git branch --show-current | tr '/' '-')
37-
docker pull ghcr.io/aim42/hsc:${tag}
38-
docker tag ghcr.io/aim42/hsc:${tag} ghcr.io/aim42/hsc:v2
40+
tag="${{ github.sha }}"
41+
docker pull "ghcr.io/aim42/hsc:${tag}"
42+
echo "Docker Images:"
43+
docker images
44+
docker tag "ghcr.io/aim42/hsc:${tag}" ghcr.io/aim42/hsc:v2
3945
4046
- name: Download Artifacts
4147
uses: actions/download-artifact@v5
@@ -65,6 +71,8 @@ jobs:
6571
- name: Collect state upon failure
6672
if: failure()
6773
run: |
74+
echo "Docker Images:"
75+
docker images
6876
echo "Git:"
6977
git status
7078
echo "Env:"
@@ -162,6 +170,8 @@ jobs:
162170
- name: Collect state upon failure
163171
if: failure()
164172
run: |
173+
echo "Docker Images:"
174+
docker images
165175
echo "Maven Repo:"
166176
(cd $HOME && find .m2 -ls)
167177
echo "Git:"
@@ -172,4 +182,4 @@ jobs:
172182
pwd
173183
echo "Files:"
174184
find * -ls
175-
./gradlew javaToolchains
185+
./gradlew javaToolchains

htmlSanityCheck-cli/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ docker {
6262
}
6363

6464
tasks.register('dockerBuildLocal', com.fussionlabs.gradle.docker.tasks.DockerBuildx) {
65+
def tag = "${'git branch --show-current'.execute().text.trim().replaceAll('/', '-')}"
66+
logger.quiet("Using tag '${tag}' for dockerBuildLocal")
6567
loadImage = true
6668
pushImage = false
6769

0 commit comments

Comments
 (0)