Skip to content

Commit

Permalink
Software install: Watchtower
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Dec 2, 2024
1 parent 6fc59d1 commit ce3115e
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
Binary file added tools/include/images/CON007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tools/include/markdown/CON007-footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Every day watchtower will pull the latest images and compare it to the one that was used to run the certain container. If it sees that the image has changed it will stop/remove containers and then restart it using the new image and the same docker run options that were used to start the container initially.
1 change: 1 addition & 0 deletions tools/include/markdown/CON007-header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Watchtower is an application that will monitor your running Docker containers and watch for changes to the images that those containers were originally started from. If watchtower detects that an image has changed, it will automatically restart the container using the new image.
20 changes: 20 additions & 0 deletions tools/json/config.software.json
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,26 @@
"status": "Stable",
"author": "@armbian",
"condition": "module_portainer status"
},
{
"id": "CON007",
"description": "Watchtower install",
"command": [
"module_watchtower install"
],
"status": "Stable",
"author": "@armbian",
"condition": "! module_watchtower status"
},
{
"id": "CON008",
"description": "Watchtower remove",
"command": [
"module_watchtower remove"
],
"status": "Stable",
"author": "@armbian",
"condition": "module_watchtower status"
}
]
},
Expand Down
68 changes: 68 additions & 0 deletions tools/modules/software/install_watchtower.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module_options+=(
["module_watchtower,author"]="@armbian"
["module_watchtower,feature"]="module_watchtower"
["module_watchtower,desc"]="Install watchtower container"
["module_watchtower,example"]="install remove status help"
["module_watchtower,port"]=""
["module_watchtower,status"]="Active"
["module_watchtower,arch"]=""
)
#
# Module watchtower
#
function module_watchtower () {
local title="watchtower"
local condition=$(which "$title" 2>/dev/null)

if check_if_installed docker-ce; then
local container=$(docker container ls -a | mawk '/watchtower?( |$)/{print $1}')
local image=$(docker image ls -a | mawk '/watchtower?( |$)/{print $3}')
fi

local commands
IFS=' ' read -r -a commands <<< "${module_options["module_watchtower,example"]}"

case "$1" in
"${commands[0]}")
check_if_installed docker-ce || install_docker
docker run -d \
--name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower
for i in $(seq 1 20); do
if docker inspect -f '{{ index .Config.Labels "build_version" }}' watchtower >/dev/null 2>&1 ; then
break
else
sleep 3
fi
if [ $i -eq 20 ] ; then
echo -e "\nTimed out waiting for ${title} to start, consult your container logs for more info (\`docker logs watchtower\`)"
exit 1
fi
done
;;
"${commands[1]}")
[[ "${container}" ]] && docker container rm -f "$container" >/dev/null
[[ "${image}" ]] && docker image rm "$image" >/dev/null
;;
"${commands[2]}")
if [[ "${container}" && "${image}" ]]; then
return 0
else
return 1
fi
;;
"${commands[3]}")
echo -e "\nUsage: ${module_options["module_watchtower,feature"]} <command>"
echo -e "Commands: ${module_options["module_watchtower,example"]}"
echo "Available commands:"
echo -e "\tinstall\t- Install $title."
echo -e "\tstatus\t- Installation status $title."
echo -e "\tremove\t- Remove $title."
echo
;;
*)
${module_options["module_watchtower,feature"]} ${commands[3]}
;;
esac
}

0 comments on commit ce3115e

Please sign in to comment.