Skip to content

Commit

Permalink
add container cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vakarisbk committed Oct 17, 2023
1 parent eceed35 commit abf7def
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions testing/testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit abf7def

Please sign in to comment.