mirror of
https://github.com/nextcloud/vm.git
synced 2025-10-26 11:27:32 +00:00
fix watchtower (#844)
This commit is contained in:
parent
50d499b343
commit
c2d5911b44
14
lib.sh
14
lib.sh
@ -964,6 +964,20 @@ systemctl daemon-reload
|
||||
systemctl restart docker
|
||||
}
|
||||
|
||||
# Check if old docker exists
|
||||
# FULL NAME e.g. ark74/nc_fts or containrrr/watchtower or collabora/code
|
||||
does_this_docker_exist() {
|
||||
if [ "$(docker ps -a >/dev/null 2>&1 && echo yes || echo no)" == "yes" ]
|
||||
then
|
||||
if [ "$(docker images "$1" | awk '{print $1}' | tail -1)" == "$1" ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Remove all dockers excluding one
|
||||
# docker_prune_except_this fts_esror 'Full Text Search'
|
||||
docker_prune_except_this() {
|
||||
|
||||
@ -36,7 +36,6 @@ https://shop.hanssonit.se/product/premium-support-per-30-minutes/"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# System Upgrade
|
||||
if which mysql > /dev/null
|
||||
then
|
||||
@ -161,16 +160,40 @@ then
|
||||
ln -s "$ADMINERDIR"/latest.php "$ADMINERDIR"/adminer.php
|
||||
fi
|
||||
|
||||
# Update ALL Docker images automatically with watchtower:
|
||||
if [ "$(docker ps -a >/dev/null 2>&1 && echo yes || echo no)" == "yes" ]
|
||||
# Remove old watchtower if existing
|
||||
if does_this_docker_exist v2tec/watchtower
|
||||
then
|
||||
cont_name=watchtower
|
||||
if ! docker ps -a --format '{{.Names}}' | grep -Eq "^${cont_name}\$";
|
||||
# Get Env values (https://github.com/koalaman/shellcheck/issues/1601)
|
||||
get_env_values() {
|
||||
# shellcheck disable=SC2016
|
||||
docker inspect -f '{{range $index, $value := .Config.Env}}{{$value}}{{println}}{{end}}' watchtower > env.list
|
||||
}
|
||||
get_env_values
|
||||
|
||||
# Remove empty lines
|
||||
sed -i '/^[[:space:]]*$/d' env.list
|
||||
|
||||
# Get Cmd values
|
||||
CmdDocker=$(docker inspect --format='{{.Config.Cmd}}' watchtower | cut -d "]" -f 1 | cut -d "[" -f 2;)
|
||||
|
||||
# Check if env.list is empty and run the docker accordingly
|
||||
if [ -s env.list ]
|
||||
then
|
||||
docker run -d --restart=unless-stopped --name watchtower -v /var/run/docker.sock:/var/run/docker.sock v2tec/watchtower --cleanup --interval 3600
|
||||
docker_prune_this v2tec/watchtower
|
||||
docker run -d --restart=unless-stopped --name watchtower -v /var/run/docker.sock:/var/run/docker.sock --env-file ./env.list containrrr/watchtower "$CmdDocker"
|
||||
rm -f env.list
|
||||
else
|
||||
docker_prune_this v2tec/watchtower
|
||||
docker run -d --restart=unless-stopped --name watchtower -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower "$CmdDocker"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Update ALL Docker images automatically with watchtower
|
||||
if ! does_this_docker_exist containrrr/watchtower
|
||||
then
|
||||
docker run -d --restart=unless-stopped --name watchtower -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup --interval 3600
|
||||
fi
|
||||
|
||||
# Cleanup un-used packages
|
||||
apt autoremove -y
|
||||
apt autoclean
|
||||
|
||||
Loading…
Reference in New Issue
Block a user