diff --git a/README.md b/README.md index a9fc38f..a4228cd 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,14 @@ ___ ## Changelog -- **v0.7.3**: Bugfix - unquoted variable in printf list caused occasional issues. +- **v0.7.4**: + - Added new option `-R`: + - Will skip container recreation after pulling images. + - Allows for more control and possible pipeline integration. + - Fixes: + - Bugfix for *value too great* error due to leading zeroes - solved with base10 conversion. + - Clean up of some legacy readme sections. +- **v0.7.3**: Bugfix - unquoted variable in printf list caused occasional issues. - **v0.7.2**: - Label rework: - Moved up label logic to work globally on the current run. @@ -41,10 +48,6 @@ ___ - `_CONTAINERSONLY` : Only notify for docker container related updates - `_ALLOWEMPTY` : Always send notifications, even when empty - `_OUTPUT` : Define output format -- **v0.7.0**: - - Bugfix: snooze dockcheck.sh-self-notification and some config clarification. - - Added authentication support to Ntfy.sh. - - Added suport for sendmail in the SMTP-template. ___ @@ -72,6 +75,7 @@ Options: -n No updates, only checking availability. -p Auto-Prune dangling images after update. -r Allow checking for updates/updating images for docker run containers. Won't update the container. +-R Skip container recreation after pulling images. -s Include stopped containers in the check. (Logic: docker ps -a). -t N Set a timeout (in seconds) per container for registry checkups, 10 is default. -u Allow automatic self updates - caution as this will pull new code and autorun it. @@ -353,7 +357,7 @@ dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/l :small_orange_diamond: [4ndreasH](https://github.com/4ndreasH) :small_orange_diamond: [markoe01](https://github.com/markoe01) :small_orange_diamond: [mushrowan](https://github.com/mushrowan) -:small_orange_diamond: +:small_orange_diamond: ___ diff --git a/default.config b/default.config index d5d21aa..2b5f75c 100644 --- a/default.config +++ b/default.config @@ -19,6 +19,7 @@ #OnlyLabel=true # Only update if label is set. See readme. #ForceRestartStacks=true # Force stop+start stack after update. Caution: restarts once for every updated container within stack. #DRunUp=true # Allow updating images for docker run, wont update the container. +#SkipRecreate # Skip container recreation after pulling images. #MonoMode=true # Monochrome mode, no printf colour codes and hides progress bar. #PrintReleaseURL=true # Prints custom releasenote urls alongside each container with updates (requires urls.list)` #PrintMarkdownURL=true # Prints custom releasenote urls as markdown @@ -89,4 +90,3 @@ # TELEGRAM_TOPIC_ID="0" # # FILE_PATH="${ScriptWorkDir}/updates_available.txt" - diff --git a/dockcheck.sh b/dockcheck.sh index 42c241a..a3ebef0 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION="v0.7.3" -# ChangeNotes: Bugfix - unquoted variable in list. Also: Please consider donating. +VERSION="v0.7.4" +# ChangeNotes: New option -R to pull without recreation. Fixes: value too great error, legacy cleanups. Github="https://github.com/mag37/dockcheck" RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh" @@ -47,6 +47,7 @@ Help() { echo "-M Prints custom releasenote urls as markdown (requires template support)." echo "-n No updates; only checking availability without interaction." echo "-p Auto-prune dangling images after update." + echo "-R Skip container recreation after pulling images." echo "-r Allow checking for updates/updating images for docker run containers. Won't update the container." echo "-s Include stopped containers in the check. (Logic: docker ps -a)." echo "-t Set a timeout (in seconds) per container for registry checkups, 10 is default." @@ -78,6 +79,7 @@ Exclude=${Exclude:-} DaysOld=${DaysOld:-} OnlySpecific=${OnlySpecific:-false} SpecificContainer=${SpecificContainer:-""} +SkipRecreate=${SkipRecreate:-false} Excludes=() GotUpdates=() NoUpdates=() @@ -95,7 +97,7 @@ c_blue="\033[0;34m" c_teal="\033[0;36m" c_reset="\033[0m" -while getopts "ayfFhiIlmMnprsuvc:e:d:t:x:" options; do +while getopts "ayfFhiIlmMnprsuvc:e:d:t:x:R" options; do case "${options}" in a|y) AutoMode=true ;; c) CollectorTextFileDirectory="${OPTARG}" ;; @@ -110,6 +112,7 @@ while getopts "ayfFhiIlmMnprsuvc:e:d:t:x:" options; do M) PrintMarkdownURL=true ;; n) DontUpdate=true; AutoMode=true;; p) AutoPrune=true ;; + R) SkipRecreate=true ;; r) DRunUp=true ;; s) Stopped="-a" ;; t) Timeout="${OPTARG}" ;; @@ -213,6 +216,7 @@ choosecontainers() { else ChoiceClean=${Choice//[,.:;]/ } for CC in $ChoiceClean; do + CC=$((10#$CC)) # Base 10 interpretation to strip leading zeroes if [[ "$CC" -lt 1 || "$CC" -gt $UpdCount ]]; then # Reset choice if out of bounds echo "Number not in list: $CC"; unset ChoiceClean; break 1 else @@ -554,53 +558,58 @@ if [[ -n "${GotUpdates:-}" ]]; then docker pull "$ContImage" || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; } done - printf "\n%bDone pulling updates. %bRecreating updated containers.%b\n" "$c_green" "$c_blue" "$c_reset" + printf "\n%bDone pulling updates.%b\n" "$c_green" "$c_reset" - CurrentQue=0 - for i in "${SelectedUpdates[@]}"; do - ((CurrentQue+=1)) - unset CompleteConfs - # Extract labels and metadata - ContLabels=$(docker inspect "$i" --format '{{json .Config.Labels}}') - ContImage=$(docker inspect "$i" --format='{{.Config.Image}}') - ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels") - [[ "$ContPath" == "null" ]] && ContPath="" - ContConfigFile=$($jqbin -r '."com.docker.compose.project.config_files"' <<< "$ContLabels") - [[ "$ContConfigFile" == "null" ]] && ContConfigFile="" - ContName=$($jqbin -r '."com.docker.compose.service"' <<< "$ContLabels") - [[ "$ContName" == "null" ]] && ContName="" - ContEnv=$($jqbin -r '."com.docker.compose.project.environment_file"' <<< "$ContLabels") - [[ "$ContEnv" == "null" ]] && ContEnv="" - ContRestartStack=$($jqbin -r '."mag37.dockcheck.restart-stack"' <<< "$ContLabels") - [[ "$ContRestartStack" == "null" ]] && ContRestartStack="" - ContOnlySpecific=$($jqbin -r '."mag37.dockcheck.only-specific-container"' <<< "$ContLabels") - [[ "$ContOnlySpecific" == "null" ]] && ContRestartStack="" + if [[ "$SkipRecreate" == true ]]; then + printf "%bSkipping container recreation due to -R.%b\n" "$c_yellow" "$c_reset" + else + printf "%bRecreating updated containers.%b\n" "$c_blue" "$c_reset" + CurrentQue=0 + for i in "${SelectedUpdates[@]}"; do + ((CurrentQue+=1)) + unset CompleteConfs + # Extract labels and metadata + ContLabels=$(docker inspect "$i" --format '{{json .Config.Labels}}') + ContImage=$(docker inspect "$i" --format='{{.Config.Image}}') + ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels") + [[ "$ContPath" == "null" ]] && ContPath="" + ContConfigFile=$($jqbin -r '."com.docker.compose.project.config_files"' <<< "$ContLabels") + [[ "$ContConfigFile" == "null" ]] && ContConfigFile="" + ContName=$($jqbin -r '."com.docker.compose.service"' <<< "$ContLabels") + [[ "$ContName" == "null" ]] && ContName="" + ContEnv=$($jqbin -r '."com.docker.compose.project.environment_file"' <<< "$ContLabels") + [[ "$ContEnv" == "null" ]] && ContEnv="" + ContRestartStack=$($jqbin -r '."mag37.dockcheck.restart-stack"' <<< "$ContLabels") + [[ "$ContRestartStack" == "null" ]] && ContRestartStack="" + ContOnlySpecific=$($jqbin -r '."mag37.dockcheck.only-specific-container"' <<< "$ContLabels") + [[ "$ContOnlySpecific" == "null" ]] && ContRestartStack="" - printf "\n%bNow recreating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset" - # Checking if compose-values are empty - hence started with docker run - [[ -z "$ContPath" ]] && { echo "Not a compose container, skipping."; continue; } + printf "\n%bNow recreating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset" + # Checking if compose-values are empty - hence started with docker run + [[ -z "$ContPath" ]] && { echo "Not a compose container, skipping."; continue; } - # cd to the compose-file directory to account for people who use relative volumes - cd "$ContPath" || { printf "\n%bPath error - skipping%b %s" "$c_red" "$c_reset" "$i"; continue; } - ## Reformatting path + multi compose - if [[ $ContConfigFile == '/'* ]]; then - CompleteConfs=$(for conf in ${ContConfigFile//,/ }; do printf -- "-f %s " "$conf"; done) - else - CompleteConfs=$(for conf in ${ContConfigFile//,/ }; do printf -- "-f %s/%s " "$ContPath" "$conf"; done) - fi - # Check if the container got an environment file set and reformat it - ContEnvs="" - if [[ -n "$ContEnv" ]]; then ContEnvs=$(for env in ${ContEnv//,/ }; do printf -- "--env-file %s " "$env"; done); fi - # Set variable when compose up should only target the specific container, not the stack - if [[ $OnlySpecific == true ]] || [[ $ContOnlySpecific == true ]]; then SpecificContainer="$ContName"; fi + # cd to the compose-file directory to account for people who use relative volumes + cd "$ContPath" || { printf "\n%bPath error - skipping%b %s" "$c_red" "$c_reset" "$i"; continue; } + ## Reformatting path + multi compose + if [[ $ContConfigFile == '/'* ]]; then + CompleteConfs=$(for conf in ${ContConfigFile//,/ }; do printf -- "-f %s " "$conf"; done) + else + CompleteConfs=$(for conf in ${ContConfigFile//,/ }; do printf -- "-f %s/%s " "$ContPath" "$conf"; done) + fi + # Check if the container got an environment file set and reformat it + ContEnvs="" + if [[ -n "$ContEnv" ]]; then ContEnvs=$(for env in ${ContEnv//,/ }; do printf -- "--env-file %s " "$env"; done); fi + # Set variable when compose up should only target the specific container, not the stack + if [[ $OnlySpecific == true ]] || [[ $ContOnlySpecific == true ]]; then SpecificContainer="$ContName"; fi - # Check if the whole stack should be restarted - if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]]; then - ${DockerBin} ${CompleteConfs} stop; ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; } - else - ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d ${SpecificContainer} || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; } - fi - done + # Check if the whole stack should be restarted + if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]]; then + ${DockerBin} ${CompleteConfs} stop; ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; } + else + ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d ${SpecificContainer} || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; } + fi + done + fi if [[ "$AutoPrune" == false ]] && [[ "$AutoMode" == false ]]; then printf "\n"; read -rep "Would you like to prune all dangling images? y/[n]: " AutoPrune; fi if [[ "$AutoPrune" == true ]] || [[ "$AutoPrune" =~ [yY] ]]; then printf "\nAuto pruning.."; docker image prune -f; fi printf "\n%bAll done!%b\n" "$c_green" "$c_reset" diff --git a/extras/apprise_quickstart.md b/extras/apprise_quickstart.md index 2d1ddd6..c526492 100644 --- a/extras/apprise_quickstart.md +++ b/extras/apprise_quickstart.md @@ -38,35 +38,15 @@ You can also use the [caronc/apprise-api](https://github.com/caronc/apprise-api) ### Customize the **notify.sh** file. -After you're done with the setup of the container and tried your notifications, you can copy the `notify_apprise.sh` file to `notify.sh` and start editing it. +After you're done with the setup of the container and tried your notifications, you need to follow the configuration setup (explained in detail in the README). +Briefly: Copy `default.config` to `dockcheck.config` then edit it to change the following, `APPRISE_URL` matching your environment: -Comment out/remove the bare metal apprise-command (starting with `apprise -vv -t...`). -Uncomment and edit the `AppriseURL` variable and *curl* line -It should look something like this when curling the API: ```bash -send_notification() { -Updates=("$@") -UpdToString=$( printf "%s\n" "${Updates[@]}" ) -FromHost=$(hostname) - -printf "\nSending Apprise notification\n" - -MessageTitle="$FromHost - updates available." -# Setting the MessageBody variable here. -read -d '\n' MessageBody << __EOF -Containers on $FromHost with updates available: - -$UpdToString - -__EOF - -AppriseURL="http://IP.or.mydomain.tld:8000/notify/apprise" -curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL - -} +NOTIFY_CHANNELS="apprise" +APPRISE_URL="http://apprise.mydomain.tld:1234/notify/apprise" ``` -That's all! +That's it! ___ ___