@@ -19,30 +19,32 @@ readonly VARIANTS=(
1919 graalvm21
2020)
2121
22- # Get a TAG_PREFIX for every built image. Resulting images will be tagged as
23- # ${TAG_PREFIX}${variant}, where ${variant} is base, latest or a JVM name.
24- # ${TAG_PREFIX} is empty for the master branch, and it is a sanitized version
25- # of the git branch otherwise. Sanitization is a conversion to lowercase, and
26- # replacing all slashes with underscores, which is the same sanitization Docker
27- # Hub does for their own builds.
28- GIT_BRANCH=" ${GITHUB_REF_NAME:- $(git branch --show-current)} "
29- # Fallback to local if there is no branch (e.g. dettached development)
30- readonly GIT_BRANCH=" ${GIT_BRANCH:- local} "
31- if [[ ${GIT_BRANCH} = master ]]; then
32- TAG_PREFIX=" "
33- else
34- TAG_PREFIX=" ${GIT_BRANCH} -"
35- TAG_PREFIX=" ${TAG_PREFIX,,} "
36- TAG_PREFIX=" ${TAG_PREFIX// \/ / _} "
37- fi
38-
39- # Cache the same RFC 3339 timestamp for re-use in all images built in the same batch.
40- BUILD_DATE=" $( date -u +" %Y-%m-%dT%H:%M:%SZ" ) "
41- GIT_HEAD_REF=" $( git show-ref --head --hash ^HEAD) "
42-
4322# Use buildkit to match CI as closely as possible.
4423export DOCKER_BUILDKIT=1
4524
25+ function compute_metadata() {
26+ # Get a TAG_PREFIX for every built image. Resulting images will be tagged as
27+ # ${TAG_PREFIX}${variant}, where ${variant} is base, latest or a JVM name.
28+ # ${TAG_PREFIX} is empty for the master branch, and it is a sanitized version
29+ # of the git branch otherwise. Sanitization is a conversion to lowercase, and
30+ # replacing all slashes with underscores, which is the same sanitization Docker
31+ # Hub does for their own builds.
32+ GIT_BRANCH=" ${GITHUB_REF_NAME:- $(git branch --show-current)} "
33+ # Fallback to local if there is no branch (e.g. dettached development)
34+ readonly GIT_BRANCH=" ${GIT_BRANCH:- local} "
35+ if [[ ${GIT_BRANCH} = master ]]; then
36+ TAG_PREFIX=" "
37+ else
38+ TAG_PREFIX=" ${GIT_BRANCH} -"
39+ TAG_PREFIX=" ${TAG_PREFIX,,} "
40+ TAG_PREFIX=" ${TAG_PREFIX// \/ / _} "
41+ fi
42+
43+ # Cache the same RFC 3339 timestamp for re-use in all images built in the same batch.
44+ BUILD_DATE=" $( date -u +" %Y-%m-%dT%H:%M:%SZ" ) "
45+ GIT_HEAD_REF=" $( git show-ref --head --hash ^HEAD) "
46+ }
47+
4648# docker build wrapper with common arguments
4749# See https://github.com/opencontainers/image-spec/blob/main/annotations.md for common labels
4850# See https://docs.github.com/en/packages/learn-github-packages/connecting-a-repository-to-a-package
@@ -68,6 +70,7 @@ function image_name() {
6870}
6971
7072function do_build() {
73+ compute_metadata
7174 docker_build base " $( image_name base) "
7275 docker_build full " $( image_name latest) "
7376 if [ -n " ${GITHUB_OUTPUT+unset} " ]; then
@@ -111,6 +114,7 @@ function shares_layers() {
111114
112115function do_test() {
113116 local image_base image_variant
117+ compute_metadata
114118 image_base=" $( image_name base) "
115119 mapfile -t base_layers < <( list_layers " ${image_base} " )
116120 for variant in " ${BASE_VARIANTS[@]} " " ${VARIANTS[@]} " ; do
@@ -132,7 +136,13 @@ function do_test() {
132136 for variant in base latest " ${BASE_VARIANTS[@]} " " ${VARIANTS[@]} " ; do
133137 image_variant=" $( image_name " ${variant} " ) "
134138 echo " Running smoke tests for ${image_variant} ..."
135- docker run -u " $( id -u) :$( id -g) " -w /work -v " $( pwd) :/work" --rm " ${image_variant} " /work/build --inner-test " ${variant} "
139+ docker run \
140+ --user " $( id -u) :$( id -g) " \
141+ --workdir /work \
142+ --volume " $( pwd) :/work" \
143+ --rm \
144+ " ${image_variant} " \
145+ /work/build --inner-test " ${variant} "
136146 done
137147}
138148
@@ -156,11 +166,12 @@ function do_inner_test() {
156166
157167function do_describe() {
158168 local image
169+ compute_metadata
159170 image=" $( image_name latest) "
160171 docker run \
161- -u " $( id -u) :$( id -g) " \
162- -w /work \
163- -v " $( pwd) :/work" \
172+ --user " $( id -u) :$( id -g) " \
173+ --workdir /work \
174+ --volume " $( pwd) :/work" \
164175 --rm \
165176 " $image " \
166177 /work/build --inner-describe
@@ -198,6 +209,7 @@ function do_inner_describe() {
198209
199210function do_push() {
200211 local tag
212+ compute_metadata
201213 for tag in base latest " ${BASE_VARIANTS[@]} " " ${VARIANTS[@]} " ; do
202214 tag=" ${tag,,} "
203215 tag=" $( image_name " ${tag} " ) "
0 commit comments