docker images: merge debian/distroless image lists

The build script, build-docker-images.sh, truncates image lists under
some circumstances. As a result the archived image lists contain only
the images from the last iteration of the $OS loop. This patch merges
all lists into one at the end.

Story: 2010226
Task: 46395

Signed-off-by: Davlet Panech <davlet.panech@windriver.com>
Change-Id: Idd8a40bf789a2fe3aa8a94d2d218d3de0cbd3765
This commit is contained in:
Davlet Panech 2022-09-22 12:15:57 -04:00
parent 93f0b873b6
commit 03f68d264f
1 changed files with 37 additions and 10 deletions

View File

@ -23,6 +23,8 @@ load_build_env
require_job_env DOCKER_BASE_OS
require_job_env DOCKER_OS_LIST
HOST_WORKSPACE="$BUILD_HOME/workspace"
wheels_file="std/build-wheels-$DOCKER_BASE_OS-$BUILD_STREAM/stx-$DOCKER_BASE_OS-$BUILD_STREAM-wheels.tar"
#require_file "$HOST_WORKSPACE/$wheels_file"
@ -105,21 +107,46 @@ retag_and_push() {
# build them
lists_dir="$HOST_WORKSPACE/std/build-images"
versioned_list_file="$lists_dir/images-$DOCKER_BASE_OS-$BUILD_STREAM-versioned.lst"
latest_list_file="$lists_dir/images-$DOCKER_BASE_OS-$BUILD_STREAM-latest.lst"
rm -rf --one-file-system "$lists_dir"
mkdir -p "$lists_dir"
failed=0
touch "$versioned_list_file" "$latest_list_file"
for os in $(echo $DOCKER_OS_LIST | sed 's/,/ /g') ; do
list_file="$lists_dir/images-$os-$BUILD_STREAM-versioned.lst"
# save list files because build script truncates them under some circumstances
for list_file in "${versioned_list_file}" "${latest_list_file}" ; do
mv "${list_file}" "${list_file}.save"
done
notice "building $BUILD_STREAM $os images"
$DRY_RUN || rm -f "$list_file"
if stx_docker_cmd $DRY_RUN_ARG "cd \$MY_REPO/build-tools/build-docker-images && ${cmd[*]} --os=$os" ; then
if $PUSH_DOCKER_IMAGES && [[ -f "$list_file" ]] ; then
retag_and_push "$list_file"
fi
continue
$DRY_RUN || rm -f "$versioned_list_file" "$latest_list_file"
if ! stx_docker_cmd $DRY_RUN_ARG "cd \$MY_REPO/build-tools/build-docker-images && ${cmd[*]} --os=$os" ; then
failed=1
fi
failed=1
if $PUSH_DOCKER_IMAGES && [[ -f "$versioned_list_file" ]] ; then
retag_and_push "$versioned_list_file"
fi
if $PUSH_DOCKER_IMAGES && [[ -f "$latest_list_file" ]] ; then
retag_and_push "$latest_list_file"
fi
# append + restore list files
for list_file in "${versioned_list_file}" "${latest_list_file}" ; do
if [[ -f "$list_file" ]] ; then
cat "$list_file" >>"${list_file}.save"
fi
mv "${list_file}.save" "${list_file}"
done
done
if [[ $failed -ne 1 ]] ; then
notice "one or more images failed to build, see output above"
if [[ $failed -eq 1 ]] ; then
error "one or more images failed to build, see output above"
exit 1
fi
notice "all images built successfully"
find "$lists_dir" -mindepth 1 -maxdepth 1 -name "images-*.lst"