mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-18 10:27:54 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e754450300 | ||
|
|
6ff15f6d97 | ||
|
|
cb65d78075 | ||
|
|
955796c47a | ||
|
|
263966dc4a | ||
|
|
e877cd826d | ||
|
|
b78485ed8b | ||
|
|
fa8edd0443 | ||
|
|
dd6a56da1b | ||
|
|
7f30126678 | ||
|
|
c61dd58858 | ||
|
|
61825370dd |
14
README.md
14
README.md
@@ -66,21 +66,15 @@ Containers need to be manually stopped, removed and created again to run on the
|
|||||||
- ~~Script breaks if one of the chosen containers are a `docker run` container.~~
|
- ~~Script breaks if one of the chosen containers are a `docker run` container.~~
|
||||||
- ~~Using relative paths for volumes eg. `${PWD}/data:data` will create the volumes where you stand.~~
|
- ~~Using relative paths for volumes eg. `${PWD}/data:data` will create the volumes where you stand.~~
|
||||||
- ~~Having no curl/wget leads to corrupt `regctl` without alerting.~~
|
- ~~Having no curl/wget leads to corrupt `regctl` without alerting.~~
|
||||||
|
- ~~Using custom `.env` files does not work.~~
|
||||||
|
|
||||||
### :hammer: Known issues
|
### :hammer: Known issues
|
||||||
- ~~No granular choice of what to update (except initial name filter).~~
|
- ~~No granular choice of what to update (except initial name filter).~~
|
||||||
- No detailed error feedback (just skip + list what's skipped) .
|
- No detailed error feedback (just skip + list what's skipped) .
|
||||||
|
|
||||||
## `dupc_function.sh`
|
## `dc_brief.sh`
|
||||||
Function to quickly check for updates on a single contianer or list of containers by name. **Without the need of pulling**.
|
Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors.
|
||||||
Preferably placed in `.bashrc` or similar.
|
|
||||||
Example:
|
|
||||||
```
|
|
||||||
$ dupc ng
|
|
||||||
Updates available for local_nginx.
|
|
||||||
nginx_reverse is already latest.
|
|
||||||
Updates available for paperless-ng.
|
|
||||||
```
|
|
||||||
# License
|
# License
|
||||||
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.
|
||||||
___
|
___
|
||||||
|
|||||||
36
dc_brief.sh
Normal file
36
dc_brief.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
### If not in PATH, set full path. Else just "regctl"
|
||||||
|
regbin="regctl"
|
||||||
|
SearchName="$1"
|
||||||
|
|
||||||
|
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
|
||||||
|
printf ". "
|
||||||
|
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
|
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
|
||||||
|
### Checking for errors while setting the variable:
|
||||||
|
if RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null) ; then
|
||||||
|
if [[ "$LocalHash" = *"$RegHash"* ]] ; then NoUpdates+=("$i"); else GotUpdates+=("$i"); fi
|
||||||
|
else
|
||||||
|
GotErrors+=("$i")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
### Sort arrays alphabetically
|
||||||
|
IFS=$'\n'
|
||||||
|
NoUpdates=($(sort <<<"${NoUpdates[*]}"))
|
||||||
|
GotUpdates=($(sort <<<"${GotUpdates[*]}"))
|
||||||
|
GotErrors=($(sort <<<"${GotErrors[*]}"))
|
||||||
|
unset IFS
|
||||||
|
|
||||||
|
### List what containers got updates or not
|
||||||
|
if [[ -n ${NoUpdates[*]} ]] ; then
|
||||||
|
printf "\n\033[0;32mContainers on latest version:\033[0m\n"
|
||||||
|
printf "%s\n" "${NoUpdates[@]}"
|
||||||
|
fi
|
||||||
|
if [[ -n ${GotErrors[*]} ]] ; then
|
||||||
|
printf "\n\033[0;31mContainers with errors, wont get updated:\033[0m\n"
|
||||||
|
printf "%s\n" "${GotErrors[@]}"
|
||||||
|
fi
|
||||||
|
if [[ -n ${GotUpdates[*]} ]] ; then
|
||||||
|
printf "\n\033[0;33mContainers with updates available:\033[0m\n"
|
||||||
|
printf "%s\n" "${GotUpdates[@]}"
|
||||||
|
fi
|
||||||
22
dockcheck.sh
22
dockcheck.sh
@@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
VERSION="v0.1.8"
|
VERSION="v0.1.9"
|
||||||
Github="https://github.com/mag37/dockcheck"
|
Github="https://github.com/mag37/dockcheck"
|
||||||
|
|
||||||
### Check if there's a new release of the script:
|
### Check if there's a new release of the script:
|
||||||
LatestRelease="$(curl -s -r 0-40 https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
|
LatestRelease="$(curl -s -r 0-50 https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
|
||||||
[ "$VERSION" != "$LatestRelease" ] && printf "New version available! Latest: %s - Local: %s \nGrab it here: %s \n\n" "$LatestRelease" "$VERSION" "$Github"
|
[ "$VERSION" != "$LatestRelease" ] && printf "New version available! Latest: %s - Local: %s \nGrab it here: %s \n\n" "$LatestRelease" "$VERSION" "$Github"
|
||||||
|
|
||||||
### Help Function:
|
### Help Function:
|
||||||
@@ -130,22 +130,22 @@ UpdCount="${#GotUpdates[@]}"
|
|||||||
|
|
||||||
### List what containers got updates or not
|
### List what containers got updates or not
|
||||||
if [[ -n ${NoUpdates[*]} ]] ; then
|
if [[ -n ${NoUpdates[*]} ]] ; then
|
||||||
printf "\n\033[32;1mContainers on latest version:\033[0m\n"
|
printf "\n\033[0;32mContainers on latest version:\033[0m\n"
|
||||||
printf "%s\n" "${NoUpdates[@]}"
|
printf "%s\n" "${NoUpdates[@]}"
|
||||||
fi
|
fi
|
||||||
if [[ -n ${GotErrors[*]} ]] ; then
|
if [[ -n ${GotErrors[*]} ]] ; then
|
||||||
printf "\n\033[33;1mContainers with errors, wont get updated:\033[0m\n"
|
printf "\n\033[0;31mContainers with errors, wont get updated:\033[0m\n"
|
||||||
printf "%s\n" "${GotErrors[@]}"
|
printf "%s\n" "${GotErrors[@]}"
|
||||||
fi
|
fi
|
||||||
if [[ -n ${GotUpdates[*]} ]] ; then
|
if [[ -n ${GotUpdates[*]} ]] ; then
|
||||||
printf "\n\033[31;1mContainers with updates available:\033[0m\n"
|
printf "\n\033[0;33mContainers with updates available:\033[0m\n"
|
||||||
[[ -z "$UpdYes" ]] && options || printf "%s\n" "${GotUpdates[@]}"
|
[[ -z "$UpdYes" ]] && options || printf "%s\n" "${GotUpdates[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### Optionally get updates if there's any
|
### Optionally get updates if there's any
|
||||||
if [ -n "$GotUpdates" ] ; then
|
if [ -n "$GotUpdates" ] ; then
|
||||||
if [ -z "$UpdYes" ] ; then
|
if [ -z "$UpdYes" ] ; then
|
||||||
printf "\n\033[36;1mChoose what containers to update.\033[0m\n"
|
printf "\n\033[0;36mChoose what containers to update.\033[0m\n"
|
||||||
choosecontainers
|
choosecontainers
|
||||||
else
|
else
|
||||||
SelectedUpdates=( "${GotUpdates[@]}" )
|
SelectedUpdates=( "${GotUpdates[@]}" )
|
||||||
@@ -156,10 +156,11 @@ if [ -n "$GotUpdates" ] ; then
|
|||||||
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" }}')
|
||||||
ContName=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.service" }}')
|
ContName=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.service" }}')
|
||||||
|
ContEnv=$(docker inspect "$i" --format '{{index .Config.Labels "com.docker.compose.project.environment_file" }}')
|
||||||
|
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
### 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
|
||||||
if [ "$DrUp" == "yes" ] ; then
|
if [ "$DrUp" == "yes" ] ; then
|
||||||
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
|
||||||
docker pull "$ContImage"
|
docker pull "$ContImage"
|
||||||
printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters"
|
printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters"
|
||||||
else
|
else
|
||||||
@@ -175,8 +176,13 @@ 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 "$(dirname "${ComposeFile}")" || { echo "Path error - skipping $i" ; continue ; }
|
cd "$(dirname "${ComposeFile}")" || { echo "Path error - skipping $i" ; continue ; }
|
||||||
$DockerBin -f "$ComposeFile" pull "$ContName"
|
docker pull "$ContImage"
|
||||||
|
### Check if the container got an environment file set, use it if so:
|
||||||
|
if [ -n "$ContEnv" ]; then
|
||||||
|
$DockerBin -f "$ComposeFile" --env-file "$ContEnv" up -d "$ContName"
|
||||||
|
else
|
||||||
$DockerBin -f "$ComposeFile" up -d "$ContName"
|
$DockerBin -f "$ComposeFile" up -d "$ContName"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
printf "\033[0;32mAll done!\033[0m\n"
|
printf "\033[0;32mAll done!\033[0m\n"
|
||||||
[[ -z "$PruneQ" ]] && read -r -p "Would you like to prune dangling images? y/[n]: " PruneQ
|
[[ -z "$PruneQ" ]] && read -r -p "Would you like to prune dangling images? y/[n]: " PruneQ
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
### Requires the regctl binary.
|
|
||||||
### Get it here: https://github.com/regclient/regclient/releases
|
|
||||||
|
|
||||||
### Preferably placed in .bashrc or similar
|
|
||||||
|
|
||||||
### Set the full path to the binary or just regctl if in PATH:
|
|
||||||
regctl="/home/gw-tdc/dockers/regctl"
|
|
||||||
|
|
||||||
dupc () {
|
|
||||||
if [[ "$@" == "help" ]]; then
|
|
||||||
echo "No container name given, here's the list of currently running containers:"
|
|
||||||
docker ps --format '{{.Names}}'
|
|
||||||
else
|
|
||||||
for i in $(docker ps --filter "name=$@" --format '{{.Names}}')
|
|
||||||
do
|
|
||||||
RepoUrl=$(docker inspect $i --format='{{.Config.Image}}')
|
|
||||||
LocalHash=$(docker image inspect $RepoUrl --format '{{.RepoDigests}}')
|
|
||||||
RegHash=$($regctl image digest --list $RepoUrl 2>/dev/null)
|
|
||||||
if [ $? -eq 0 ] ; then
|
|
||||||
if [[ "$LocalHash" = *"$RegHash"* ]] ; then printf "$i is already latest.\n" ; else printf "$i got updates.\n" ; fi
|
|
||||||
else
|
|
||||||
printf "$i got errors, no check possible.\n"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
dupc $1
|
|
||||||
BIN
example.gif
BIN
example.gif
Binary file not shown.
|
Before Width: | Height: | Size: 345 KiB After Width: | Height: | Size: 333 KiB |
Reference in New Issue
Block a user