Skip to content

Commit c72bd03

Browse files
committed
Update the "Official Images Updates" workflow
* Utilize a Dockerfile that can be used locally as well * Display the diff to the current upstream version (in the build) Signed-off-by: Christoph Obexer <[email protected]>
1 parent 7fa7549 commit c72bd03

File tree

4 files changed

+83
-16
lines changed

4 files changed

+83
-16
lines changed

.github/workflows/official-images.yml

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,43 @@ jobs:
1717
runs-on: ubuntu-latest
1818
permissions:
1919
contents: read
20+
pull-requests: write
2021
steps:
2122
- name: Checkout
2223
uses: actions/checkout@v5
2324
with:
2425
fetch-depth: 0 # we need all branches so we can read Dockerfiles from them
25-
- name: Provision best available generate-stackbrew-library.sh
26+
- name: Provision best available generate-stackbrew-library.sh and toolbox
2627
env:
2728
EVENT_NAME: ${{ github.event_name }}
2829
CURRENT_COMMIT: ${{ github.sha }}
2930
BASE_REF: ${{ github.event.pull_request.base.ref }}
30-
# if the script was modified in the current PR, use that version; otherwise, use the version from master
3131
shell: bash
3232
run: |
33+
# if the generate-stackbrew-library.sh was modified in the current PR, use that version; otherwise, use the version from master
3334
if [ "${EVENT_NAME}" == "pull_request" ] && [ "$(git diff --name-only "origin/$BASE_REF..$CURRENT_COMMIT" -- 'generate-stackbrew-library.sh' | wc -l)" -gt 0 ]; then
3435
echo "Using modified generate-stackbrew-library.sh"
3536
else
3637
echo "Using generate-stackbrew-library.sh from master branch"
3738
git checkout origin/master -- generate-stackbrew-library.sh
3839
fi
40+
# if the toolbox Dockerfile was modified in the current PR, use that version; otherwise, use the version from master
41+
if [ "${EVENT_NAME}" == "pull_request" ] && [ "$(git diff --name-only "origin/$BASE_REF..$CURRENT_COMMIT" -- 'toolbox/Dockerfile' | wc -l)" -gt 0 ]; then
42+
echo "Using modified toolbox/Dockerfile"
43+
else
44+
echo "Using toolbox/Dockerfile from master branch"
45+
git checkout origin/master -- toolbox/Dockerfile
46+
fi
47+
- run: docker build --tag gradle-dockerhub-toolbox -f toolbox/Dockerfile toolbox
3948
- name: Generate library file
40-
uses: docker://bash:latest
41-
with:
42-
# See https://github.com/docker-library/bashbrew?tab=readme-ov-file#installing
43-
args: |
44-
-c "\
45-
apk add --no-cache jq git curl ca-certificates && \
46-
git config --global --add safe.directory '*' && \
47-
curl -fsSL -o /usr/local/bin/bashbrew https://github.com/docker-library/bashbrew/releases/download/v0.1.13/bashbrew-amd64 && \
48-
chmod +x /usr/local/bin/bashbrew && \
49-
bashbrew --version && \
50-
./generate-stackbrew-library.sh ${BASE_SHA:+--substitute ${BASE_SHA} ${CURRENT_COMMIT}} > library-gradle \
51-
"
49+
run: |
50+
docker run --rm \
51+
-v "$PWD:/ws" \
52+
-w /ws \
53+
-e CURRENT_COMMIT \
54+
-e BASE_SHA \
55+
gradle-dockerhub-toolbox \
56+
bash -c 'if [ -n "$BASE_SHA" ]; then ./generate-stackbrew-library.sh --substitute "$BASE_SHA" "$CURRENT_COMMIT"; else ./generate-stackbrew-library.sh; fi > library-gradle'
5257
env:
5358
CURRENT_COMMIT: ${{ github.sha }}
5459
BASE_SHA: ${{ github.event.pull_request.base.sha }}
@@ -57,3 +62,35 @@ jobs:
5762
with:
5863
name: gradle
5964
path: library-gradle
65+
- name: Compare library files
66+
id: compare
67+
run: |
68+
curl -q -sS -o /dev/stdout "https://raw.githubusercontent.com/docker-library/official-images/refs/heads/master/library/gradle" | \
69+
sed -E "s/GitCommit: .*/GitCommit: 0000000000000000000000000000000000000000/" > existing-library-gradle
70+
sed -E "1d; s/GitCommit: .*/GitCommit: 0000000000000000000000000000000000000000/" library-gradle > updated-library-gradle
71+
DIFF_OUTPUT=$(diff existing-library-gradle updated-library-gradle || :)
72+
echo "$DIFF_OUTPUT"
73+
echo "diff<<EOF" >> $GITHUB_OUTPUT
74+
echo "$DIFF_OUTPUT" >> $GITHUB_OUTPUT
75+
echo "EOF" >> $GITHUB_OUTPUT
76+
- name: Comment PR with diff
77+
if: github.event_name == 'pull_request' && steps.compare.outputs.diff != ''
78+
uses: actions/github-script@v7
79+
with:
80+
script: |
81+
const diff = `${{ steps.compare.outputs.diff }}`;
82+
const body = `<details>
83+
<summary>Library file diff (ignoring commit IDs)</summary>
84+
85+
\`\`\`diff
86+
${diff}
87+
\`\`\`
88+
89+
</details>`;
90+
91+
github.rest.issues.createComment({
92+
issue_number: context.issue.number,
93+
owner: context.repo.owner,
94+
repo: context.repo.repo,
95+
body: body
96+
});

