mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-18 02:17:46 +00:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15d3a96b2c | ||
|
|
fbd27d6e37 | ||
|
|
7bd5f87ed1 | ||
|
|
e24cba0078 | ||
|
|
886379dc7d | ||
|
|
488669b99a | ||
|
|
e20fdd9e85 | ||
|
|
3d1c424d23 | ||
|
|
132fda3388 | ||
|
|
cc9b3b0828 | ||
|
|
29c2c5e961 | ||
|
|
5dc9af9874 | ||
|
|
f91ca08d54 | ||
|
|
9a246b52c4 | ||
|
|
0c33f581f7 | ||
|
|
b492aacf0f | ||
|
|
f498138d4b | ||
|
|
6a3198eb08 | ||
|
|
48bfea9fbf | ||
|
|
f2fc5a4d34 | ||
|
|
f0940e81ec | ||
|
|
a25e648557 | ||
|
|
0e2bdc94ad |
21
README.md
21
README.md
@@ -2,7 +2,8 @@
|
|||||||
<img src="extras/dockcheck_logo_by_booYah187.png" width="160" title="dockcheck">
|
<img src="extras/dockcheck_logo_by_booYah187.png" width="160" title="dockcheck">
|
||||||
</p>
|
</p>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://img.shields.io/badge/-bash-grey?style=flat-square&logo=gnubash" alt="bash">
|
<img src="https://img.shields.io/badge/coded%20by%20Human-100%25-yellow?style=flat-square" alt="No AI!">
|
||||||
|
<img src="https://img.shields.io/badge/bash-4.3-green?style=flat-square&logo=gnubash" alt="bash">
|
||||||
<a href="https://www.gnu.org/licenses/gpl-3.0.html"><img src="https://img.shields.io/badge/license-GPLv3-red?style=flat-square" alt="GPLv3"></a>
|
<a href="https://www.gnu.org/licenses/gpl-3.0.html"><img src="https://img.shields.io/badge/license-GPLv3-red?style=flat-square" alt="GPLv3"></a>
|
||||||
<img src="https://img.shields.io/github/v/tag/mag37/dockcheck?style=flat-square&label=release" alt="release">
|
<img src="https://img.shields.io/github/v/tag/mag37/dockcheck?style=flat-square&label=release" alt="release">
|
||||||
<a href="https://ko-fi.com/mag37"><img src="https://img.shields.io/badge/-Ko--fi-grey?style=flat-square&logo=Ko-fi" alt="Buy me a Coffee"></a>
|
<a href="https://ko-fi.com/mag37"><img src="https://img.shields.io/badge/-Ko--fi-grey?style=flat-square&logo=Ko-fi" alt="Buy me a Coffee"></a>
|
||||||
@@ -14,11 +15,11 @@
|
|||||||
<h4 align="center">With features like excluding specific containers, filter by name, auto-prune dangling images and more.</h4</h3>
|
<h4 align="center">With features like excluding specific containers, filter by name, auto-prune dangling images and more.</h4</h3>
|
||||||
|
|
||||||
|
|
||||||
### :warning: URGENT! The 2.1 change had a breaking error - make sure you run an updated version.
|
|
||||||
If you've had errors, inspect your containers and look for odd compose paths, volumes or ports.
|
|
||||||
[errorCheck.sh](https://github.com/mag37/dockcheck/blob/main/errorCheck.sh) lists the important bits of each running container. If anything suspicious, recreate the container manually with `docker compose`.
|
|
||||||
|
|
||||||
### :pushpin: Recent changes:
|
### :pushpin: Recent changes:
|
||||||
|
- **v0.3.0**: Added a flag `-d N` to choose how many days old new images have to be before being pulled and updated.
|
||||||
|
- **v0.2.6**: regctl check / download logic changed. Now using the scripts directory as primary location.
|
||||||
|
- **v0.2.5**: Added a new option `-s` to include stopped containers in the check for updates.
|
||||||
|
- **v0.2.4**: Fixed a bug with the Exclude-logic to only exclude exact matches. Added a counter.
|
||||||
- **v0.2.3**: Added a self updating function (curl/git) and a ugly changenote-message for updates.
|
- **v0.2.3**: Added a self updating function (curl/git) and a ugly changenote-message for updates.
|
||||||
- **v0.2.2**: Fixed breaking errors with multi-compose, odd breakage and working dir error.
|
- **v0.2.2**: Fixed breaking errors with multi-compose, odd breakage and working dir error.
|
||||||
- **v0.2.1**: Added option to exclude a list of containers.
|
- **v0.2.1**: Added option to exclude a list of containers.
|
||||||
@@ -40,15 +41,17 @@ ___
|
|||||||
```
|
```
|
||||||
$ ./dockcheck.sh -h
|
$ ./dockcheck.sh -h
|
||||||
Syntax: dockcheck.sh [OPTION] [part of name to filter]
|
Syntax: dockcheck.sh [OPTION] [part of name to filter]
|
||||||
Example: dockcheck.sh -a -e nextcloud,heimdall
|
Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h Print this Help.
|
-h Print this Help.
|
||||||
-a|y Automatic updates, without interaction.
|
-a|y Automatic updates, without interaction.
|
||||||
-n No updates, only checking availability.
|
-n No updates, only checking availability.
|
||||||
|
-e X Exclude containers, separated by comma.
|
||||||
|
-d N Only update to new images that are N+ days old. Lists too recent with +prefix. 2xSlower.
|
||||||
-p Auto-Prune dangling images after update.
|
-p Auto-Prune dangling images after update.
|
||||||
-e Exclude containers, separated by comma.
|
|
||||||
-r Allow updating images for docker run, wont update the container.
|
-r Allow updating images for docker run, wont update the container.
|
||||||
|
-s Include stopped containers in the check. (Logic: docker ps -a).
|
||||||
```
|
```
|
||||||
|
|
||||||
Basic example:
|
Basic example:
|
||||||
@@ -80,6 +83,7 @@ Containers need to be manually stopped, removed and created again to run on the
|
|||||||
### :hammer: Known issues
|
### :hammer: Known issues
|
||||||
- No detailed error feedback (just skip + list what's skipped).
|
- No detailed error feedback (just skip + list what's skipped).
|
||||||
- Not respecting `--profile` options when re-creating the container.
|
- Not respecting `--profile` options when re-creating the container.
|
||||||
|
- Not working well with containers created by Portainer.
|
||||||
|
|
||||||
## `dc_brief.sh`
|
## `dc_brief.sh`
|
||||||
Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors.
|
Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors.
|
||||||
@@ -88,8 +92,7 @@ Just a brief, slimmed down version of the script to only print what containers g
|
|||||||
dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/licenses/gpl-3.0-standalone.html) license.
|
dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/licenses/gpl-3.0-standalone.html) license.
|
||||||
___
|
___
|
||||||
|
|
||||||
## Check out a spinoff brother-project:
|
### Check out a spinoff project: [Palleri/DCW](https://github.com/Palleri/DCW) for a WebUI-front with exporters and notifications.
|
||||||
### [Palleri/dockcheck-web](https://github.com/Palleri/dockcheck-web) for a WebUI-front!
|
|
||||||
|
|
||||||
## Special Thanks:
|
## Special Thanks:
|
||||||
- :bison: [t0rnis](https://github.com/t0rnis)
|
- :bison: [t0rnis](https://github.com/t0rnis)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
|
|||||||
SearchName="$1"
|
SearchName="$1"
|
||||||
|
|
||||||
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
|
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
|
||||||
[[ " ${Excludes[*]} " =~ ${i} ]] && continue; # Skip if the container is excluded
|
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
|
||||||
printf ". "
|
printf ". "
|
||||||
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
|
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
|
||||||
|
|||||||
64
dockcheck.sh
64
dockcheck.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
VERSION="v0.2.3"
|
VERSION="v0.3.0"
|
||||||
### ChangeNotes: Added self-updating git/curl-function and a dirty changenote.
|
### ChangeNotes: Added feature (-d N) to only update to new images that are N+ days old.
|
||||||
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"
|
||||||
|
|
||||||
@@ -17,25 +17,31 @@ LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/### ChangeNot
|
|||||||
### Help Function:
|
### Help Function:
|
||||||
Help() {
|
Help() {
|
||||||
echo "Syntax: dockcheck.sh [OPTION] [part of name to filter]"
|
echo "Syntax: dockcheck.sh [OPTION] [part of name to filter]"
|
||||||
echo "Example: dockcheck.sh -a -e nextcloud,heimdall"
|
echo "Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall"
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo "-h Print this Help."
|
echo "-h Print this Help."
|
||||||
echo "-a|y Automatic updates, without interaction."
|
echo "-a|y Automatic updates, without interaction."
|
||||||
echo "-n No updates, only checking availability."
|
echo "-n No updates, only checking availability."
|
||||||
echo "-e Exclude containers, separated by comma."
|
echo "-e X Exclude containers, separated by comma."
|
||||||
|
echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower."
|
||||||
echo "-p Auto-Prune dangling images after update."
|
echo "-p Auto-Prune dangling images after update."
|
||||||
echo "-r Allow updating images for docker run, wont update the container"
|
echo "-r Allow updating images for docker run, wont update the container"
|
||||||
|
echo "-s Include stopped containers in the check. (Logic: docker ps -a)"
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "aynprhe:" options; do
|
Stopped=""
|
||||||
|
while getopts "aynprhse:d:" options; do
|
||||||
case "${options}" in
|
case "${options}" in
|
||||||
a|y) UpdYes="yes" ;;
|
a|y) UpdYes="yes" ;;
|
||||||
n) UpdYes="no" ;;
|
n) UpdYes="no" ;;
|
||||||
r) DrUp="yes" ;;
|
r) DrUp="yes" ;;
|
||||||
p) PruneQ="yes" ;;
|
p) PruneQ="yes" ;;
|
||||||
e) Exclude=${OPTARG} ;;
|
e) Exclude=${OPTARG} ;;
|
||||||
h|*) Help ; exit 0 ;;
|
s) Stopped="-a" ;;
|
||||||
|
d) DaysOld=${OPTARG}
|
||||||
|
if ! [[ $DaysOld =~ ^[0-9]+$ ]] ; then { printf "Days -d argument given (%s) is not a number.\n" "${DaysOld}" ; exit 2 ; } ; fi ;;
|
||||||
|
h|*) Help ; exit 2 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift "$((OPTIND-1))"
|
shift "$((OPTIND-1))"
|
||||||
@@ -47,7 +53,6 @@ self_update_git() {
|
|||||||
git fetch
|
git fetch
|
||||||
[ -n "$(git diff --name-only "$ScriptUpstream" "$ScriptName")" ] && {
|
[ -n "$(git diff --name-only "$ScriptUpstream" "$ScriptName")" ] && {
|
||||||
printf "%s\n" "Pulling the latest version."
|
printf "%s\n" "Pulling the latest version."
|
||||||
# git checkout "$ScriptUpstream"
|
|
||||||
git pull --force
|
git pull --force
|
||||||
printf "%s\n" "--- starting over with the updated version ---"
|
printf "%s\n" "--- starting over with the updated version ---"
|
||||||
cd - || { printf "Path error.\n" ; return ; }
|
cd - || { printf "Path error.\n" ; return ; }
|
||||||
@@ -100,8 +105,19 @@ choosecontainers() {
|
|||||||
printf "\n"
|
printf "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datecheck() {
|
||||||
|
ImageDate=$($regbin image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 )
|
||||||
|
ImageAge=$((($(date +%s) - $(date -d "$ImageDate" +%s))/86400))
|
||||||
|
if [ $ImageAge -gt $DaysOld ] ; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
### Version check & initiate self update
|
### Version check & initiate self update
|
||||||
[[ "$VERSION" != "$LatestRelease" ]] && { printf "New version available! Local: %s - Latest: %s \n Change Notes: %s \n" "$VERSION" "$LatestRelease" "$LatestChanges" ; self_update_select ; }
|
[[ "$VERSION" != "$LatestRelease" ]] && { printf "New version available! Local: %s - Latest: %s \n Change Notes: %s \n" "$VERSION" "$LatestRelease" "$LatestChanges" ; [[ -z "$UpdYes" ]] && self_update_select ; }
|
||||||
|
|
||||||
### Set $1 to a variable for name filtering later.
|
### Set $1 to a variable for name filtering later.
|
||||||
SearchName="$1"
|
SearchName="$1"
|
||||||
@@ -110,7 +126,7 @@ IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
|
|||||||
|
|
||||||
### Check if required binary exists in PATH or directory:
|
### Check if required binary exists in PATH or directory:
|
||||||
if [[ $(builtin type -P "regctl") ]]; then regbin="regctl" ;
|
if [[ $(builtin type -P "regctl") ]]; then regbin="regctl" ;
|
||||||
elif [[ -f "./regctl" ]]; then regbin="./regctl" ;
|
elif [[ -f "$ScriptWorkDir/regctl" ]]; then regbin="$ScriptWorkDir/regctl" ;
|
||||||
else
|
else
|
||||||
read -r -p "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " GetDep
|
read -r -p "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " GetDep
|
||||||
if [[ "$GetDep" =~ [yY] ]] ; then
|
if [[ "$GetDep" =~ [yY] ]] ; then
|
||||||
@@ -121,8 +137,8 @@ else
|
|||||||
*) echo "Architecture not supported, exiting." ; exit 1;;
|
*) echo "Architecture not supported, exiting." ; exit 1;;
|
||||||
esac
|
esac
|
||||||
RegUrl="https://github.com/regclient/regclient/releases/latest/download/regctl-linux-$architecture"
|
RegUrl="https://github.com/regclient/regclient/releases/latest/download/regctl-linux-$architecture"
|
||||||
if [[ $(builtin type -P curl) ]]; then curl -L $RegUrl > ./regctl ; chmod +x ./regctl ; regbin="./regctl" ;
|
if [[ $(builtin type -P curl) ]]; then curl -L $RegUrl > "$ScriptWorkDir/regctl" ; chmod +x "$ScriptWorkDir/regctl" ; regbin="$ScriptWorkDir/regctl" ;
|
||||||
elif [[ $(builtin type -P wget) ]]; then wget $RegUrl -O ./regctl ; chmod +x ./regctl ; regbin="./regctl" ;
|
elif [[ $(builtin type -P wget) ]]; then wget $RegUrl -O "$ScriptWorkDir/regctl" ; chmod +x "$ScriptWorkDir/regctl" ; regbin="$ScriptWorkDir/regctl" ;
|
||||||
else
|
else
|
||||||
printf "%s\n" "curl/wget not available - get regctl manually from the repo link, quitting."
|
printf "%s\n" "curl/wget not available - get regctl manually from the repo link, quitting."
|
||||||
fi
|
fi
|
||||||
@@ -154,15 +170,31 @@ for i in "${GotUpdates[@]}"; do
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
### Listing typed exclusions:
|
||||||
|
if [[ -n ${Excludes[*]} ]] ; then
|
||||||
|
printf "\n\033[0;34mExcluding these names:\033[0m\n"
|
||||||
|
printf "%s\n" "${Excludes[@]}"
|
||||||
|
printf "\n"
|
||||||
|
fi
|
||||||
|
|
||||||
### Check the image-hash of every running container VS the registry
|
### Check the image-hash of every running container VS the registry
|
||||||
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
|
for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do
|
||||||
[[ " ${Excludes[*]} " =~ ${i} ]] && continue; # Skip if the container is excluded
|
### Looping every item over the list of excluded names and skipping:
|
||||||
|
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
|
||||||
printf ". "
|
printf ". "
|
||||||
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
|
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
|
||||||
### Checking for errors while setting the variable:
|
### Checking for errors while setting the variable:
|
||||||
if RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null) ; then
|
if RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null) ; then
|
||||||
if [[ "$LocalHash" = *"$RegHash"* ]] ; then NoUpdates+=("$i"); else GotUpdates+=("$i"); fi
|
if [[ "$LocalHash" = *"$RegHash"* ]] ; then
|
||||||
|
NoUpdates+=("$i")
|
||||||
|
else
|
||||||
|
if [[ -n "$DaysOld" ]] && ! datecheck ; then
|
||||||
|
NoUpdates+=("+$i ${ImageAge}d")
|
||||||
|
else
|
||||||
|
GotUpdates+=("$i")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
GotErrors+=("$i")
|
GotErrors+=("$i")
|
||||||
fi
|
fi
|
||||||
@@ -200,8 +232,11 @@ if [ -n "$GotUpdates" ] ; then
|
|||||||
SelectedUpdates=( "${GotUpdates[@]}" )
|
SelectedUpdates=( "${GotUpdates[@]}" )
|
||||||
fi
|
fi
|
||||||
if [ "$UpdYes" == "${UpdYes#[Nn]}" ] ; then
|
if [ "$UpdYes" == "${UpdYes#[Nn]}" ] ; then
|
||||||
|
NumberofUpdates="${#SelectedUpdates[@]}"
|
||||||
|
CurrentQue=0
|
||||||
for i in "${SelectedUpdates[@]}"
|
for i in "${SelectedUpdates[@]}"
|
||||||
do
|
do
|
||||||
|
((CurrentQue+=1))
|
||||||
unset CompleteConfs
|
unset CompleteConfs
|
||||||
ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.working_dir" }}')
|
ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.working_dir" }}')
|
||||||
ContConfigFile=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}')
|
ContConfigFile=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}')
|
||||||
@@ -226,6 +261,7 @@ if [ -n "$GotUpdates" ] ; then
|
|||||||
fi
|
fi
|
||||||
### cd to the compose-file directory to account for people who use relative volumes, eg - ${PWD}/data:data
|
### cd to the compose-file directory to account for people who use relative volumes, eg - ${PWD}/data:data
|
||||||
cd "$ContPath" || { echo "Path error - skipping $i" ; continue ; }
|
cd "$ContPath" || { echo "Path error - skipping $i" ; continue ; }
|
||||||
|
printf "\n\033[0;36mNow updating (%s/%s): \033[0;34m%s\033[0m\n" "$CurrentQue" "$NumberofUpdates" "$i"
|
||||||
docker pull "$ContImage"
|
docker pull "$ContImage"
|
||||||
### Reformat for multi-compose:
|
### Reformat for multi-compose:
|
||||||
IFS=',' read -r -a Confs <<< "$ComposeFile" ; unset IFS
|
IFS=',' read -r -a Confs <<< "$ComposeFile" ; unset IFS
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 333 KiB After Width: | Height: | Size: 404 KiB |
Reference in New Issue
Block a user