@@ -65,6 +65,31 @@ parse_output ()
65
65
(exit $rc )
66
66
}
67
67
68
+ analyze_logs_by_logdetective () {
69
+ local log_file_name=" $1 "
70
+ echo " Sending failed log by fpaste command to paste bin."
71
+ paste_bin_link=$( fpaste " $log_file_name " )
72
+ # shellcheck disable=SC2181
73
+ if [[ $? -ne 0 ]]; then
74
+ echo " ERROR: Failed to send log file to private bin: ${log_file_name} "
75
+ return
76
+ fi
77
+ # pastebin link is "https://paste.centos.org/view/ee98ba05"
78
+ # We need a raw link that is "https://paste.centos.org/view/raw/ee98ba05"
79
+ raw_paste_bin_link=" ${paste_bin_link// view/ view\/ raw} "
80
+ echo " Sending log file to logdetective server: ${raw_paste_bin_link} "
81
+ echo " -------- LOGDETECTIVE BUILD LOG ANALYSIS START --------"
82
+ # shellcheck disable=SC2181
83
+ if ! curl -k --insecure --header " Content-Type: application/json" --request POST --data " {\" url\" :\" ${raw_paste_bin_link} \" }" " $LOGDETECTIVE_SERVER /analyze" > /tmp/logdetective_output.txt; then
84
+ echo " ERROR: Failed to analyze log file by logdetective server."
85
+ cat " /tmp/logdetective_output.txt"
86
+ echo " -------- LOGDETECTIVE BUILD LOG ANALYSIS FAILED --------"
87
+ return
88
+ fi
89
+ jq -rC ' .explanation.text' < " /tmp/logdetective_output.txt"
90
+ echo " -------- LOGDETECTIVE BUILD LOG ANALYSIS FINISHED --------"
91
+ }
92
+
68
93
# "best-effort" cleanup of image
69
94
function clean_image {
70
95
for id_file in .image-id .image-id-from; do
@@ -191,10 +216,37 @@ function docker_build_with_version {
191
216
if [[ " $SKIP_SQUASH " -eq 0 ]] && [[ " $is_podman " -eq 1 ]]; then
192
217
BUILD_OPTIONS+=" --squash"
193
218
fi
219
+
220
+ command=" docker build ${BUILD_OPTIONS} -f $dockerfile ${DOCKER_BUILD_CONTEXT} "
221
+ echo " -> building using $command "
222
+
223
+ tmp_file=$( mktemp " /tmp/${dir} -${OS} .XXXXXX" )
224
+ $command 2>&1 | tee " $tmp_file "
225
+ cat " $tmp_file "
226
+ last_row=$( < " $tmp_file " tail -n 1)
227
+ commit_message=$( < " $tmp_file " tail -n 3)
228
+ # Structure of log build is as follows:
229
+ # COMMIT
230
+ # --> e191d12b5928
231
+ # e191d12b5928360dd6024fe80d31e08f994d42577f76b9b143e014749afc8ab4
232
+ # shellcheck disable=SC2016
233
+ if [[ " $commit_message " == * " COMMIT" * ]] && [[ " $last_row " =~ (^--> )? (Using cache )? [a-fA-F0-9]+$ ]]; then
234
+ IMAGE_ID=" $last_row "
235
+ else
236
+ # Do not fail in case of sending log to pastebin or logdetective fails.
237
+ echo " Analyse logs by logdetective, why it failed."
238
+ analyze_logs_by_logdetective " ${tmp_file} "
239
+ exit 1
240
+ fi
241
+
242
+ rm -f " $tmp_file "
243
+
194
244
# shellcheck disable=SC2016
195
- parse_output ' docker build ' " $BUILD_OPTIONS " ' -f "$dockerfile" "${DOCKER_BUILD_CONTEXT}"' \
196
- " tail -n 1 | awk '/Successfully built|(^--> )?(Using cache )?[a-fA-F0-9]+$/{print \$ NF}'" \
197
- IMAGE_ID
245
+
246
+ # parse_output 'docker build '"$BUILD_OPTIONS"' -f "$dockerfile" "${DOCKER_BUILD_CONTEXT}"' \
247
+ # "tail -n 1 | awk '/Successfully built|(^--> )?(Using cache )?[a-fA-F0-9]+$/{print \$NF}'" \
248
+ # IMAGE_ID
249
+ # analyze_logs_by_logdetective "$?" "${tmp_file}"
198
250
echo " $IMAGE_ID " > .image-id
199
251
}
200
252
0 commit comments