-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_all_images.sh
executable file
·349 lines (260 loc) · 9.87 KB
/
build_all_images.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/bin/bash
source ./_common.sh
BUILD_ALL_IMAGES_PUSH=${1}
function build_base_image {
log_in_to_docker_hub
if [[ $(get_latest_docker_hub_version "base") == $(./release_notes.sh get-version) ]] && [[ "${LIFERAY_DOCKER_DEVELOPER_MODE}" != "true" ]]
then
echo ""
echo "Docker image base is up to date."
return
fi
echo ""
echo "Building Docker image base."
echo ""
LIFERAY_DOCKER_IMAGE_PLATFORMS="${LIFERAY_DOCKER_IMAGE_PLATFORMS}" time ./build_base_image.sh "${BUILD_ALL_IMAGES_PUSH}" | tee -a "${LOGS_DIR}"/base.log
if [ "${PIPESTATUS[0]}" -gt 0 ]
then
echo "FAILED: Base" >> "${LOGS_DIR}/results"
exit 1
else
echo "SUCCESS: Base" >> "${LOGS_DIR}/results"
fi
}
function build_bundle_image {
local query=${1}
local version=${2}
local additional_tags=$(get_string $( yq "${query}".additional_tags < bundles.yml))
local bundle_url=$(get_string $(yq "${query}".bundle_url < bundles.yml))
local fix_pack_url=$(get_string $(yq "${query}".fix_pack_url < bundles.yml))
local latest=$(get_string $(yq "${query}".latest < bundles.yml))
local test_hotfix_url=$(get_string $(yq "${query}".test_hotfix_url < bundles.yml))
local test_installed_patch=$(get_string $( yq "${query}".test_installed_patch < bundles.yml))
if [ -n "${additional_tags}" ]
then
version="${version},${additional_tags}"
fi
if [ ! -n "${version}" ]
then
local build_id=${bundle_url##*/}
else
local build_id=${version}
fi
echo ""
echo "Building Docker image ${build_id} based on ${bundle_url}."
echo ""
LIFERAY_DOCKER_FIX_PACK_URL=${fix_pack_url} LIFERAY_DOCKER_IMAGE_PLATFORMS="${LIFERAY_DOCKER_IMAGE_PLATFORMS}" LIFERAY_DOCKER_LATEST=${latest} LIFERAY_DOCKER_RELEASE_FILE_URL=${bundle_url} LIFERAY_DOCKER_RELEASE_VERSION=${version} LIFERAY_DOCKER_TEST_HOTFIX_URL=${test_hotfix_url} LIFERAY_DOCKER_TEST_INSTALLED_PATCHES=${test_installed_patch} time ./build_bundle_image.sh "${BUILD_ALL_IMAGES_PUSH}" 2>&1 | tee "${LOGS_DIR}/${build_id}.log"
local build_bundle_image_exit_code=${PIPESTATUS[0]}
if [ "${build_bundle_image_exit_code}" -gt 0 ]
then
echo "FAILED: ${build_id}" >> "${LOGS_DIR}/results"
if [ "${build_bundle_image_exit_code}" -eq 4 ]
then
echo "Detected a license failure while building image ${build_id}." > "${LOGS_DIR}/license-failure"
echo "There is an existing license failure."
exit 4
fi
else
echo "SUCCESS: ${build_id}" >> "${LOGS_DIR}/results"
fi
}
function build_bundle_images {
#
# LIFERAY_DOCKER_IMAGE_FILTER="7.2.10-dxp-1 " ./build_all_images.sh
# LIFERAY_DOCKER_IMAGE_FILTER=7.2.10 ./build_all_images.sh
#
local main_keys=$(yq '' < bundles.yml | grep -v ' .*' | sed 's/://')
local specified_version=${LIFERAY_DOCKER_IMAGE_FILTER}
if [ -z "${LIFERAY_DOCKER_IMAGE_FILTER}" ]
then
specified_version="*"
fi
local search_output=$(yq .\""${specified_version}"\" < bundles.yml)
if [[ "${search_output}" != "null" ]]
then
local versions=$(echo "${search_output}" | grep '^.*:$' | sed 's/://')
for version in ${versions}
do
local query=.\"$(get_main_key "${main_keys}" "${version}")\".\"${version}\"
build_bundle_image "${query}" "${version}"
done
else
local main_key=$(get_main_key "${main_keys}" "${specified_version}")
if [[ "${main_key}" = "null" ]]
then
echo "No bundles were found."
exit 1
else
local query=.\"${main_key}\".\"${specified_version}\"
if [[ "$(yq "${query}" < bundles.yml)" != "null" ]]
then
build_bundle_image "${query}" "${specified_version}"
else
echo "No bundles were found."
exit 1
fi
fi
fi
}
function build_jdk11_image {
local jdk11_image_version=1.0
local latest_available_zulu11_amd64_version=$(get_latest_available_zulu_version "11" "amd64")
local latest_available_zulu11_arm64_version=$(get_latest_available_zulu_version "11" "arm64")
if [[ $(get_latest_docker_hub_zulu_version "jdk11" "11" "amd64") == "${latest_available_zulu11_amd64_version}" ]] && [[ $(get_latest_docker_hub_zulu_version "jdk11" "11" "arm64") == "${latest_available_zulu11_arm64_version}" ]] && [[ "${LIFERAY_DOCKER_DEVELOPER_MODE}" != "true" ]]
then
echo ""
echo "Docker image JDK 11 is up to date."
return
fi
echo ""
echo "Building Docker image JDK 11."
echo ""
LIFERAY_DOCKER_IMAGE_PLATFORMS="${LIFERAY_DOCKER_IMAGE_PLATFORMS}" LIFERAY_DOCKER_ZULU_11_AMD64_VERSION=${latest_available_zulu11_amd64_version} LIFERAY_DOCKER_ZULU_11_ARM64_VERSION=${latest_available_zulu11_arm64_version} time ./build_jdk11_image.sh "${BUILD_ALL_IMAGES_PUSH}" | tee -a "${LOGS_DIR}"/jdk11.log
if [ "${PIPESTATUS[0]}" -gt 0 ]
then
echo "FAILED: JDK 11" >> "${LOGS_DIR}/results"
exit 1
else
echo "SUCCESS: JDK 11" >> "${LOGS_DIR}/results"
fi
}
function build_jdk11_jdk8_image {
local jdk11_jdk8_image_version=1.0
local latest_available_zulu8_amd64_version=$(get_latest_available_zulu_version "8" "amd64")
local latest_available_zulu8_arm64_version=$(get_latest_available_zulu_version "8" "arm64")
if [[ $(get_latest_docker_hub_zulu_version "jdk11-jdk8" "8" "amd64") == "${latest_available_zulu8_amd64_version}" ]] && [[ $(get_latest_docker_hub_zulu_version "jdk11-jdk8" "8" "arm64") == "${latest_available_zulu8_arm64_version}" ]] && [[ "${LIFERAY_DOCKER_DEVELOPER_MODE}" != "true" ]]
then
echo ""
echo "Docker image JDK 8 is up to date."
return
fi
echo ""
echo "Building Docker image JDK 11/JDK 8."
echo ""
LIFERAY_DOCKER_IMAGE_PLATFORMS="${LIFERAY_DOCKER_IMAGE_PLATFORMS}" LIFERAY_DOCKER_ZULU_8_AMD64_VERSION=${latest_available_zulu8_amd64_version} LIFERAY_DOCKER_ZULU_8_ARM64_VERSION=${latest_available_zulu8_arm64_version} time ./build_jdk11_jdk8_image.sh "${BUILD_ALL_IMAGES_PUSH}" | tee -a "${LOGS_DIR}"/jdk11_jdk8.log
if [ "${PIPESTATUS[0]}" -gt 0 ]
then
echo "FAILED: JDK 11/JDK 8" >> "${LOGS_DIR}/results"
exit 1
else
echo "SUCCESS: JDK 11/JDK 8" >> "${LOGS_DIR}/results"
fi
}
function build_job_runner_image {
if [[ $(get_latest_docker_hub_version "job-runner") == $(./release_notes.sh get-version) ]] && [[ "${LIFERAY_DOCKER_DEVELOPER_MODE}" != "true" ]]
then
echo ""
echo "Docker image job runner is up to date."
return
fi
local job_runner_version=1.0
echo ""
echo "Building Docker image job runner."
echo ""
LIFERAY_DOCKER_IMAGE_PLATFORMS="${LIFERAY_DOCKER_IMAGE_PLATFORMS}" time ./build_job_runner_image.sh "${BUILD_ALL_IMAGES_PUSH}" | tee -a "${LOGS_DIR}"/job_runner.log
if [ "${PIPESTATUS[0]}" -gt 0 ]
then
echo "FAILED: Job Runner" >> "${LOGS_DIR}/results"
exit 1
else
echo "SUCCESS: Job Runner" >> "${LOGS_DIR}/results"
fi
}
function get_latest_available_zulu_version {
local version=$(curl -H 'accept: */*' -L -s "https://api.azul.com/zulu/download/community/v1.0/bundles/latest/?arch=${2}&bundle_type=jdk&ext=deb&hw_bitness=64&javafx=false&java_version=${1}&os=linux" | jq -r '.zulu_version | join(".")' | cut -f1,2,3 -d'.')
echo "${version}"
}
function get_latest_docker_hub_version {
local token=$(curl -s "https://auth.docker.io/token?scope=repository:liferay/${1}:pull&service=registry.docker.io" | jq -r '.token')
local version=$(curl -s -H "Authorization: Bearer $token" "https://registry-1.docker.io/v2/liferay/${1}/manifests/latest" | grep -o '\\"org.label-schema.version\\":\\"[0-9]\.[0-9]\.[0-9]*\\"' | head -1 | sed 's/\\"//g' | sed 's:.*\:::')
echo "${version}"
}
function get_latest_docker_hub_zulu_version {
local token=$(curl -s "https://auth.docker.io/token?scope=repository:liferay/${1}:pull&service=registry.docker.io" | jq -r '.token')
local version=$(curl -s -H "Authorization: Bearer $token" "https://registry-1.docker.io/v2/liferay/${1}/manifests/latest" | grep -o "\\\\\"org.label-schema.zulu${2}_${3}_version\\\\\":\\\\\"[0-9]*\.[0-9]*\.[0-9]*\\\\\"" | head -1 | sed 's/\\"//g' | sed 's:.*\:::')
echo "${version}"
}
function get_main_key {
local main_keys=${1}
local version=${2}
for main_key in ${main_keys}
do
local count=$(echo "${version}" | grep -c -E "${main_key}-|${main_key}\.")
if [ "${count}" -gt 0 ]
then
echo "${main_key}"
break
fi
done
}
function get_string {
if [ "${1}" == "null" ]
then
echo ""
else
echo "${1}"
fi
}
function main {
check_utils 7z curl docker git java jq sed sort tr unzip yq
if [ "${BUILD_ALL_IMAGES_PUSH}" == "push" ] && ! ./release_notes.sh fail-on-change
then
exit 1
fi
if [ "${BUILD_ALL_IMAGES_PUSH}" == "push" ] && [ -z "${LIFERAY_DOCKER_IMAGE_PLATFORMS}" ]
then
LIFERAY_DOCKER_IMAGE_PLATFORMS=linux/amd64,linux/arm64
fi
validate_bundles_yml
LOGS_DIR=logs-$(date "$(date)" "+%Y%m%d%H%M")
mkdir -p "${LOGS_DIR}"
build_base_image
build_jdk11_image
build_jdk11_jdk8_image
build_job_runner_image
build_bundle_images
echo ""
echo "Results: "
echo ""
cat "${LOGS_DIR}/results"
}
function validate_bundles_yml {
if [ $(yq '.*.*.latest' < bundles.yml | grep "true" -c) -gt 2 ]
then
echo "There are too many images designated as latest."
exit 1
fi
local dxp_latest_key_counter=0
local main_keys=$(yq '' < bundles.yml | grep -v ' .*' | sed 's/://')
local portal_latest_key_counter=0
for main_key in ${main_keys}
do
if [ $(yq .\""${main_key}"\".*.latest < bundles.yml | grep "true\|false" -c) -gt 0 ]
then
local minor_keys=$(yq .\""${main_key}"\" < bundles.yml | grep -v ' .*' | sed 's/://')
for minor_key in ${minor_keys}
do
if [ $(yq .\""${main_key}"\".\""${minor_key}"\".latest < bundles.yml | grep "true\|false" -c) -gt 0 ]
then
if [ $(yq .\""${main_key}"\".\""${minor_key}"\".bundle_url < bundles.yml | grep "portal-tomcat") ]
then
portal_latest_key_counter=$((portal_latest_key_counter+1))
elif [ $(yq .\""${main_key}"\".\""${minor_key}"\".bundle_url < bundles.yml | grep "dxp-tomcat") ]
then
dxp_latest_key_counter=$((dxp_latest_key_counter+1))
fi
fi
done
fi
done
if [ ${dxp_latest_key_counter} -gt 1 ]
then
echo "There are ${dxp_latest_key_counter} latest DXP images."
exit 1
elif [ ${portal_latest_key_counter} -gt 1 ]
then
echo "There are ${portal_latest_key_counter} latest portal images."
exit 1
fi
}
main