From 0887025412df86dc72c9866a869e29348e2a651a Mon Sep 17 00:00:00 2001 From: mag37 Date: Thu, 18 Jan 2024 20:59:55 +0100 Subject: [PATCH 1/6] Added functionality for labels and force restarts. --- dockcheck.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/dockcheck.sh b/dockcheck.sh index be30773..8fb3828 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -24,8 +24,10 @@ Help() { echo "-a|y Automatic updates, without interaction." echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower." echo "-e X Exclude containers, separated by comma." + echo "-f Force stack restart after update. Caution: will once for every updated container within stack." echo "-h Print this Help." echo "-i Inform - send a preconfigured notification." + echo "-l Only update if label is set. See readme." echo "-m Monochrome mode, no printf color codes." echo "-n No updates, only checking availability." echo "-p Auto-Prune dangling images after update." @@ -42,12 +44,14 @@ c_teal="\033[0;36m" c_reset="\033[0m" Stopped="" -while getopts "aynprhisme:d:" options; do +while getopts "aynpfrhlisme:d:" options; do case "${options}" in a|y) AutoUp="yes" ;; n) AutoUp="no" ;; r) DRunUp="yes" ;; p) AutoPrune="yes" ;; + l) OnlyLabel=true ;; + f) ForceRestartStacks=true ;; i) [ -s $ScriptWorkDir/notify.sh ] && { source $ScriptWorkDir/notify.sh ; Notify="yes" ; } ;; e) Exclude=${OPTARG} ;; m) declare c_{red,green,yellow,blue,teal,reset}="" ;; @@ -275,6 +279,8 @@ if [ -n "$GotUpdates" ] ; then ContName=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.service" }}') ContEnv=$(docker inspect "$i" --format '{{index .Config.Labels "com.docker.compose.project.environment_file" }}') ContImage=$(docker inspect "$i" --format='{{.Config.Image}}') + ContUpdateLabel=$(docker inspect "$i" --format '{{ index .Config.Labels "mag37.dockcheck.update" }}') + ContRestartStack=$(docker inspect "$i" --format '{{ index .Config.Labels "mag37.dockcheck.restart-stack" }}') ### Checking if compose-values are empty - hence started with docker run: if [ -z "$ContPath" ] ; then if [ "$DRunUp" == "yes" ] ; then @@ -294,16 +300,25 @@ if [ -n "$GotUpdates" ] ; then ### cd to the compose-file directory to account for people who use relative volumes, eg - ${PWD}/data:data cd "$ContPath" || { echo "Path error - skipping $i" ; continue ; } printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset" + ### Checking if Label Only -option is set, and if container got the label + [[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != true ]] && { echo "No label, skipping" ; continue ; } } docker pull "$ContImage" ### Reformat for multi-compose: IFS=',' read -r -a Confs <<< "$ComposeFile" ; unset IFS for conf in "${Confs[@]}"; do CompleteConfs+="-f $conf " ; done - ### Check if the container got an environment file set, use it if so: - if [ -n "$ContEnv" ]; then - $DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d "$ContName" # unquoted array to allow split - rework? + if [ -n "$ContEnv" ]; then # also checking if stack should be restarted + if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]] ; then + $DockerBin ${CompleteConfs[@]} stop ; $DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d + else + $DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d "$ContName" # unquoted array to allow split - rework? + fi else - $DockerBin ${CompleteConfs[@]} up -d "$ContName" # unquoted array to allow split - rework? + if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]] ; then + $DockerBin ${CompleteConfs[@]} stop ; $DockerBin ${CompleteConfs[@]} up -d + else + $DockerBin ${CompleteConfs[@]} up -d "$ContName" + fi fi done printf "\n%bAll done!%b\n" "$c_green" "$c_reset" From 4a8afde7906809557a8b8a5a43b4ee193d1c5a89 Mon Sep 17 00:00:00 2001 From: mag37 Date: Sat, 20 Jan 2024 10:33:32 +0100 Subject: [PATCH 2/6] Added pushbullet template. Suggested and contributed by [@arpanghosh8453](https://github.com/arpanghosh8453) --- README.md | 2 ++ notify_pushbullet.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 notify_pushbullet.sh diff --git a/README.md b/README.md index 2e50e7d..45d8329 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,8 @@ Current templates: - Apprise (with it's [multitude](https://github.com/caronc/apprise#supported-notifications) of notifications) - both native [caronc/apprise](https://github.com/caronc/apprise) and the standalone [linuxserver/docker-apprise-api](https://github.com/linuxserver/docker-apprise-api) - Read the [QuickStart](extras/apprise_quickstart.md) +- [ntfy.sh](https://ntfy.sh/) - HTTP-based pub-sub notifications. +- [Pushbullet](https://www.pushbullet.com/) - connecting different devices with cross-platform features. Further additions are welcome - suggestions or PR! Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2). diff --git a/notify_pushbullet.sh b/notify_pushbullet.sh new file mode 100644 index 0000000..9019017 --- /dev/null +++ b/notify_pushbullet.sh @@ -0,0 +1,27 @@ +### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. +# +# Copy/rename this file to notify.sh to enable the notification snippet. +# Required receiving services must already be set up. +# Requires jq installed and in PATH. +# Modify to fit your setup - set Url and Token. + +send_notification() { +Updates=("$@") +UpdToString=$( printf "%s\n" "${Updates[@]}" ) +FromHost=$(hostname) + +# platform specific notification code would go here +printf "\nSending pushbullet notification\n" + +MessageTitle="$FromHost - updates available." +# Setting the MessageBody variable here. +MessageBody="Containers on $FromHost with updates available: $UpdToString" + +# Modify to fit your setup: +PushUrl="https://api.pushbullet.com/v2/pushes" +PushToken="Your Pushbullet token here" + +# Requires jq to process json data +jq -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -sS -o /dev/null --show-error --fail -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @- + +} From 32f6d428d31249305b3a51a0faa6e53cd603c285 Mon Sep 17 00:00:00 2001 From: mag37 Date: Sat, 20 Jan 2024 10:36:41 +0100 Subject: [PATCH 3/6] pushbullet info --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 45d8329..31bfef3 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,12 @@ ___ ## :bell: Changelog +- **v0.3.6**: Added pushbullet template. - **v0.3.5**: Added a simple progress bar for the registry checkup. - **v0.3.4**: Added ntfy.sh template and error message on registry fail. - **v0.3.3**: Added Apprise template and the option `-i` inform - to send notifications. - **v0.3.2**: Added a notify function to wrap a notify-script, currently DSM/Ssmtp + template script. - **v0.3.1**: Addded option `-m` , monochrome mode - no printf color codes. -- **v0.3.0**: Added option `-d N`, age (days) new images have to be before being pulled and updated. ___ ## :nut_and_bolt: Dependencies From 4817d75d94cdc4a9665ea1bff401341e1ebe5231 Mon Sep 17 00:00:00 2001 From: mag37 Date: Sat, 20 Jan 2024 10:38:11 +0100 Subject: [PATCH 4/6] pushbullet template version bump. --- dockcheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dockcheck.sh b/dockcheck.sh index 8fb3828..28b49da 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION="v0.3.5" -### ChangeNotes: Added a simple handcrafted progress bar. +VERSION="v0.3.6" +### ChangeNotes: Added a Pushbullet template. Github="https://github.com/mag37/dockcheck" RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh" From 05d21a707a3720bd195197efead8c665b4e2f02b Mon Sep 17 00:00:00 2001 From: mag37 Date: Sun, 21 Jan 2024 20:29:29 +0100 Subject: [PATCH 5/6] added readme about labels --- README.md | 43 ++++++++++++++++++++++++++++--------------- dockcheck.sh | 2 +- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 31bfef3..c9b4959 100644 --- a/README.md +++ b/README.md @@ -38,22 +38,25 @@ ___ ## :mag_right: `dockcheck.sh` ``` $ ./dockcheck.sh -h - Syntax: dockcheck.sh [OPTION] [part of name to filter] - Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall - - Options: - -a|y Automatic updates, without interaction. - -d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower. - -e X Exclude containers, separated by comma. - -h Print this Help. - -i Inform - send a preconfigured notification. - -m Monochrome mode, no printf color codes. - -n No updates, only checking availability. - -p Auto-Prune dangling images after update. - -r Allow updating images for docker run, wont update the container. - -s Include stopped containers in the check. (Logic: docker ps -a) +Syntax: dockcheck.sh [OPTION] [part of name to filter] +Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall + +Options:" +-a|y Automatic updates, without interaction. +-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower. +-e X Exclude containers, separated by comma. +-f Force stack restart after update. Caution: restarts once for every updated container within stack. +-h Print this Help. +-i Inform - send a preconfigured notification. +-l Only update if label is set. See readme. +-m Monochrome mode, no printf color codes. +-n No updates, only checking availability. +-p Auto-Prune dangling images after update. +-r Allow updating images for docker run, wont update the container. +-s Include stopped containers in the check. (Logic: docker ps -a). ``` + ### Basic example: ``` $ ./dockcheck.sh @@ -90,6 +93,16 @@ Current templates: Further additions are welcome - suggestions or PR! Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2). +## :bookmark: Labels +Optionally add labels to compose-files. Currently these are the usable labels: +``` + labels: + mag37.dockcheck.restart-stack: true + mag37.dockcheck.update: true +``` +- `mag37.dockcheck.restart-stack: true` works instead of the `-f` option, forcing stop+restart on the whole compose-stack (Caution: Will restart on every updated container within stack). +- `mag37.dockcheck.update: true` will when used with the `-l` option only update containers with this label and skip the rest. Will still list updates as usual. + ## :roller_coaster: Workaround for non **amd64** / **arm64** `regctl` provides binaries for amd64/arm64, to use on other architecture you could try this workaround. Run regctl in a container wrapped in a shell script. Copied from [regclient/docs/install.md](https://github.com/regclient/regclient/blob/main/docs/install.md): @@ -123,7 +136,7 @@ Containers need to be manually stopped, removed and created again to run on the ## :scroll: License dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/licenses/gpl-3.0-standalone.html) license. -### :floppy_disk: The [story](https://mag37.org/posts/project_dockcheck/) behind it. 1 year in the mirror. +### :floppy_disk: The [story](https://mag37.org/posts/project_dockcheck/) behind it. 1 year in retrospect. ___ diff --git a/dockcheck.sh b/dockcheck.sh index 28b49da..5c4e30d 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -24,7 +24,7 @@ Help() { echo "-a|y Automatic updates, without interaction." echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower." echo "-e X Exclude containers, separated by comma." - echo "-f Force stack restart after update. Caution: will once for every updated container within stack." + echo "-f Force stack restart after update. Caution: restarts once for every updated container within stack." echo "-h Print this Help." echo "-i Inform - send a preconfigured notification." echo "-l Only update if label is set. See readme." From abbb924867678f582a74c23df3bbc080c307ac90 Mon Sep 17 00:00:00 2001 From: mag37 Date: Wed, 24 Jan 2024 19:37:15 +0100 Subject: [PATCH 6/6] labels and -f option --- README.md | 2 +- dockcheck.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c9b4959..516b0b5 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,12 @@ ___ ## :bell: Changelog +- **v0.3.7**: Added support for [labels](#labels), added the `-f` option (force restart stack). - **v0.3.6**: Added pushbullet template. - **v0.3.5**: Added a simple progress bar for the registry checkup. - **v0.3.4**: Added ntfy.sh template and error message on registry fail. - **v0.3.3**: Added Apprise template and the option `-i` inform - to send notifications. - **v0.3.2**: Added a notify function to wrap a notify-script, currently DSM/Ssmtp + template script. -- **v0.3.1**: Addded option `-m` , monochrome mode - no printf color codes. ___ ## :nut_and_bolt: Dependencies diff --git a/dockcheck.sh b/dockcheck.sh index 5c4e30d..f92bdd2 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION="v0.3.6" -### ChangeNotes: Added a Pushbullet template. +VERSION="v0.3.7" +### ChangeNotes: Added label support (see readme) and -f (force restart stack) option. Github="https://github.com/mag37/dockcheck" RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"