Skip to content
Snippets Groups Projects
Commit 1d64069b authored by jurgenhaas's avatar jurgenhaas
Browse files

#84 Allow to delete multiple projects at once

parent 9fc5baf0
No related branches found
Tags v1.12.3
No related merge requests found
#!/bin/bash #!/bin/bash
function removecontainer() { function removecontainer() {
docker container ls --all -q -f name=^${PROJECT}_ > /tmp/reset.lst docker container ls --all -q -f name=^${PROJECT}_ >/tmp/reset.lst
IDS=$(cat /tmp/reset.lst) IDS=$(cat /tmp/reset.lst)
if [[ ! -n ${IDS} ]]; then if [[ ! -n ${IDS} ]]; then
echo "No containers to be removed." echo "No containers to be removed."
return return
fi fi
echo "Deleting containers ..." echo "Deleting containers ..."
for CONTAINERID in `cat /tmp/reset.lst`; do for CONTAINERID in $(cat /tmp/reset.lst); do
docker rm -f $CONTAINERID docker rm -f $CONTAINERID
done done
rm /tmp/reset.lst rm /tmp/reset.lst
...@@ -25,21 +25,34 @@ function removenetwork() { ...@@ -25,21 +25,34 @@ function removenetwork() {
if [[ -f "docker-compose.yml" ]]; then if [[ -f "docker-compose.yml" ]]; then
sed -i -e "/- ${PROJECT}$/d" docker-compose.yml sed -i -e "/- ${PROJECT}$/d" docker-compose.yml
sed -i -e "/^ ${PROJECT}:$/{N;d;}" docker-compose.yml sed -i -e "/^ ${PROJECT}:$/{N;d;}" docker-compose.yml
docker-compose stop NETWORKS="${NETWORKS} traefik_${PROJECT}"
docker rm -f traefik_traefik_1
docker network rm traefik_${PROJECT}
docker-compose --project-name traefik up -d
fi fi
} }
function rebuildtraefik() {
cd ${HOME}/.traefik || return
if [[ -f "docker-compose.yml" ]]; then
docker-compose --project-name traefik up -d --remove-orphans
fi
if [[ "$NETWORKS" == "" ]]; then
return
fi
docker network rm ${NETWORKS}
}
if [[ -n $1 ]]; then if [[ -n $1 ]]; then
PROJECT=$1 NETWORKS=""
while [[ -n $1 ]]; do
PROJECT=$1
read -p "Are you sure you want to remove the project ${PROJECT} with all containers and network? Type YES to confirm: " CONFIRM
if [[ "$CONFIRM" == YES ]]; then
removecontainer
removenetwork
fi
shift
done
rebuildtraefik
else else
echo "Please provide the project name you want to delete." echo "Please provide the project name you want to delete."
exit exit
fi fi
read -p "Are you sure you want to remove the project ${PROJECT} with all containers and network? Type YES to confirm: " CONFIRM
if [[ "$CONFIRM" == YES ]]; then
removecontainer
removenetwork
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment