mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-18 02:17:46 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ecc354663 | ||
|
|
4a2daa9899 | ||
|
|
ae8a232a1a | ||
|
|
abbb924867 | ||
|
|
05d21a707a | ||
|
|
4817d75d94 | ||
|
|
32f6d428d3 | ||
|
|
4a8afde790 | ||
|
|
ae53fe2cc7 | ||
|
|
722fb90ce2 | ||
|
|
18947a462d | ||
|
|
0887025412 |
51
README.md
51
README.md
@@ -17,19 +17,21 @@
|
|||||||
|
|
||||||
___
|
___
|
||||||
## :bell: Changelog
|
## :bell: Changelog
|
||||||
|
|
||||||
|
- **v0.3.7**: Added support for [labels](#bookmark-labels), added the `-f` option (force restart stack).
|
||||||
|
- **v0.3.6**: Added pushbullet template.
|
||||||
- **v0.3.5**: Added a simple progress bar for the registry checkup.
|
- **v0.3.5**: Added a simple progress bar for the registry checkup.
|
||||||
- **v0.3.4**: Added ntfy.sh template and error message on registry fail.
|
- **v0.3.4**: Added ntfy.sh template and error message on registry fail.
|
||||||
- **v0.3.3**: Added Apprise template and the option `-i` inform - to send notifications.
|
- **v0.3.3**: Added Apprise template and the option `-i` inform - to send notifications.
|
||||||
- **v0.3.2**: Added a notify function to wrap a notify-script, currently DSM/Ssmtp + template script.
|
- **v0.3.2**: Added a notify function to wrap a notify-script, currently DSM/Ssmtp + template script.
|
||||||
- **v0.3.1**: Addded option `-m` , monochrome mode - no printf color codes.
|
|
||||||
- **v0.3.0**: Added option `-d N`, age (days) new images have to be before being pulled and updated.
|
|
||||||
___
|
___
|
||||||
|
|
||||||
## :nut_and_bolt: Dependencies
|
## :nut_and_bolt: Dependencies
|
||||||
- Running docker (duh) and compose, either standalone or plugin.
|
- Running docker (duh) and compose, either standalone or plugin.
|
||||||
- [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))
|
||||||
- User will be prompted to download `regctl` if not in `PATH` or `PWD`.
|
- User will be prompted to download `regctl` if not in `PATH` or `PWD`.
|
||||||
- regctl requires `amd64/arm64` - see [workaround](#workaround-for-non-amd64--arm64) if other architecture is used.
|
- regctl requires `amd64/arm64` - see [workaround](#roller_coaster-workaround-for-non-amd64--arm64) if other architecture is used.
|
||||||
___
|
___
|
||||||
|
|
||||||
|
|
||||||
@@ -38,22 +40,25 @@ ___
|
|||||||
## :mag_right: `dockcheck.sh`
|
## :mag_right: `dockcheck.sh`
|
||||||
```
|
```
|
||||||
$ ./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 -y -d 10 -e nextcloud,heimdall
|
Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall
|
||||||
|
|
||||||
Options:
|
Options:"
|
||||||
-a|y Automatic updates, without interaction.
|
-a|y Automatic updates, without interaction.
|
||||||
-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower.
|
-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower.
|
||||||
-e X Exclude containers, separated by comma.
|
-e X Exclude containers, separated by comma.
|
||||||
-h Print this Help.
|
-f Force stack restart after update. Caution: restarts once for every updated container within stack.
|
||||||
-i Inform - send a preconfigured notification.
|
-h Print this Help.
|
||||||
-m Monochrome mode, no printf color codes.
|
-i Inform - send a preconfigured notification.
|
||||||
-n No updates, only checking availability.
|
-l Only update if label is set. See readme.
|
||||||
-p Auto-Prune dangling images after update.
|
-m Monochrome mode, no printf color codes.
|
||||||
-r Allow updating images for docker run, wont update the container.
|
-n No updates, only checking availability.
|
||||||
-s Include stopped containers in the check. (Logic: docker ps -a)
|
-p Auto-Prune dangling images after update.
|
||||||
|
-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:
|
||||||
```
|
```
|
||||||
$ ./dockcheck.sh
|
$ ./dockcheck.sh
|
||||||
@@ -84,10 +89,22 @@ Current templates:
|
|||||||
- Apprise (with it's [multitude](https://github.com/caronc/apprise#supported-notifications) of notifications)
|
- Apprise (with it's [multitude](https://github.com/caronc/apprise#supported-notifications) of notifications)
|
||||||
- both native [caronc/apprise](https://github.com/caronc/apprise) and the standalone [linuxserver/docker-apprise-api](https://github.com/linuxserver/docker-apprise-api)
|
- both native [caronc/apprise](https://github.com/caronc/apprise) and the standalone [linuxserver/docker-apprise-api](https://github.com/linuxserver/docker-apprise-api)
|
||||||
- Read the [QuickStart](extras/apprise_quickstart.md)
|
- Read the [QuickStart](extras/apprise_quickstart.md)
|
||||||
|
- [ntfy.sh](https://ntfy.sh/) - HTTP-based pub-sub notifications.
|
||||||
|
- [Pushbullet](https://www.pushbullet.com/) - connecting different devices with cross-platform features.
|
||||||
|
|
||||||
Further additions are welcome - suggestions or PR!
|
Further additions are welcome - suggestions or PR!
|
||||||
<sub><sup>Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).</sup></sub>
|
<sub><sup>Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).</sup></sub>
|
||||||
|
|
||||||
|
## :bookmark: Labels
|
||||||
|
Optionally add labels to compose-files. Currently these are the usable labels:
|
||||||
|
```
|
||||||
|
labels:
|
||||||
|
mag37.dockcheck.restart-stack: true
|
||||||
|
mag37.dockcheck.update: true
|
||||||
|
```
|
||||||
|
- `mag37.dockcheck.restart-stack: true` works instead of the `-f` option, forcing stop+restart on the whole compose-stack (Caution: Will restart on every updated container within stack).
|
||||||
|
- `mag37.dockcheck.update: true` will when used with the `-l` option only update containers with this label and skip the rest. Will still list updates as usual.
|
||||||
|
|
||||||
## :roller_coaster: Workaround for non **amd64** / **arm64**
|
## :roller_coaster: Workaround for non **amd64** / **arm64**
|
||||||
`regctl` provides binaries for amd64/arm64, to use on other architecture you could try this workaround.
|
`regctl` provides binaries for amd64/arm64, to use on other architecture you could try this workaround.
|
||||||
Run regctl in a container wrapped in a shell script. Copied from [regclient/docs/install.md](https://github.com/regclient/regclient/blob/main/docs/install.md):
|
Run regctl in a container wrapped in a shell script. Copied from [regclient/docs/install.md](https://github.com/regclient/regclient/blob/main/docs/install.md):
|
||||||
@@ -121,7 +138,7 @@ Containers need to be manually stopped, removed and created again to run on the
|
|||||||
## :scroll: License
|
## :scroll: 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.
|
||||||
|
|
||||||
### :floppy_disk: The [story](https://mag37.org/posts/project_dockcheck/) behind it. 1 year in the mirror.
|
### :floppy_disk: The [story](https://mag37.org/posts/project_dockcheck/) behind it. 1 year in retrospect.
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
|
|||||||
29
dockcheck.sh
29
dockcheck.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
VERSION="v0.3.5"
|
VERSION="v0.3.7"
|
||||||
### ChangeNotes: Added a simple handcrafted progress bar.
|
### ChangeNotes: Added label support (see readme) and -f (force restart stack) option.
|
||||||
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"
|
||||||
|
|
||||||
@@ -24,8 +24,10 @@ Help() {
|
|||||||
echo "-a|y Automatic updates, without interaction."
|
echo "-a|y Automatic updates, without interaction."
|
||||||
echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower."
|
echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower."
|
||||||
echo "-e X Exclude containers, separated by comma."
|
echo "-e X Exclude containers, separated by comma."
|
||||||
|
echo "-f Force stack restart after update. Caution: restarts once for every updated container within stack."
|
||||||
echo "-h Print this Help."
|
echo "-h Print this Help."
|
||||||
echo "-i Inform - send a preconfigured notification."
|
echo "-i Inform - send a preconfigured notification."
|
||||||
|
echo "-l Only update if label is set. See readme."
|
||||||
echo "-m Monochrome mode, no printf color codes."
|
echo "-m Monochrome mode, no printf color codes."
|
||||||
echo "-n No updates, only checking availability."
|
echo "-n No updates, only checking availability."
|
||||||
echo "-p Auto-Prune dangling images after update."
|
echo "-p Auto-Prune dangling images after update."
|
||||||
@@ -42,12 +44,14 @@ c_teal="\033[0;36m"
|
|||||||
c_reset="\033[0m"
|
c_reset="\033[0m"
|
||||||
|
|
||||||
Stopped=""
|
Stopped=""
|
||||||
while getopts "aynprhisme:d:" options; do
|
while getopts "aynpfrhlisme:d:" options; do
|
||||||
case "${options}" in
|
case "${options}" in
|
||||||
a|y) AutoUp="yes" ;;
|
a|y) AutoUp="yes" ;;
|
||||||
n) AutoUp="no" ;;
|
n) AutoUp="no" ;;
|
||||||
r) DRunUp="yes" ;;
|
r) DRunUp="yes" ;;
|
||||||
p) AutoPrune="yes" ;;
|
p) AutoPrune="yes" ;;
|
||||||
|
l) OnlyLabel=true ;;
|
||||||
|
f) ForceRestartStacks=true ;;
|
||||||
i) [ -s $ScriptWorkDir/notify.sh ] && { source $ScriptWorkDir/notify.sh ; Notify="yes" ; } ;;
|
i) [ -s $ScriptWorkDir/notify.sh ] && { source $ScriptWorkDir/notify.sh ; Notify="yes" ; } ;;
|
||||||
e) Exclude=${OPTARG} ;;
|
e) Exclude=${OPTARG} ;;
|
||||||
m) declare c_{red,green,yellow,blue,teal,reset}="" ;;
|
m) declare c_{red,green,yellow,blue,teal,reset}="" ;;
|
||||||
@@ -275,6 +279,8 @@ if [ -n "$GotUpdates" ] ; then
|
|||||||
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" }}')
|
ContEnv=$(docker inspect "$i" --format '{{index .Config.Labels "com.docker.compose.project.environment_file" }}')
|
||||||
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
|
||||||
|
ContUpdateLabel=$(docker inspect "$i" --format '{{ index .Config.Labels "mag37.dockcheck.update" }}')
|
||||||
|
ContRestartStack=$(docker inspect "$i" --format '{{ index .Config.Labels "mag37.dockcheck.restart-stack" }}')
|
||||||
### 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 [ "$DRunUp" == "yes" ] ; then
|
if [ "$DRunUp" == "yes" ] ; then
|
||||||
@@ -294,16 +300,25 @@ if [ -n "$GotUpdates" ] ; then
|
|||||||
### 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%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset"
|
printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset"
|
||||||
|
### Checking if Label Only -option is set, and if container got the label
|
||||||
|
[[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != true ]] && { echo "No label, skipping" ; continue ; } }
|
||||||
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
|
||||||
for conf in "${Confs[@]}"; do CompleteConfs+="-f $conf " ; done
|
for conf in "${Confs[@]}"; do CompleteConfs+="-f $conf " ; done
|
||||||
|
|
||||||
### Check if the container got an environment file set, use it if so:
|
### Check if the container got an environment file set, use it if so:
|
||||||
if [ -n "$ContEnv" ]; then
|
if [ -n "$ContEnv" ]; then # also checking if stack should be restarted
|
||||||
$DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d "$ContName" # unquoted array to allow split - rework?
|
if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]] ; then
|
||||||
|
$DockerBin ${CompleteConfs[@]} stop ; $DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d
|
||||||
|
else
|
||||||
|
$DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d "$ContName" # unquoted array to allow split - rework?
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
$DockerBin ${CompleteConfs[@]} up -d "$ContName" # unquoted array to allow split - rework?
|
if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]] ; then
|
||||||
|
$DockerBin ${CompleteConfs[@]} stop ; $DockerBin ${CompleteConfs[@]} up -d
|
||||||
|
else
|
||||||
|
$DockerBin ${CompleteConfs[@]} up -d "$ContName"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
|
printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
|
||||||
|
|||||||
27
notify_pushbullet.sh
Normal file
27
notify_pushbullet.sh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||||
|
#
|
||||||
|
# Copy/rename this file to notify.sh to enable the notification snippet.
|
||||||
|
# Required receiving services must already be set up.
|
||||||
|
# Requires jq installed and in PATH.
|
||||||
|
# Modify to fit your setup - set Url and Token.
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
Updates=("$@")
|
||||||
|
UpdToString=$( printf "%s\n" "${Updates[@]}" )
|
||||||
|
FromHost=$(hostname)
|
||||||
|
|
||||||
|
# platform specific notification code would go here
|
||||||
|
printf "\nSending pushbullet notification\n"
|
||||||
|
|
||||||
|
MessageTitle="$FromHost - updates available."
|
||||||
|
# Setting the MessageBody variable here.
|
||||||
|
MessageBody="Containers on $FromHost with updates available: $UpdToString"
|
||||||
|
|
||||||
|
# Modify to fit your setup:
|
||||||
|
PushUrl="https://api.pushbullet.com/v2/pushes"
|
||||||
|
PushToken="Your Pushbullet token here"
|
||||||
|
|
||||||
|
# Requires jq to process json data
|
||||||
|
jq -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -sS -o /dev/null --show-error --fail -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user