generate-stackbrew-library.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ for branch in "${branches[@]}"; do
7676
# convert "git ls-tree" output to a list of directories that contain a Dockerfile
7777
[
7878
inputs
79-
| select(endswith("/Dockerfile"))
79+
# filter to only Dockerfiles, excluding the toolbox/ and hidden directories
80+
| select(endswith("/Dockerfile") and ((startswith("toolbox/") or startswith(".")) | not))
8081
| rtrimstr("/Dockerfile")
8182
]
8283
| sort_by(
@@ -219,7 +220,7 @@ for branch in "${branches[@]}"; do
219220
ubi)
220221
tags+=(
221222
'ubi'
222-
"${versions[@]/%/-$jdk-$suite}" # "X.Y.Z-ubi10"
223+
"${versions[@]/%/-$jdk-$suite}" # "X.Y.Z-jdkNN-ubi10"
223224
"$suite" # "ubi10"
224225
)
225226
;;

toolbox.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
if ! build_output=$(docker build --pull --tag gradle-dockerhub-toolbox -f toolbox/Dockerfile toolbox 2>&1); then
4+
echo "$build_output" >&2
5+
echo "Failed to build gradle-dockerhub-toolbox image" >&2
6+
exit 1
7+
fi
8+
9+
exec docker run --rm -ti \
10+
-v "$(pwd):/workspace" \
11+
-w /workspace \
12+
gradle-dockerhub-toolbox \
13+
bash "$@"

toolbox/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM bash:latest
2+
3+
WORKDIR /ws
4+
5+
# See https://github.com/docker-library/bashbrew?tab=readme-ov-file#installing
6+
RUN apk add --no-cache \
7+
ca-certificates \
8+
curl \
9+
git \
10+
jq \
11+
&& git config --global --add safe.directory '*'
12+
13+
ARG BASHBREW_VERSION=0.1.13
14+
RUN curl -fsSL -o /usr/local/bin/bashbrew "https://github.com/docker-library/bashbrew/releases/download/v${BASHBREW_VERSION}/bashbrew-amd64" && \
15+
chmod +x /usr/local/bin/bashbrew && \
16+
bashbrew --version

0 commit comments

Comments
 (0)