diff --git a/tools/include/images/CON007.png b/tools/include/images/CON007.png new file mode 100644 index 000000000..30495268d Binary files /dev/null and b/tools/include/images/CON007.png differ diff --git a/tools/include/markdown/CON007-footer.md b/tools/include/markdown/CON007-footer.md new file mode 100644 index 000000000..cb2741fed --- /dev/null +++ b/tools/include/markdown/CON007-footer.md @@ -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. diff --git a/tools/include/markdown/CON007-header.md b/tools/include/markdown/CON007-header.md new file mode 100644 index 000000000..392b4e797 --- /dev/null +++ b/tools/include/markdown/CON007-header.md @@ -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. diff --git a/tools/json/config.software.json b/tools/json/config.software.json index b270d9c07..efbc91de5 100644 --- a/tools/json/config.software.json +++ b/tools/json/config.software.json @@ -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" } ] }, diff --git a/tools/modules/software/install_watchtower.sh b/tools/modules/software/install_watchtower.sh new file mode 100644 index 000000000..933d00715 --- /dev/null +++ b/tools/modules/software/install_watchtower.sh @@ -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"]} " + 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 +}