Clean up loci container and image on build failure

When loci hits a failure building an image, it leaves behind
a stopped docker container and a <none>:<none> image. This
commit updates build-stx-images.sh to look for and remove
these leftovers on failures.

Change-Id: I5c61b03b7f9b0f69f81e80e5c9fc787852f4441b
Story: 2005248
Task: 31050
Signed-off-by: Don Penney <don.penney@windriver.com>
This commit is contained in:
Don Penney 2019-05-16 10:54:11 -04:00
parent 729ef33454
commit 471afe69b5

View File

@ -222,6 +222,21 @@ function post_build {
fi
}
function cleanup_loci_failure {
# When loci fails, it leaves behind a stopped container and a none:none image.
# This function looks for those stopped containers to clean up after a failure.
local container
local image
local extra_fields
docker ps --no-trunc -f status=exited | grep /opt/loci/scripts/install.sh \
| while read container image extra_fields; do
echo "Cleaning loci build container and image: ${container} ${image}"
docker rm ${container}
docker image rm ${image}
done
}
function build_image_loci {
local image_build_file=$1
@ -292,6 +307,7 @@ function build_image_loci {
if [ ${PIPESTATUS[0]} -ne 0 ]; then
echo "Failed to build ${LABEL}... Aborting"
RESULTS_FAILED+=(${LABEL})
cleanup_loci_failure
return 1
fi