From 4ddb54770eda407577878e0baf30bf8e720df8a4 Mon Sep 17 00:00:00 2001 From: mag37 Date: Sat, 25 Feb 2023 10:32:22 +0100 Subject: [PATCH 1/5] multi-compose fix Added a hacky fix for multi-compose containers, for example using overrides in custom directories or multiple override.yml --- dockcheck.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dockcheck.sh b/dockcheck.sh index 51397c5..83e720b 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -VERSION="v0.2.0" +VERSION="v0.2.1" Github="https://github.com/mag37/dockcheck" ### Check if there's a new release of the script: @@ -177,11 +177,15 @@ if [ -n "$GotUpdates" ] ; then ### cd to the compose-file directory to account for people who use relative volumes, eg - ${PWD}/data:data cd "$(dirname "${ComposeFile}")" || { echo "Path error - skipping $i" ; continue ; } docker pull "$ContImage" + ### Reformat for multi-compose: + IFS=',' read -r -a Confs <<< "$ContConfigFile" ; 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 -f "$ComposeFile" --env-file "$ContEnv" up -d "$ContName" + $DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d "$ContName" else - $DockerBin -f "$ComposeFile" up -d "$ContName" + $DockerBin ${CompleteConfs[@]} up -d "$ContName" fi done printf "\033[0;32mAll done!\033[0m\n" From 191d27097dbd7fdc874833c42d93db68a99413ed Mon Sep 17 00:00:00 2001 From: mag37 Date: Sun, 26 Feb 2023 07:49:57 +0100 Subject: [PATCH 2/5] Added exclude-option Added option to exclude specific containers, full names separated by comma. `dockcheck.sh -e heimdall,glances` --- dockcheck.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dockcheck.sh b/dockcheck.sh index 83e720b..5c23aaf 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -15,16 +15,18 @@ Help() { echo "-h Print this Help." echo "-a|y Automatic updates, without interaction." echo "-n No updates, only checking availability." + echo "-e Exclude containers, separated by comma." echo "-p Auto-Prune dangling images after update." echo "-r Allow updating images for docker run, wont update the container" } -while getopts "aynprh" options; do +while getopts "aynprhe:" options; do case "${options}" in a|y) UpdYes="yes" ;; n) UpdYes="no" ;; r) DrUp="yes" ;; p) PruneQ="yes" ;; + e) Exclude=${OPTARG} ;; h|*) Help ; exit 0 ;; esac done @@ -32,6 +34,8 @@ shift "$((OPTIND-1))" ### Set $1 to a variable for name filtering later. SearchName="$1" +### Create array of excludes +IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS ### Check if required binary exists in PATH or directory: if [[ $(builtin type -P "regctl") ]]; then regbin="regctl" ; @@ -108,6 +112,7 @@ choosecontainers() { ### Check the image-hash of every running container VS the registry for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do + [[ " ${Excludes[*]} " =~ ${i} ]] && continue; # Skip if the container is excluded printf ". " RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}') LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}') @@ -178,14 +183,14 @@ if [ -n "$GotUpdates" ] ; then cd "$(dirname "${ComposeFile}")" || { echo "Path error - skipping $i" ; continue ; } docker pull "$ContImage" ### Reformat for multi-compose: - IFS=',' read -r -a Confs <<< "$ContConfigFile" ; Unset IFS + IFS=',' read -r -a Confs <<< "$ContConfigFile" ; 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" + $DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d "$ContName" # unquoted array to allow split else - $DockerBin ${CompleteConfs[@]} up -d "$ContName" + $DockerBin ${CompleteConfs[@]} up -d "$ContName" # unquoted array to allow split fi done printf "\033[0;32mAll done!\033[0m\n" From d877a862927349ca28af2a5e87d41db247bb2c91 Mon Sep 17 00:00:00 2001 From: mag37 Date: Sun, 26 Feb 2023 08:03:15 +0100 Subject: [PATCH 3/5] Added exclude-opt Added options to allow for exclude option to be used --- dc_brief.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) mode change 100644 => 100755 dc_brief.sh diff --git a/dc_brief.sh b/dc_brief.sh old mode 100644 new mode 100755 index 208e0dd..5935b8a --- a/dc_brief.sh +++ b/dc_brief.sh @@ -2,9 +2,21 @@ ### If not in PATH, set full path. Else just "regctl" regbin="regctl" +### options to allow exclude: +while getopts "e:" options; do + case "${options}" in + e) Exclude=${OPTARG} ;; + *) exit 0 ;; + esac +done +shift "$((OPTIND-1))" +### Create array of excludes +IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS + SearchName="$1" for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do + [[ " ${Excludes[*]} " =~ ${i} ]] && continue; # Skip if the container is excluded printf ". " RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}') LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}') From c7304093bdc59164a282b32ddceeb1075a9eda58 Mon Sep 17 00:00:00 2001 From: Palleri Date: Sun, 26 Feb 2023 11:24:46 +0100 Subject: [PATCH 4/5] Added visual "new line" after update check. --- dc_brief.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/dc_brief.sh b/dc_brief.sh index 5935b8a..0982e3b 100755 --- a/dc_brief.sh +++ b/dc_brief.sh @@ -48,3 +48,4 @@ if [[ -n ${GotUpdates[*]} ]] ; then printf "\n\033[0;33mContainers with updates available:\033[0m\n" printf "%s\n" "${GotUpdates[@]}" fi +printf "\n\n" From f233cf3b41e4f730566c705fe5104f2fa69241a7 Mon Sep 17 00:00:00 2001 From: mag37 Date: Sun, 26 Feb 2023 13:16:54 +0100 Subject: [PATCH 5/5] Added info --- README.md | 6 ++++-- dockcheck.sh | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9f6466e..a5b22af 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,14 @@ ___ ``` $ ./dockcheck.sh -h Syntax: dockcheck.sh [OPTION] [part of name to filter] -Example: dockcheck.sh -a ng +Example: dockcheck.sh -a -e nextcloud,heimdall Options: -h Print this Help. -a|y Automatic updates, without interaction. -n No updates, only checking availability. -p Auto-Prune dangling images after update. +-e Exclude containers, separated by comma. -r Allow updating images for docker run, wont update the container. ``` @@ -68,11 +69,12 @@ Containers need to be manually stopped, removed and created again to run on the - ~~Having no curl/wget leads to corrupt `regctl` without alerting.~~ - ~~Using custom `.env` files does not work.~~ - ~~Pull not respecting image:tags, always defaulting to latest~~ +- ~~Not respecting multi-compose projects using multiple `-f` like `...override.yml` or similar.~~ +- ~~Not being able to exclude specific containers.~~ ### :hammer: Known issues - No detailed error feedback (just skip + list what's skipped) . - Not respecting `--profile` options when re-creating the container. -- Not respecting multi-compose projects using multiple `-f` like `...override.yml` or similar. ## `dc_brief.sh` Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors. diff --git a/dockcheck.sh b/dockcheck.sh index 5c23aaf..894531b 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -9,7 +9,7 @@ LatestRelease="$(curl -s -r 0-50 https://raw.githubusercontent.com/mag37/dockche ### Help Function: Help() { echo "Syntax: dockcheck.sh [OPTION] [part of name to filter]" - echo "Example: dockcheck.sh -a ng" + echo "Example: dockcheck.sh -a -e nextcloud,heimdall" echo echo "Options:" echo "-h Print this Help." @@ -188,9 +188,9 @@ if [ -n "$GotUpdates" ] ; then ### 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 + $DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d "$ContName" # unquoted array to allow split - rework? else - $DockerBin ${CompleteConfs[@]} up -d "$ContName" # unquoted array to allow split + $DockerBin ${CompleteConfs[@]} up -d "$ContName" # unquoted array to allow split - rework? fi done printf "\033[0;32mAll done!\033[0m\n"