mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-17 09:57:49 +00:00
label and update list rework (#229)
* Reformatting the updates available list * rewritten list padding to be dynamic * Label rework + clearer messages (#228) - Moved up label check and logic to earlier in the process, to iterate the whole run the same way if `-l` option is passed. - Added messaging to make it clearer. - Clarified Readme and --help message. - Clarified prune message (to mean ALL dangling, not just currently updated).
This commit is contained in:
27
README.md
27
README.md
@@ -22,6 +22,15 @@
|
|||||||
___
|
___
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
|
||||||
|
- **v0.7.2**:
|
||||||
|
- Label rework:
|
||||||
|
- Moved up label logic to work globally on the current run.
|
||||||
|
- Only iterating on labeled containers when used with `-l` option, not listing others.
|
||||||
|
- Clarified messaging and readme/help texts.
|
||||||
|
- List reformatting for "available updates" numbering to easier highlight and copy:
|
||||||
|
- Padded with zero, changed `)` to `-`, example: `02 - homer`
|
||||||
|
- Can be selected by writing `2,3,4` or `02,03,04`.
|
||||||
- **v0.7.1**:
|
- **v0.7.1**:
|
||||||
- Added support for multiple notifications using the same template
|
- Added support for multiple notifications using the same template
|
||||||
- Added support for notification output format
|
- Added support for notification output format
|
||||||
@@ -36,18 +45,6 @@ ___
|
|||||||
- Bugfix: snooze dockcheck.sh-self-notification and some config clarification.
|
- Bugfix: snooze dockcheck.sh-self-notification and some config clarification.
|
||||||
- Added authentication support to Ntfy.sh.
|
- Added authentication support to Ntfy.sh.
|
||||||
- Added suport for sendmail in the SMTP-template.
|
- Added suport for sendmail in the SMTP-template.
|
||||||
- **v0.6.9**:
|
|
||||||
- Bugfix: label logic didn't skip recreation (skipped pulling).
|
|
||||||
- Added comma separated search filtering so you can selectively search exactly which containers to check/update.
|
|
||||||
- eg: `dockcheck.sh -yp homer,dozzle`
|
|
||||||
- **v0.6.8**:
|
|
||||||
- Bugfix: Unbound variable in notify_v2.sh
|
|
||||||
- New option: "DisplaySourcedFiles" *config* added to list what files get sourced
|
|
||||||
- **v0.6.7**: Snooze feature, curl, and consolidation
|
|
||||||
- Added snooze feature to delay notifications
|
|
||||||
- Added configurable default curl arguments
|
|
||||||
- Consolidated and standardized notify template update notifications
|
|
||||||
- Added curl error handling
|
|
||||||
___
|
___
|
||||||
|
|
||||||
|
|
||||||
@@ -69,7 +66,7 @@ Options:
|
|||||||
-h Print this Help.
|
-h Print this Help.
|
||||||
-i Inform - send a preconfigured notification.
|
-i Inform - send a preconfigured notification.
|
||||||
-I Prints custom releasenote urls alongside each container with updates in CLI output (requires urls.list).
|
-I Prints custom releasenote urls alongside each container with updates in CLI output (requires urls.list).
|
||||||
-l Only update if label is set. See readme.
|
-l Only include containers with label set. See readme.
|
||||||
-m Monochrome mode, no printf colour codes and hides progress bar.
|
-m Monochrome mode, no printf colour codes and hides progress bar.
|
||||||
-M Prints custom releasenote urls as markdown (requires template support).
|
-M Prints custom releasenote urls as markdown (requires template support).
|
||||||
-n No updates, only checking availability.
|
-n No updates, only checking availability.
|
||||||
@@ -283,10 +280,12 @@ Optionally add labels to compose-files. Currently these are the usable labels:
|
|||||||
mag37.dockcheck.only-specific-container: true
|
mag37.dockcheck.only-specific-container: true
|
||||||
mag37.dockcheck.restart-stack: true
|
mag37.dockcheck.restart-stack: true
|
||||||
```
|
```
|
||||||
- `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.
|
- `mag37.dockcheck.update: true` will when used with the `-l` option only check and update containers with this label set and skip the rest.
|
||||||
- `mag37.dockcheck.only-specific-container: true` works instead of the `-F` option, specifying the updated container when doing compose up, like `docker compose up -d homer`.
|
- `mag37.dockcheck.only-specific-container: true` works instead of the `-F` option, specifying the updated container when doing compose up, like `docker compose up -d homer`.
|
||||||
- `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.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).
|
||||||
|
|
||||||
|
Adding or modifying labels in compose-files requires a restart of the container to take effect.
|
||||||
|
|
||||||
## Workaround for non **amd64** / **arm64**
|
## Workaround for non **amd64** / **arm64**
|
||||||
`regctl` provides binaries for amd64/arm64, to use on other architecture you could try this workaround.
|
`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):
|
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):
|
||||||
|
|||||||
33
dockcheck.sh
33
dockcheck.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
VERSION="v0.7.1"
|
VERSION="v0.7.2"
|
||||||
# ChangeNotes: Add support for multiple notifications of the same type, output formatting, and file output
|
# ChangeNotes: Reformatted updates list, rewrote label logic to work globally when used with `-l`.
|
||||||
Github="https://github.com/mag37/dockcheck"
|
Github="https://github.com/mag37/dockcheck"
|
||||||
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
|
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ Help() {
|
|||||||
echo "-h Print this Help."
|
echo "-h Print this Help."
|
||||||
echo "-i Inform - send a preconfigured notification."
|
echo "-i Inform - send a preconfigured notification."
|
||||||
echo "-I Prints custom releasenote urls alongside each container with updates in CLI output (requires urls.list)."
|
echo "-I Prints custom releasenote urls alongside each container with updates in CLI output (requires urls.list)."
|
||||||
echo "-l Only update if label is set. See readme."
|
echo "-l Only include containers with label set. See readme."
|
||||||
echo "-m Monochrome mode, no printf colour codes and hides progress bar."
|
echo "-m Monochrome mode, no printf colour codes and hides progress bar."
|
||||||
echo "-M Prints custom releasenote urls as markdown (requires template support)."
|
echo "-M Prints custom releasenote urls as markdown (requires template support)."
|
||||||
echo "-n No updates; only checking availability without interaction."
|
echo "-n No updates; only checking availability without interaction."
|
||||||
@@ -342,12 +342,13 @@ dependency_check() {
|
|||||||
dependency_check "regctl" "regbin" "https://github.com/regclient/regclient/releases/latest/download/regctl-linux-TEMP"
|
dependency_check "regctl" "regbin" "https://github.com/regclient/regclient/releases/latest/download/regctl-linux-TEMP"
|
||||||
dependency_check "jq" "jqbin" "https://github.com/jqlang/jq/releases/latest/download/jq-linux-TEMP"
|
dependency_check "jq" "jqbin" "https://github.com/jqlang/jq/releases/latest/download/jq-linux-TEMP"
|
||||||
|
|
||||||
# Numbered List function
|
# Numbered List function - pads with zero
|
||||||
# if urls.list exists add release note url per line
|
|
||||||
list_options() {
|
list_options() {
|
||||||
num=1
|
local total="${#Updates[@]}"
|
||||||
|
[[ ${#total} < 2 ]] && local pads=2 || local pads="${#total}"
|
||||||
|
local num=1
|
||||||
for update in "${Updates[@]}"; do
|
for update in "${Updates[@]}"; do
|
||||||
echo "$num) $update"
|
printf "%0*d - %s\n" $pads $num $update
|
||||||
((num++))
|
((num++))
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@@ -423,6 +424,10 @@ check_image() {
|
|||||||
printf "%s\n" "NoUpdates !$i - not checked, no compose file"
|
printf "%s\n" "NoUpdates !$i - not checked, no compose file"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
# Checking if Label Only -option is set, and if container got the label
|
||||||
|
ContUpdateLabel=$($jqbin -r '."mag37.dockcheck.update"' <<< "$ContLabels")
|
||||||
|
[[ "$ContUpdateLabel" == "null" ]] && ContUpdateLabel=""
|
||||||
|
[[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != true ]] && { echo "Skip $i"; return; } }
|
||||||
|
|
||||||
local NoUpdates GotUpdates GotErrors
|
local NoUpdates GotUpdates GotErrors
|
||||||
ImageId=$(docker inspect "$i" --format='{{.Image}}')
|
ImageId=$(docker inspect "$i" --format='{{.Image}}')
|
||||||
@@ -448,7 +453,7 @@ check_image() {
|
|||||||
# Make required functions and variables available to subprocesses
|
# Make required functions and variables available to subprocesses
|
||||||
export -f check_image datecheck
|
export -f check_image datecheck
|
||||||
export Excludes_string="${Excludes[*]:-}" # Can only export scalar variables
|
export Excludes_string="${Excludes[*]:-}" # Can only export scalar variables
|
||||||
export t_out regbin RepoUrl DaysOld DRunUp jqbin
|
export t_out regbin RepoUrl DaysOld DRunUp jqbin OnlyLabel
|
||||||
|
|
||||||
# Check for POSIX xargs with -P option, fallback without async
|
# Check for POSIX xargs with -P option, fallback without async
|
||||||
if (echo "test" | xargs -P 2 >/dev/null 2>&1) && [[ "$MaxAsync" != 0 ]]; then
|
if (echo "test" | xargs -P 2 >/dev/null 2>&1) && [[ "$MaxAsync" != 0 ]]; then
|
||||||
@@ -478,6 +483,8 @@ done < <( \
|
|||||||
xargs $XargsAsync -I {} bash -c 'check_image "{}"' \
|
xargs $XargsAsync -I {} bash -c 'check_image "{}"' \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
[[ "$OnlyLabel" == true ]] && printf "\n%bLabel option active:%b Only checking containers with labels set.\n" "$c_blue" "$c_reset"
|
||||||
|
|
||||||
# Sort arrays alphabetically
|
# Sort arrays alphabetically
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
NoUpdates=($(sort <<<"${NoUpdates[*]:-}"))
|
NoUpdates=($(sort <<<"${NoUpdates[*]:-}"))
|
||||||
@@ -533,10 +540,6 @@ if [[ -n "${GotUpdates:-}" ]]; then
|
|||||||
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
|
ContPath=$($jqbin -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
|
||||||
[[ "$ContPath" == "null" ]] && ContPath=""
|
[[ "$ContPath" == "null" ]] && ContPath=""
|
||||||
ContUpdateLabel=$($jqbin -r '."mag37.dockcheck.update"' <<< "$ContLabels")
|
|
||||||
[[ "$ContUpdateLabel" == "null" ]] && ContUpdateLabel=""
|
|
||||||
# Checking if Label Only -option is set, and if container got the label
|
|
||||||
[[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != true ]] && { echo "No update label, skipping."; continue; } }
|
|
||||||
|
|
||||||
# Checking if compose-values are empty - hence started with docker run
|
# Checking if compose-values are empty - hence started with docker run
|
||||||
if [[ -z "$ContPath" ]]; then
|
if [[ -z "$ContPath" ]]; then
|
||||||
@@ -568,8 +571,6 @@ if [[ -n "${GotUpdates:-}" ]]; then
|
|||||||
[[ "$ContName" == "null" ]] && ContName=""
|
[[ "$ContName" == "null" ]] && ContName=""
|
||||||
ContEnv=$($jqbin -r '."com.docker.compose.project.environment_file"' <<< "$ContLabels")
|
ContEnv=$($jqbin -r '."com.docker.compose.project.environment_file"' <<< "$ContLabels")
|
||||||
[[ "$ContEnv" == "null" ]] && ContEnv=""
|
[[ "$ContEnv" == "null" ]] && ContEnv=""
|
||||||
ContUpdateLabel=$($jqbin -r '."mag37.dockcheck.update"' <<< "$ContLabels")
|
|
||||||
[[ "$ContUpdateLabel" == "null" ]] && ContUpdateLabel=""
|
|
||||||
ContRestartStack=$($jqbin -r '."mag37.dockcheck.restart-stack"' <<< "$ContLabels")
|
ContRestartStack=$($jqbin -r '."mag37.dockcheck.restart-stack"' <<< "$ContLabels")
|
||||||
[[ "$ContRestartStack" == "null" ]] && ContRestartStack=""
|
[[ "$ContRestartStack" == "null" ]] && ContRestartStack=""
|
||||||
ContOnlySpecific=$($jqbin -r '."mag37.dockcheck.only-specific-container"' <<< "$ContLabels")
|
ContOnlySpecific=$($jqbin -r '."mag37.dockcheck.only-specific-container"' <<< "$ContLabels")
|
||||||
@@ -578,8 +579,6 @@ if [[ -n "${GotUpdates:-}" ]]; then
|
|||||||
printf "\n%bNow recreating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset"
|
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
|
# Checking if compose-values are empty - hence started with docker run
|
||||||
[[ -z "$ContPath" ]] && { echo "Not a compose container, skipping."; continue; }
|
[[ -z "$ContPath" ]] && { echo "Not a compose container, skipping."; continue; }
|
||||||
# Checking if Label Only -option is set, and if container got the label
|
|
||||||
[[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != true ]] && { echo "No update label, skipping."; continue; } }
|
|
||||||
|
|
||||||
# cd to the compose-file directory to account for people who use relative volumes
|
# 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; }
|
cd "$ContPath" || { printf "\n%bPath error - skipping%b %s" "$c_red" "$c_reset" "$i"; continue; }
|
||||||
@@ -602,7 +601,7 @@ if [[ -n "${GotUpdates:-}" ]]; then
|
|||||||
${DockerBin} ${CompleteConfs} ${ContEnvs} up -d ${SpecificContainer} || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; }
|
${DockerBin} ${CompleteConfs} ${ContEnvs} up -d ${SpecificContainer} || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; }
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [[ "$AutoPrune" == false ]] && [[ "$AutoMode" == false ]]; then printf "\n"; read -rep "Would you like to prune dangling images? y/[n]: " AutoPrune; 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
|
if [[ "$AutoPrune" == true ]] || [[ "$AutoPrune" =~ [yY] ]]; then printf "\nAuto pruning.."; docker image prune -f; fi
|
||||||
printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
|
printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user