mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-16 16:28:17 +01:00
Moving the label logic to earlier in the process - at check level
This commit is contained in:
parent
7d1e1637f9
commit
b0e92c9aab
1 changed files with 7 additions and 9 deletions
16
dockcheck.sh
16
dockcheck.sh
|
|
@ -423,6 +423,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 +452,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 +482,8 @@ done < <( \
|
||||||
xargs $XargsAsync -I {} bash -c 'check_image "{}"' \
|
xargs $XargsAsync -I {} bash -c 'check_image "{}"' \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
[[ "$OnlyLabel" == true ]] && printf "\n%bLabel option set:%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 +539,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 +570,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 +578,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; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue