Skip to content

Instantly share code, notes, and snippets.

@Asherslab
Created April 13, 2019 23:26
Show Gist options
  • Save Asherslab/49eb3cad0a8cb170f191a936a00e3266 to your computer and use it in GitHub Desktop.
Save Asherslab/49eb3cad0a8cb170f191a936a00e3266 to your computer and use it in GitHub Desktop.
#!/bin/sh
stacks=$(docker stack ls | grep -o -P 'chatchain-pr-.{1}' | cut -c14-)
stackprefix=chatchain-pr-
databasesuffix=_mongo-databases
networksuffix=_internal
matchuntilblankspace='\S*'
githubpullprefix=https://github.com/ldtteam/chatchain/pull/
delete_stack() {
echo
echo ----- Removing Stack: $stack -----
docker stack rm $stackprefix$stack
containers=$(docker ps -a | grep -o -P $stackprefix$stack$matchuntilblankspace)
for container in $containers
do
docker container rm -f -v $container
done
docker volume rm $volume
docker network rm $network
echo ------------------------------
}
for stack in $stacks
do
echo
echo Stack: $stackprefix$stack
echo Pull Request: $githubpullprefix$stack
state=$(curl https://api.github.com/repos/ldtteam/chatchain/pulls/$stack -s | jq -r '.state')
echo Status: $state
volumename=$stackprefix$stack$databasesuffix
volume=$(docker volume ls | grep -o -P $volumename) # just in case it doesn't exist
echo Volume: $volume
networkname=$stackprefix$stack$networksuffix
network=$(docker network ls | grep -o -P $networkname) # just in case it doesn't exist
echo Network: $network
services=$(docker service ls | grep -o -P $stackprefix$stack$matchuntilblankspace)
echo ----- Services -----
for service in $services
do
echo $service
done
echo --------------------
if [ $state != open ]
then
# echo $stack
delete_stack $stack $volume $network
fi
done
echo
echo ----- Pruning Images -----
docker image prune -f
echo --------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment