Skip to content

Commit

Permalink
add failure handling to cleaning script
Browse files Browse the repository at this point in the history
  • Loading branch information
pfandzelter committed Sep 18, 2023
1 parent 8768313 commit e7e28b7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#!/bin/sh

set -e

TF_TAG="tinyFaaS"
TMP_DIR="tmp"

# remove old containers, networks and images
containers=$(docker ps -a -q --filter label=$TF_TAG)

if [ -n "$containers" ]; then
docker stop "$containers" > /dev/null
docker rm "$containers" > /dev/null
for container in $containers; do
docker stop "$container" > /dev/null || echo "Failed to stop container $container! Please stop it manually..."
docker rm "$container" > /dev/null || echo "Failed to remove container $container! Please remove it manually..."
done
else
echo "No old containers to remove. Skipping..."
fi

networks=$(docker network ls -q --filter label=$TF_TAG)

if [ -n "$networks" ]; then
docker network rm "$networks" > /dev/null
for network in $networks; do
docker network rm "$network" > /dev/null || echo "Failed to remove network $network! Please remove it manually..."
done
else
echo "No old networks to remove. Skipping..."
fi
Expand All @@ -27,17 +29,15 @@ images=$(docker image ls -q --filter label=$TF_TAG)

if [ -n "$images" ]; then
for image in $images; do
docker image rm "$image" > /dev/null
docker image rm "$image" > /dev/null || echo "Failed to remove image $image! Please remove it manually..."
done
else
echo "No old images to remove. Skipping..."
fi

# remove tmp directory
if [ -d "$TMP_DIR" ]; then
rm -rf "$TMP_DIR"
rm -rf "$TMP_DIR" > /dev/null || echo "Failed to remove directory $TMP_DIR ! Please remove it manually..."
else
echo "No tmp directory to remove. Skipping..."
fi

set +e

0 comments on commit e7e28b7

Please sign in to comment.