Skip to content

Commit 0ea6e9a

Browse files
authored
Merge pull request #535 from dinogun/alpine_musl_support
Add support for musl based native alpine docker images.
2 parents 958e35c + 0b970d0 commit 0ea6e9a

File tree

6 files changed

+300
-202
lines changed

6 files changed

+300
-202
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ Note: Hotspot is not supported on Ubuntu 20.04 for s390x arch.
2121
- 1809
2222
- ltsc2016
2323

24-
# Official and Unofficial Images
25-
AdoptOpenJDK Docker Images are available as both Official Images (Maintained by Docker) and Unofficial Images (Maintained by AdoptOpenJDK). Please choose based on your requirements.
24+
# musl libc based Alpine Images
25+
26+
Starting from Java 16, hotspot builds are available natively built on musl libc instead of the regular glibc as part of the AdoptOpenJDK project. Currently these are available only for the x86_64 architecture. Accordingly we now have both regular and slim Docker Images for alpine musl based hotspot on x86_64.
27+
28+
# Official and Non-official Images
29+
AdoptOpenJDK Docker Images are available as both Official Images (Maintained by Docker) and Non-official Images (Maintained by AdoptOpenJDK). Please choose based on your requirements.
2630
* [Official Images](https://hub.docker.com/_/adoptopenjdk) are maintained by Docker and updated on every release from AdoptOpenJDK as well as when the underlying OSes are updated. Supported OSes and their versions and type of images are as below.
2731
- Linux
2832
- Ubuntu (20.04): Release

build_latest.sh

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,26 @@ set_runtype "$4"
5353
# Get the image build time stored in the "build_time" array for the current arch
5454
# Build time is stored as the time since 1-1-1970
5555
function get_image_build_time() {
56+
local osfamily=$2
57+
5658
if ! declare -p "$1" &>/dev/null; then
5759
return;
5860
fi
5961

6062
# shellcheck disable=SC2154,SC1083
61-
btime=$(btarray=$1[${current_arch}]; eval btarch=\${"$btarray"}; echo "${btarch}");
63+
btime=$(btarray=$1[${osfamily}_${current_arch}]; eval btarch=\${"$btarray"}; echo "${btarch}");
6264

6365
echo "${btime}"
6466
}
6567

6668
# Check if the adopt image is available, if not need to build it.
6769
function check_adopt_image_available() {
68-
local tag=$1
70+
local image_name=$1
6971

70-
echo "INFO: Checking when the adopt docker image ${tag} was built ..."
71-
if ! docker pull "${tag}" &>/dev/null; then
72+
echo "INFO: Checking when the adopt docker image ${image_name} was built ..."
73+
if ! docker pull "${image_name}" &>/dev/null; then
7274
# Adopt image not available currently, build needed
73-
echo "INFO: AdoptOpenJDK docker image for ${tag} does not exist. Docker build needed"
75+
echo "INFO: AdoptOpenJDK docker image for ${image_name} does not exist. Docker build needed"
7476
build_needed=1
7577
return;
7678
fi
@@ -79,7 +81,7 @@ function check_adopt_image_available() {
7981
# Check if we have a newer base OS docker image
8082
# If a new base OS docker image was built in the last 24 hrs, then we need to rebuild the adopt docker image
8183
function check_new_os_image_available() {
82-
local tag=$2
84+
local image_name=$2
8385

8486
# Get the date when the base image was created. Eg if the base OS is ubuntu, this
8587
# translates as the exact date/time when the Ubuntu image was created on DockerHub
@@ -104,7 +106,7 @@ EOF
104106
)"
105107

106108
# Get the shasums of the current Adopt Image layers
107-
docker inspect "${tag}" > adopt_image.info
109+
docker inspect "${image_name}" > adopt_image.info
108110
adopt_sha_arr="$(python3 <<EOF
109111
import sys, json;
110112
input_file = open ('adopt_image.info');
@@ -118,7 +120,7 @@ EOF
118120
for ssum in ${base_os_sha_arr}
119121
do
120122
if ! echo "${adopt_sha_arr}" | grep -q "${ssum}" ; then
121-
echo "Base OS layer ${ssum} not found in Adopt Image: ${tag}"
123+
echo "Base OS layer ${ssum} not found in Adopt Image: ${image_name}"
122124
# Layer missing in the current Adopt Image, rebuild needed
123125
build_needed=1
124126
break;
@@ -130,10 +132,11 @@ EOF
130132

131133
# Check if we have a newer adopt build tarball
132134
function check_new_adopt_build_available() {
133-
local tag=$1
135+
local osfamily=$1
136+
local image_name=$2
134137

135138
# Get the last build date for the current arch from the "build_time" array
136-
adopt_last_build_date=$(get_image_build_time "${build_time}")
139+
adopt_last_build_date=$(get_image_build_time "${build_time}" "${osfamily}")
137140
if [ -z "${adopt_last_build_date}" ]; then
138141
echo "INFO: Unknown last tarball build time. Docker build needed"
139142
build_needed=1
@@ -143,12 +146,12 @@ function check_new_adopt_build_available() {
143146
adopt_last_build_date=$(( adopt_last_build_date + 86400 ))
144147

145148
# check when the adopt image was last built
146-
adopt_image_creation="$(docker inspect "${tag}" | python3 -c "import sys, json; print(json.load(sys.stdin)[0]['Created'])")"
149+
adopt_image_creation="$(docker inspect "${image_name}" | python3 -c "import sys, json; print(json.load(sys.stdin)[0]['Created'])")"
147150
# Convert this to seconds since 1-1-1970
148151
adopt_image_creation_date="$(date --date="${adopt_image_creation}" +%s)"
149152

150-
echo "INFO: Current docker image for ${tag} build date: $(date --date="@${adopt_image_creation_date}")"
151-
echo "INFO: Current adopt build tarball related to ${tag} build date: $(date --date="@${adopt_last_build_date}")"
153+
echo "INFO: Current docker image for ${image_name} build date: $(date --date="@${adopt_image_creation_date}")"
154+
echo "INFO: Current adopt build tarball related to ${image_name} build date: $(date --date="@${adopt_last_build_date}")"
152155
if [[ ${adopt_image_creation_date} -le ${adopt_last_build_date} ]]; then
153156
# build needed
154157
echo "INFO: Newer adopt build found. Docker build needed"
@@ -164,12 +167,12 @@ function check_new_adopt_build_available() {
164167
# 3. If a new Adopt build is found
165168
# 4. On any other error condition
166169
function check_build_needed() {
167-
local tag=$2
170+
local osfamily=$2
171+
local image_name=$3
168172

173+
echo "Checking build for image_name: ${image_name}"
169174
build_needed=0
170175

171-
adopt_image_tag="${tag// -t /}"
172-
173176
# `runtype` flag specifies if the script is being run for `build` or `test` (PR checks)
174177
# Checking for runtype if its `test` we proceed to build release images, as part of PR checks
175178
if [ "${runtype}" == "test" ]; then
@@ -182,60 +185,56 @@ function check_build_needed() {
182185
# For nightly images, check if a newer adopt nightly build is available.
183186
if [ "${build}" == "nightly" ]; then
184187
# Check if we have a newer adopt build tarball
185-
check_new_adopt_build_available "${adopt_image_tag}"
188+
check_new_adopt_build_available "${osfamily}" "${image_name}"
186189
if [[ ${build_needed} -eq 1 ]]; then
187190
return;
188191
fi
189192
fi
190193

191194
# Check if the adopt image is available, if not need to build it.
192-
check_adopt_image_available "${adopt_image_tag}"
195+
check_adopt_image_available "${image_name}"
193196
if [[ ${build_needed} -eq 1 ]]; then
194197
return;
195198
fi
196199

197200
# Check if we have a newer base OS Image
198-
check_new_os_image_available "$1" "${adopt_image_tag}"
201+
check_new_os_image_available "$1" "${image_name}"
199202
if [[ ${build_needed} -eq 1 ]]; then
200203
return;
201204
fi
202205

203206
# Check if we have a newer adopt build tarball
204-
check_new_adopt_build_available "${adopt_image_tag}"
207+
check_new_adopt_build_available "${osfamily}" "${image_name}"
205208
if [[ ${build_needed} -eq 1 ]]; then
206209
return;
207210
fi
208211

209212
# build not needed
210-
echo "INFO: Docker image for ${adopt_image_tag} exists and is latest. Docker build NOT needed"
213+
echo "INFO: Docker image for ${image_name} exists and is latest. Docker build NOT needed"
211214
}
212215

213-
# Build the Docker image with the given repo, build, build type and tags.
216+
# Build the Docker image with the given repo, build, build type and tag.
214217
function build_image() {
215-
repo=$1; shift;
216-
build=$1; shift;
217-
btype=$1; shift;
218-
219-
local local_tags=("$@") # copy arguments to local array
220-
for i in "${!local_tags[@]}"
221-
do
222-
echo "Tag - ${i} : ${local_tags[$i]}" # Adding an echo to check if jenkins build job is passing multiple tags
223-
tags="${tags} -t ${repo}:${local_tags[$i]}"
224-
done
225-
226-
auto_space_line=" "
227-
image_name="${repo}:${tag}"
228-
printf -v expanded_tags "%s ${repo}:%s " "-t" "${local_tags[@]}" # concatenate to single string : -t repo:tag -t repo:tag2
229-
expanded_tags=${expanded_tags%?} # remove trailing space
230-
dockerfile="Dockerfile.${vm}.${build}.${btype}"
218+
local repo=$1;
219+
local build=$2;
220+
local btype=$3;
221+
local osfamily=$4;
222+
local tag=$5;
223+
224+
local dockerfile="Dockerfile.${vm}.${build}.${btype}"
225+
local image_name="${repo}:${tag}"
226+
check_build_needed "${dockerfile}" "${osfamily}" "${image_name}"
231227
# Check if we need to build this image.
232-
check_build_needed "${dockerfile}" "${tags}"
233228
if [[ ${build_needed} -eq 0 ]]; then
234229
# No build needed, we are done
235230
return;
236231
fi
237232

238-
echo "docker push ${repo}:${tag}" >> "${push_cmdfile}"
233+
auto_space_line=" "
234+
printf -v expanded_tags "%s ${repo}:%s " "-t" "${tag}" # concatenate to single string : -t repo:tag -t repo:tag2
235+
expanded_tags=${expanded_tags%?} # remove trailing space
236+
237+
echo "docker push ${image_name}" >> "${push_cmdfile}"
239238
echo "#####################################################"
240239
echo "INFO: docker build --no-cache ${expanded_tags} -f ${dockerfile} ."
241240
echo "#####################################################"
@@ -264,11 +263,8 @@ function build_image() {
264263
echo "#####################################################"
265264
echo " Scanning with snyk for vulnerabilities "
266265
echo "#####################################################"
267-
for i in "${!tags[@]}"
268-
do
269-
echo "...scanning ${repo}:${tags[$i]}"
270-
snyk test --docker "${repo}:${tags[$i]}" --file="${dockerfile}"
271-
done
266+
echo "...scanning ${image_name}"
267+
snyk test --docker "${image_name}" --file="${dockerfile}"
272268
fi
273269
echo "| ${image_name:0:80}${auto_space_line:0:$((76 - ${#image_name}))} | success |" >> ${summary_table_file}
274270
echo "+------------------------------------------------------------------------------+----------+" >> ${summary_table_file}
@@ -295,11 +291,8 @@ function build_image() {
295291
echo "#####################################################"
296292
echo " Scanning with snyk for vulnerabilities "
297293
echo "#####################################################"
298-
for i in "${!tags[@]}"
299-
do
300-
echo "...scanning ${repo}:${tags[$i]}"
301-
snyk test --docker "${repo}:${tags[$i]}" --file="${dockerfile}"
302-
done
294+
echo "...scanning ${image_name}"
295+
snyk test --docker "${image_name}" --file="${dockerfile}"
303296
fi
304297
echo "| ${image_name:0:80}${auto_space_line:0:$((76 - ${#image_name}))} | success |" >> ${summary_table_file}
305298
echo "+------------------------------------------------------------------------------+----------+" >> ${summary_table_file}
@@ -309,15 +302,23 @@ function build_image() {
309302

310303
# Build the docker image for a given VM, OS, BUILD and BUILD_TYPE combination.
311304
function build_dockerfile {
312-
vm=$1; pkg=$2; os=$3; build=$4; btype=$5;
313-
305+
local vm=$1;
306+
local pkg=$2;
307+
local build=$3;
308+
local btype=$4;
309+
local osfamily=$5;
310+
local os=$6;
311+
312+
local tag=""
313+
echo "INFO: current_arch: ${current_arch}, osfamily: ${osfamily}, os: ${os}"
314314
if [ -z "${current_arch}" ]; then
315315
jverinfo="${shasums}[version]"
316316
else
317-
jverinfo="${shasums}[version-${current_arch}]"
317+
jverinfo="${shasums}[version-${osfamily}_${current_arch}]"
318318
fi
319319
# shellcheck disable=SC1083,SC2086
320320
eval jrel=\${$jverinfo}
321+
echo "INFO: release: ${jrel}"
321322
# Docker image tags cannot have "+" in them, replace it with "_" instead.
322323
# shellcheck disable=SC2154
323324
rel=${jrel//+/_}
@@ -354,7 +355,7 @@ function build_dockerfile {
354355
fi
355356
echo "INFO: Building ${trepo} ${tag} from $file ..."
356357
pushd "${dir}" >/dev/null || return
357-
build_image "${trepo}" "${build}" "${btype}" "${tag}"
358+
build_image "${trepo}" "${build}" "${btype}" "${osfamily}" "${tag}"
358359
popd >/dev/null || return
359360
}
360361

@@ -386,6 +387,7 @@ do
386387
# Type = Full or Slim
387388
btypes=$(parse_vm_entry "${vm}" "${version}" "${package}" "${os}" "Type:")
388389
dir=$(parse_vm_entry "${vm}" "${version}" "${package}" "${os}" "Directory:")
390+
osfamily=$(parse_vm_entry "${vm}" "${version}" "${package}" "${os}" "OS_Family:")
389391

390392
for build in ${builds}
391393
do
@@ -411,12 +413,12 @@ do
411413
for btype in ${btypes}
412414
do
413415
file="${dir}/Dockerfile.${vm}.${build}.${btype}"
414-
generate_dockerfile "${file}" "${package}" "${build}" "${btype}" "${os}"
416+
generate_dockerfile "${file}" "${package}" "${build}" "${btype}" "${osfamily}" "${os}"
415417
if [ ! -f "${file}" ]; then
416418
continue;
417419
fi
418420
# Build the docker images for valid Dockerfiles
419-
build_dockerfile "${vm}" "${package}" "${os}" "${build}" "${btype}"
421+
build_dockerfile "${vm}" "${package}" "${build}" "${btype}" "${osfamily}" "${os}"
420422
done
421423
done
422424
done

0 commit comments

Comments
 (0)