From 471afe69b508b976b0f0111924418dbb7c2cf2ad Mon Sep 17 00:00:00 2001 From: Don Penney Date: Thu, 16 May 2019 10:54:11 -0400 Subject: [PATCH] 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 : 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 --- .../build-docker-images/build-stx-images.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/build-tools/build-docker-images/build-stx-images.sh b/build-tools/build-docker-images/build-stx-images.sh index bd8e6d4a..b4974635 100755 --- a/build-tools/build-docker-images/build-stx-images.sh +++ b/build-tools/build-docker-images/build-stx-images.sh @@ -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