mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-18 10:27:54 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61f90893ef | ||
|
|
229cde0efb | ||
|
|
0c6674ac8e | ||
|
|
3e079e2ec5 | ||
|
|
b2d67c9f52 | ||
|
|
3aeee837f9 | ||
|
|
408a8b14dd | ||
|
|
a2868ea505 | ||
|
|
62a3d10b4f |
15
README.md
15
README.md
@@ -16,14 +16,16 @@
|
|||||||
|
|
||||||
<h4 align="center">For Podman - see the fork <a href="https://github.com/sudo-kraken/podcheck">sudo-kraken/podcheck</a>!</h4>
|
<h4 align="center">For Podman - see the fork <a href="https://github.com/sudo-kraken/podcheck">sudo-kraken/podcheck</a>!</h4>
|
||||||
|
|
||||||
|
<h4 align="center">:whale: Docker Hub pull limit :chart_with_downwards_trend: not an issue for checks but for actual pulls - <a href="#whale-docker-hub-pull-limit-chart_with_downwards_trend-not-an-issue-for-checks-but-for-actual-pulls">read more</a></h4>
|
||||||
|
|
||||||
___
|
___
|
||||||
## :bell: Changelog
|
## :bell: Changelog
|
||||||
|
|
||||||
|
- **v0.5.6.0**: Heavily improved performance due to async checking for updates.
|
||||||
- **v0.5.5.0**: osx and bsd compatibility changes + rewrite of dependency installer
|
- **v0.5.5.0**: osx and bsd compatibility changes + rewrite of dependency installer
|
||||||
- **v0.5.4.0**: Added support for a Prometheus+node_exporter metric collection through a file collector.
|
- **v0.5.4.0**: Added support for a Prometheus+node_exporter metric collection through a file collector.
|
||||||
- **v0.5.3.0**: Local image check changed (use imageId instead of name) and Gotify-template fixed (whale icon removed).
|
- **v0.5.3.0**: Local image check changed (use imageId instead of name) and Gotify-template fixed (whale icon removed).
|
||||||
- **v0.5.2.1**: Rewrite of dependency downloads, jq can be installed with package manager or static binary.
|
- **v0.5.2.1**: Rewrite of dependency downloads, jq can be installed with package manager or static binary.
|
||||||
- **v0.5.1**: DEPENDENCY WARNING: now requires **jq**. + Upstreaming changes from [sudo-kraken/podcheck](https://github.com/sudo-kraken/podcheck)
|
|
||||||
___
|
___
|
||||||
|
|
||||||
|
|
||||||
@@ -77,6 +79,7 @@ ___
|
|||||||
## :nut_and_bolt: Dependencies
|
## :nut_and_bolt: Dependencies
|
||||||
- Running docker (duh) and compose, either standalone or plugin. (see [Podman fork](https://github.com/sudo-kraken/podcheck)
|
- Running docker (duh) and compose, either standalone or plugin. (see [Podman fork](https://github.com/sudo-kraken/podcheck)
|
||||||
- Bash shell or compatible shell of at least v4.3
|
- Bash shell or compatible shell of at least v4.3
|
||||||
|
- POSIX `xargs`, usually default but can be installed with the `findutils` package - to enable async.
|
||||||
- [jq](https://github.com/jqlang/jq)
|
- [jq](https://github.com/jqlang/jq)
|
||||||
- User will be prompted to install with package manager or download static binary.
|
- User will be prompted to install with package manager or download static binary.
|
||||||
- [regclient/regctl](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
|
- [regclient/regctl](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
|
||||||
@@ -177,7 +180,15 @@ chmod 755 regctl
|
|||||||
```
|
```
|
||||||
Test it with `./regctl --help` and then either add the file to the same path as *dockcheck.sh* or in your path (eg. `~/.local/bin/regctl`).
|
Test it with `./regctl --help` and then either add the file to the same path as *dockcheck.sh* or in your path (eg. `~/.local/bin/regctl`).
|
||||||
|
|
||||||
## :guardsman: Function to auth with docker hub before running
|
## :whale: Docker Hub pull limit :chart_with_downwards_trend: not an issue for checks but for actual pulls
|
||||||
|
Due to recent changes in [Docker Hub usage and limits](https://docs.docker.com/docker-hub/usage/)
|
||||||
|
>Unauthenticated users: 10 pulls/hour
|
||||||
|
>Authenticated users with a free account: 100 pulls/hour
|
||||||
|
|
||||||
|
This is not an issue for registry checks. But if you have a large stack and pull more than 10 updates at once consider updating more often or to create a free account.
|
||||||
|
You could use/modify the login-wrapper function in the example below to automate the login prior to running `dockcheck.sh`.
|
||||||
|
|
||||||
|
### :guardsman: Function to auth with docker hub before running
|
||||||
**Example** - Change names, paths, and remove cat+password flag if you rather get prompted:
|
**Example** - Change names, paths, and remove cat+password flag if you rather get prompted:
|
||||||
```sh
|
```sh
|
||||||
function dchk {
|
function dchk {
|
||||||
|
|||||||
66
dockcheck.sh
66
dockcheck.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
VERSION="v0.5.5.0"
|
VERSION="v0.5.6.0"
|
||||||
### ChangeNotes: osx and bsd compatibility changes + rewrite of dependency installer
|
### ChangeNotes: Heavily improved performance due to asynchronous update checks.
|
||||||
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"
|
||||||
|
|
||||||
@@ -46,6 +46,7 @@ c_blue="\033[0;34m"
|
|||||||
c_teal="\033[0;36m"
|
c_teal="\033[0;36m"
|
||||||
c_reset="\033[0m"
|
c_reset="\033[0m"
|
||||||
|
|
||||||
|
MaxAsync=32
|
||||||
Timeout=10
|
Timeout=10
|
||||||
Stopped=""
|
Stopped=""
|
||||||
while getopts "aynpfrhlisvmc:e:d:t:" options; do
|
while getopts "aynpfrhlisvmc:e:d:t:" options; do
|
||||||
@@ -282,31 +283,70 @@ if [[ $t_out ]]; then
|
|||||||
else t_out=""
|
else t_out=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check the image-hash of every running container VS the registry
|
check_image() {
|
||||||
for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do
|
i="$1"
|
||||||
((RegCheckQue+=1))
|
local Excludes=($Excludes_string)
|
||||||
progress_bar "$RegCheckQue" "$ContCount"
|
for e in "${Excludes[@]}" ; do
|
||||||
# Looping every item over the list of excluded names and skipping
|
if [[ "$i" == "$e" ]]; then
|
||||||
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
|
echo Skip $i
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
local NoUpdates GotUpdates GotErrors
|
||||||
ImageId=$(docker inspect "$i" --format='{{.Image}}')
|
ImageId=$(docker inspect "$i" --format='{{.Image}}')
|
||||||
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
LocalHash=$(docker image inspect "$ImageId" --format '{{.RepoDigests}}')
|
LocalHash=$(docker image inspect "$ImageId" --format '{{.RepoDigests}}')
|
||||||
|
|
||||||
# Checking for errors while setting the variable
|
# Checking for errors while setting the variable
|
||||||
if RegHash=$(${t_out} $regbin -v error image digest --list "$RepoUrl" 2>&1) ; then
|
if RegHash=$(${t_out} $regbin -v error image digest --list "$RepoUrl" 2>&1) ; then
|
||||||
if [[ "$LocalHash" = *"$RegHash"* ]] ; then
|
if [[ "$LocalHash" = *"$RegHash"* ]] ; then
|
||||||
NoUpdates+=("$i")
|
echo NoUpdates "$i"
|
||||||
else
|
else
|
||||||
if [[ -n "$DaysOld" ]] && ! datecheck ; then
|
if [[ -n "$DaysOld" ]] && ! datecheck ; then
|
||||||
NoUpdates+=("+$i ${ImageAge}d")
|
echo NoUpdates "+$i ${ImageAge}d"
|
||||||
else
|
else
|
||||||
GotUpdates+=("$i")
|
echo GotUpdates "$i"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Here the RegHash is the result of an error code
|
# Here the RegHash is the result of an error code
|
||||||
GotErrors+=("$i - ${RegHash}")
|
echo GotErrors "$i - ${RegHash}"
|
||||||
fi
|
fi
|
||||||
done
|
}
|
||||||
|
|
||||||
|
# Make required functions and variables available to subprocesses
|
||||||
|
export -f check_image datecheck
|
||||||
|
export Excludes_string="${Excludes[@]}" # Can only export scalar variables
|
||||||
|
export t_out regbin RepoUrl DaysOld
|
||||||
|
|
||||||
|
# Check for POSIX xargs with -P option, fallback without async
|
||||||
|
if (echo "test" | xargs -P 10 >/dev/null 2>&1) ; then
|
||||||
|
XargsAsync="-P $MaxAsync"
|
||||||
|
else
|
||||||
|
XargsAsync=""
|
||||||
|
printf "%bMissing POSIX xargs, consider installing 'findutils' for asynchronous lookups.%b\n" "$c_red" "$c_reset"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Asynchronously check the image-hash of every running container VS the registry
|
||||||
|
while read -r line; do
|
||||||
|
((RegCheckQue+=1))
|
||||||
|
progress_bar "$RegCheckQue" "$ContCount"
|
||||||
|
|
||||||
|
Got=${line%% *} # Extracts the first word (NoUpdates, GotUpdates, GotErrors)
|
||||||
|
item=${line#* }
|
||||||
|
|
||||||
|
case "$Got" in
|
||||||
|
NoUpdates) NoUpdates+=("$item") ;;
|
||||||
|
GotUpdates) GotUpdates+=("$item") ;;
|
||||||
|
GotErrors) GotErrors+=("$item") ;;
|
||||||
|
Skip) ;;
|
||||||
|
*) echo "Error! Unexpected output from subprocess: ${line}" ;;
|
||||||
|
esac
|
||||||
|
done < <( \
|
||||||
|
docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}' | \
|
||||||
|
xargs ${XargsAsync} -I {} bash -c 'check_image "{}"' \
|
||||||
|
)
|
||||||
|
|
||||||
# Sort arrays alphabetically
|
# Sort arrays alphabetically
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
|||||||
Reference in New Issue
Block a user