Compare commits

..

12 Commits

Author SHA1 Message Date
mag37
e754450300 fixed :tag for pull
Pull did not take tag in account when pulling. Quickfixed it to use the
actual tag of the image of the running container when pulling.
2023-02-23 13:05:06 +01:00
mag37
6ff15f6d97 Update README.md 2023-02-21 21:10:38 +01:00
mag37
cb65d78075 Create dc_brief.sh
A brief version of the script, just checking and listing all running containers with updates / no updates / errors.
2023-02-21 21:08:50 +01:00
mag37
955796c47a Delete dupc_function.sh 2023-02-21 21:04:01 +01:00
mag37
263966dc4a Update README.md
added .env to buglist.
2023-02-20 15:15:52 +01:00
mag37
e877cd826d Merge pull request #25 from mag37/testing_019
added fix for .env
2023-02-20 12:08:34 +01:00
mag37
b78485ed8b version bump
Changed version number to merge with main, also added some margins to
the curl for version.
2023-02-20 11:35:51 +01:00
mag37
fa8edd0443 env-file check, colors
Made a check to see if the compose is started with a env-file, if so use
that file with the compose-command.
2023-02-19 14:21:22 +01:00
mag37
dd6a56da1b new example 2023-02-16 13:51:22 +01:00
mag37
7f30126678 Delete 018vid.gif 2023-02-16 13:50:12 +01:00
mag37
c61dd58858 new example 2023-02-16 13:49:58 +01:00
mag37
61825370dd Delete example.gif 2023-02-16 13:49:22 +01:00
5 changed files with 55 additions and 48 deletions

View File

@@ -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.~~
- ~~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.~~
- ~~Using custom `.env` files does not work.~~
### :hammer: Known issues
- ~~No granular choice of what to update (except initial name filter).~~
- No detailed error feedback (just skip + list what's skipped) .
## `dupc_function.sh`
Function to quickly check for updates on a single contianer or list of containers by name. **Without the need of pulling**.
Preferably placed in `.bashrc` or similar.
Example:
```
$ dupc ng
Updates available for local_nginx.
nginx_reverse is already latest.
Updates available for paperless-ng.
```
## `dc_brief.sh`
Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors.
# 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
View 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

View File

@@ -1,9 +1,9 @@
#!/usr/bin/env bash
VERSION="v0.1.8"
VERSION="v0.1.9"
Github="https://github.com/mag37/dockcheck"
### 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"
### Help Function:
@@ -130,22 +130,22 @@ UpdCount="${#GotUpdates[@]}"
### List what containers got updates or not
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[@]}"
fi
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[@]}"
fi
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[@]}"
fi
### Optionally get updates if there's any
if [ -n "$GotUpdates" ] ; 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
else
SelectedUpdates=( "${GotUpdates[@]}" )
@@ -156,10 +156,11 @@ if [ -n "$GotUpdates" ] ; then
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" }}')
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:
if [ -z "$ContPath" ] ; then
if [ "$DrUp" == "yes" ] ; then
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
docker pull "$ContImage"
printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters"
else
@@ -175,8 +176,13 @@ if [ -n "$GotUpdates" ] ; then
fi
### 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 ; }
$DockerBin -f "$ComposeFile" pull "$ContName"
$DockerBin -f "$ComposeFile" up -d "$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"
fi
done
printf "\033[0;32mAll done!\033[0m\n"
[[ -z "$PruneQ" ]] && read -r -p "Would you like to prune dangling images? y/[n]: " PruneQ

View File

@@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 345 KiB

After

Width:  |  Height:  |  Size: 333 KiB