[update.sh] Do not clean up dangling items, remove old image tags (not removed by dangling=true)
This commit is contained in:
parent
94e5631662
commit
bdfaef09c6
56
update.sh
56
update.sh
@ -109,6 +109,17 @@ elif [[ ${MERGE_RETURN} != 0 ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo -e "\e[32mFetching new docker-compose version...\e[0m"
|
||||||
|
sleep 2
|
||||||
|
if [[ $(curl -sL -w "%{http_code}" https://www.servercow.de/docker-compose/latest.php -o /dev/null) == "200" ]]; then
|
||||||
|
LATEST_COMPOSE=$(curl -#L https://www.servercow.de/docker-compose/latest.php)
|
||||||
|
curl -#L https://github.com/docker/compose/releases/download/${LATEST_COMPOSE}/docker-compose-$(uname -s)-$(uname -m) > $(which docker-compose)
|
||||||
|
chmod +x $(which docker-compose)
|
||||||
|
else
|
||||||
|
echo -e "\e[33mCannot determine latest docker-compose version, skipping...\e[0m"
|
||||||
|
fi
|
||||||
|
|
||||||
echo -e "\e[32mFetching new images, if any...\e[0m"
|
echo -e "\e[32mFetching new images, if any...\e[0m"
|
||||||
sleep 2
|
sleep 2
|
||||||
docker-compose pull --parallel
|
docker-compose pull --parallel
|
||||||
@ -117,19 +128,48 @@ docker-compose pull --parallel
|
|||||||
[[ ! -d data/assets/ssl ]] && mkdir -p data/assets/ssl
|
[[ ! -d data/assets/ssl ]] && mkdir -p data/assets/ssl
|
||||||
cp -n data/assets/ssl-example/*.pem data/assets/ssl/
|
cp -n data/assets/ssl-example/*.pem data/assets/ssl/
|
||||||
|
|
||||||
echo -e "\e[32mFetching new docker-compose version...\e[0m"
|
|
||||||
sleep 2
|
|
||||||
curl -L https://github.com/docker/compose/releases/download/$(curl -Ls https://www.servercow.de/docker-compose/latest.php)/docker-compose-$(uname -s)-$(uname -m) > $(which docker-compose)
|
|
||||||
chmod +x $(which docker-compose)
|
|
||||||
|
|
||||||
echo -e "\e[32mStarting mailcow...\e[0m"
|
echo -e "\e[32mStarting mailcow...\e[0m"
|
||||||
sleep 2
|
sleep 2
|
||||||
docker-compose up -d --remove-orphans
|
docker-compose up -d --remove-orphans
|
||||||
#echo -e "\e[32mCleaning up dangling Docker objects...\e[0m"
|
|
||||||
if [[ ! -z $(docker images -qf "dangling=true") ]]; then
|
IMGS_TO_DELETE=()
|
||||||
docker rmi -f $(docker images -qf "dangling=true" -q)
|
for container in $(grep -oP "image: \Kmailcow.+" docker-compose.yml); do
|
||||||
|
REPOSITORY=${container/:*}
|
||||||
|
TAG=${container/*:}
|
||||||
|
V_MAIN=${container/*.}
|
||||||
|
V_SUB=${container/*.}
|
||||||
|
|
||||||
|
EXISTING_TAGS=$(docker images | grep ${REPOSITORY} | awk '{ print $2 }')
|
||||||
|
for existing_tag in ${EXISTING_TAGS[@]}; do
|
||||||
|
V_MAIN_EXISTING=${existing_tag/*.}
|
||||||
|
V_SUB_EXISTING=${existing_tag/*.}
|
||||||
|
if [[ $V_MAIN_EXISTING == "latest" ]]; then
|
||||||
|
echo "Found deprecated label \"latest\" for repository $REPOSITORY, it should be deleted."
|
||||||
|
IMGS_TO_DELETE+=($REPOSITORY:$existing_tag)
|
||||||
|
elif [[ $V_MAIN_EXISTING -lt $V_MAIN ]]; then
|
||||||
|
echo "Found tag $existing_tag for $REPOSITORY, which is older than the current tag $TAG and should be deleted."
|
||||||
|
IMGS_TO_DELETE+=($REPOSITORY:$existing_tag)
|
||||||
|
elif [[ $V_SUB_EXISTING -lt $V_SUB ]]; then
|
||||||
|
echo "Found tag $existing_tag for $REPOSITORY, which is older than the current tag $TAG and should be deleted."
|
||||||
|
IMGS_TO_DELETE+=($REPOSITORY:$existing_tag)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
if [[ ! -z ${IMGS_TO_DELETE[*]} ]]; then
|
||||||
|
echo "Run the following command to delete unused image tags:"
|
||||||
|
echo
|
||||||
|
echo " docker rmi ${IMGS_TO_DELETE[*]}"
|
||||||
|
echo
|
||||||
|
read -r -p "Do you want to delete old image tags right now? [Y/n] " response
|
||||||
|
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
|
||||||
|
docker rmi ${IMGS_TO_DELETE[*]}
|
||||||
|
else
|
||||||
|
"OK, skipped."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo -e "\e[32mIf you want to cleanup further garbage collected by Docker, please make sure all containers are up and running before cleaning your system by executing \"docker system prune\".\e[0m"
|
||||||
|
|
||||||
#echo "In case you encounter any problem, hard-reset to a state before updating mailcow:"
|
#echo "In case you encounter any problem, hard-reset to a state before updating mailcow:"
|
||||||
#echo
|
#echo
|
||||||
#git reflog --color=always | grep "Before update on "
|
#git reflog --color=always | grep "Before update on "
|
||||||
|
Loading…
Reference in New Issue
Block a user