From abf7def0a606f6e94abae39fd50b6a9edaa1f85d Mon Sep 17 00:00:00 2001 From: vakarisbk Date: Tue, 17 Oct 2023 16:04:32 +0300 Subject: [PATCH] add container cleanup --- .github/workflows/main.yml | 1 + testing/testing.sh | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ac77be1..4650f46 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -256,6 +256,7 @@ jobs: # TODO(SPARK-44495): Resume to use the latest minikube for k8s-integration-tests. curl -LO https://storage.googleapis.com/minikube/releases/v1.30.1/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube + rm minikube-linux-amd64 # Github Action limit cpu:2, memory: 6947MB, limit to 2U6G for better resource statistic minikube start --cpus 2 --memory 6144 diff --git a/testing/testing.sh b/testing/testing.sh index d399d6d..2ee3774 100755 --- a/testing/testing.sh +++ b/testing/testing.sh @@ -59,15 +59,25 @@ function remove_network() { docker network rm "$NETWORK_NAME" > /dev/null } -# Find and kill any remaining containers attached to the network +# Find and kill any remaining containers and their images attached to the network function cleanup() { - local containers + local containers container_images + containers="$(docker ps --quiet --filter network="$NETWORK_NAME")" if [ -n "$containers" ]; then echo >&2 -n "==> Killing $(echo -n "$containers" | grep -c '^') orphaned container(s)..." echo "$containers" | xargs docker kill > /dev/null echo >&2 " done." + + # Get image IDs of the killed containers + container_images=$(docker container inspect -f '{{.Image}}' $containers) + + if [ -n "$container_images" ]; then + echo >&2 -n "==> Removing images associated with orphaned containers..." + echo "$container_images" | xargs docker rmi > /dev/null + echo >&2 " done." + fi fi }