cron: dockcheck updates itself, and notifies for every container
- Install dockcheck as a git clone in ~/.local/share/dockcheck with AutoSelfUpdate (git pull also updates notify templates and urls.list); no pinned versions. regctl is refreshed weekly by run_dockcheck.sh. - Since dockcheck ~v0.7, OnlyLabel skips unlabelled containers entirely, so they got no update notices. run_dockcheck.sh now runs twice: update labelled containers quietly, then check everything and notify once. - Running dockcheck.sh by hand now checks everything and changes nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a5cdfded37
commit
62cdf879f5
4 files changed
+134
-104
No files matched your search
+23
-15
@@ -11,26 +11,34 @@ jobs on the server, never on the machine running Ansible.
|
|||||||
| 09:10 daily | root | `/usr/local/bin/update_warhammer_feed.sh`: Warhammer RSS feed |
|
| 09:10 daily | root | `/usr/local/bin/update_warhammer_feed.sh`: Warhammer RSS feed |
|
||||||
|
|
||||||
### Dockcheck (container updates)
|
### Dockcheck (container updates)
|
||||||
- Installs [dockcheck](https://github.com/mag37/dockcheck), its Gotify notify
|
- [dockcheck](https://github.com/mag37/dockcheck) is a git clone in
|
||||||
templates, `urls.list` and `regctl` into `/home/phil/.local/bin/`, pinned
|
`/home/phil/.local/share/dockcheck`, linked as `~/.local/bin/dockcheck.sh`.
|
||||||
to `dockcheck_version` and `regctl_version` in `defaults/main.yml`. Bump
|
It updates itself every run (`AutoSelfUpdate`: `git pull`, which also
|
||||||
those and run `bin/deploy --tags cron` to upgrade.
|
updates its notify templates and `urls.list`). Ansible only makes the first
|
||||||
- Templates `/home/phil/.config/dockcheck.config` from `dockcheck.config.j2`
|
clone.
|
||||||
|
- `regctl` (`~/.local/bin/regctl`), which dockcheck uses to query
|
||||||
|
registries, is refreshed weekly from its latest release by
|
||||||
|
`run_dockcheck.sh`.
|
||||||
|
- `/home/phil/.config/dockcheck.config` comes from `dockcheck.config.j2`
|
||||||
(Gotify token from `vault_dockcheck`).
|
(Gotify token from `vault_dockcheck`).
|
||||||
- Settings: `OnlyLabel=true` and `AutoMode=true`, so containers labelled
|
- At 08:00 `run_dockcheck.sh` runs dockcheck twice:
|
||||||
`mag37.dockcheck.update=true` are pulled and recreated automatically; any
|
1. Update run: containers labelled `mag37.dockcheck.update=true` are
|
||||||
other container with an update gets a Gotify notice. `dawarich_db` and
|
pulled and recreated. No notification.
|
||||||
`dawarich_redis` are skipped.
|
2. Check run: every container is checked and one Gotify notice lists the
|
||||||
|
updates still waiting (unlabelled containers, and images held back by
|
||||||
|
`DaysOld`).
|
||||||
- `DaysOld=3`: images newer than 3 days wait for a later run.
|
- `DaysOld=3`: images newer than 3 days wait for a later run.
|
||||||
- `BackupForDays=7`: the replaced image is kept for 7 days for rollback.
|
- `BackupForDays=7`: the replaced image is kept for 7 days for rollback.
|
||||||
List backups with `dockcheck.sh -B` (or `docker images | grep _`);
|
List backups with `dockcheck.sh -B`; to roll back, retag the backup and
|
||||||
to roll back, retag the backup and recreate the container.
|
recreate the container.
|
||||||
- `run_dockcheck.sh` logs to `/var/log/dockcheck/dockcheck.log`, rotated
|
- `dawarich_db` and `dawarich_redis` are skipped.
|
||||||
weekly (a year kept).
|
- Logs go to `/var/log/dockcheck/dockcheck.log`, rotated weekly (a year
|
||||||
|
kept).
|
||||||
|
|
||||||
To see what needs updating by hand, run dockcheck on the server:
|
To see what needs updating by hand (checks everything, changes nothing,
|
||||||
|
sends nothing):
|
||||||
```bash
|
```bash
|
||||||
ssh phil@100.70.169.99 '~/.local/bin/dockcheck.sh -n'
|
ssh phil@100.70.169.99 '~/.local/bin/dockcheck.sh'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Warhammer RSS feed
|
### Warhammer RSS feed
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
# Pinned so a deploy installs a known version. Bump these to upgrade:
|
|
||||||
# https://github.com/mag37/dockcheck/releases
|
|
||||||
# https://github.com/regclient/regclient/releases (regctl, which dockcheck uses to query registries)
|
|
||||||
dockcheck_version: v0.8.3
|
|
||||||
regctl_version: v0.11.7
|
|
||||||
+93
-74
@@ -29,45 +29,70 @@
|
|||||||
owner: phil
|
owner: phil
|
||||||
group: phil
|
group: phil
|
||||||
|
|
||||||
# Install dockcheck in phil's .local/bin, pinned to dockcheck_version.
|
# --- Dockcheck (container updates) ---
|
||||||
# force: a version bump replaces the file (get_url otherwise never re-downloads).
|
# dockcheck lives in a git clone and updates itself on every run
|
||||||
- name: Download dockcheck.sh script
|
# (AutoSelfUpdate does a `git pull`, which also brings new notify templates
|
||||||
get_url:
|
# and urls.list). Ansible only makes the first clone and never resets it.
|
||||||
url: "https://raw.githubusercontent.com/mag37/dockcheck/{{ dockcheck_version }}/dockcheck.sh"
|
- name: Clone dockcheck
|
||||||
dest: /home/phil/.local/bin/dockcheck.sh
|
become_user: phil
|
||||||
force: true
|
git:
|
||||||
mode: '0755'
|
repo: https://github.com/mag37/dockcheck.git
|
||||||
owner: phil
|
dest: /home/phil/.local/share/dockcheck
|
||||||
group: phil
|
version: main
|
||||||
|
update: false
|
||||||
|
|
||||||
# dockcheck only downloads regctl when it's missing, so it never updates by itself
|
# Keep the old path working for running it by hand
|
||||||
- name: Download regctl
|
- name: Link dockcheck.sh into .local/bin
|
||||||
get_url:
|
|
||||||
url: "https://github.com/regclient/regclient/releases/download/{{ regctl_version }}/regctl-linux-amd64"
|
|
||||||
dest: /home/phil/.local/bin/regctl
|
|
||||||
force: true
|
|
||||||
mode: '0755'
|
|
||||||
owner: phil
|
|
||||||
group: phil
|
|
||||||
|
|
||||||
# Release-note links for known images, shown with each update (PrintReleaseURL).
|
|
||||||
# dockcheck reads it from beside dockcheck.sh.
|
|
||||||
- name: Download dockcheck release-note URL list
|
|
||||||
get_url:
|
|
||||||
url: "https://raw.githubusercontent.com/mag37/dockcheck/{{ dockcheck_version }}/notify_templates/urls.list"
|
|
||||||
dest: /home/phil/.local/bin/urls.list
|
|
||||||
force: true
|
|
||||||
mode: '0644'
|
|
||||||
owner: phil
|
|
||||||
group: phil
|
|
||||||
|
|
||||||
# Left over from an old install; dockcheck reads notify_templates/notify_v2.sh
|
|
||||||
- name: Remove stale notify_v2.sh beside dockcheck.sh
|
|
||||||
file:
|
file:
|
||||||
path: /home/phil/.local/bin/notify_v2.sh
|
src: /home/phil/.local/share/dockcheck/dockcheck.sh
|
||||||
|
dest: /home/phil/.local/bin/dockcheck.sh
|
||||||
|
state: link
|
||||||
|
force: true
|
||||||
|
owner: phil
|
||||||
|
group: phil
|
||||||
|
|
||||||
|
# dockcheck reads release-note links from beside dockcheck.sh; upstream keeps
|
||||||
|
# the list in notify_templates/, so link it (and keep git status clean)
|
||||||
|
- name: Link urls.list beside dockcheck.sh
|
||||||
|
file:
|
||||||
|
src: notify_templates/urls.list
|
||||||
|
dest: /home/phil/.local/share/dockcheck/urls.list
|
||||||
|
state: link
|
||||||
|
owner: phil
|
||||||
|
group: phil
|
||||||
|
|
||||||
|
- name: Keep local files out of the dockcheck clone's git status
|
||||||
|
copy:
|
||||||
|
dest: /home/phil/.local/share/dockcheck/.git/info/exclude
|
||||||
|
content: |
|
||||||
|
urls.list
|
||||||
|
snooze.list
|
||||||
|
*.bak
|
||||||
|
owner: phil
|
||||||
|
group: phil
|
||||||
|
mode: '0644'
|
||||||
|
|
||||||
|
# regctl (dockcheck's registry client) isn't updated by dockcheck;
|
||||||
|
# run_dockcheck.sh refreshes it weekly. This only seeds it.
|
||||||
|
- name: Install regctl
|
||||||
|
get_url:
|
||||||
|
url: https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64
|
||||||
|
dest: /home/phil/.local/bin/regctl
|
||||||
|
mode: '0755'
|
||||||
|
owner: phil
|
||||||
|
group: phil
|
||||||
|
|
||||||
|
# Left over from the old download-into-.local/bin install
|
||||||
|
- name: Remove the old dockcheck files from .local/bin
|
||||||
|
file:
|
||||||
|
path: "/home/phil/.local/bin/{{ item }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
loop:
|
||||||
|
- notify_templates
|
||||||
|
- notify_v2.sh
|
||||||
|
- urls.list
|
||||||
|
- snooze.list
|
||||||
|
|
||||||
# Create .config directory for phil user
|
|
||||||
- name: Ensure .config directory exists for phil
|
- name: Ensure .config directory exists for phil
|
||||||
file:
|
file:
|
||||||
path: /home/phil/.config
|
path: /home/phil/.config
|
||||||
@@ -76,36 +101,6 @@
|
|||||||
owner: phil
|
owner: phil
|
||||||
group: phil
|
group: phil
|
||||||
|
|
||||||
# Create notify_templates directory alongside dockcheck.sh
|
|
||||||
- name: Ensure notify_templates directory exists in .local/bin
|
|
||||||
file:
|
|
||||||
path: /home/phil/.local/bin/notify_templates
|
|
||||||
state: directory
|
|
||||||
mode: '0755'
|
|
||||||
owner: phil
|
|
||||||
group: phil
|
|
||||||
|
|
||||||
# Download notify_v2.sh script for dockcheck notifications
|
|
||||||
- name: Download notify_v2.sh script
|
|
||||||
get_url:
|
|
||||||
url: "https://raw.githubusercontent.com/mag37/dockcheck/{{ dockcheck_version }}/notify_templates/notify_v2.sh"
|
|
||||||
dest: /home/phil/.local/bin/notify_templates/notify_v2.sh
|
|
||||||
force: true
|
|
||||||
mode: '0755'
|
|
||||||
owner: phil
|
|
||||||
group: phil
|
|
||||||
|
|
||||||
# Download notify_gotify.sh script for dockcheck notifications
|
|
||||||
- name: Download notify_gotify.sh script
|
|
||||||
get_url:
|
|
||||||
url: "https://raw.githubusercontent.com/mag37/dockcheck/{{ dockcheck_version }}/notify_templates/notify_gotify.sh"
|
|
||||||
dest: /home/phil/.local/bin/notify_templates/notify_gotify.sh
|
|
||||||
force: true
|
|
||||||
mode: '0755'
|
|
||||||
owner: phil
|
|
||||||
group: phil
|
|
||||||
|
|
||||||
# Template dockcheck configuration file
|
|
||||||
- name: Template dockcheck configuration
|
- name: Template dockcheck configuration
|
||||||
template:
|
template:
|
||||||
src: dockcheck.config.j2
|
src: dockcheck.config.j2
|
||||||
@@ -114,7 +109,6 @@
|
|||||||
owner: phil
|
owner: phil
|
||||||
group: phil
|
group: phil
|
||||||
|
|
||||||
# Create log directory for dockcheck
|
|
||||||
- name: Create dockcheck log directory
|
- name: Create dockcheck log directory
|
||||||
file:
|
file:
|
||||||
path: /var/log/dockcheck
|
path: /var/log/dockcheck
|
||||||
@@ -123,7 +117,8 @@
|
|||||||
owner: phil
|
owner: phil
|
||||||
group: phil
|
group: phil
|
||||||
|
|
||||||
# Create dockcheck wrapper script to avoid cron escaping issues
|
# Two runs: update labelled containers quietly, then check everything and
|
||||||
|
# send one Gotify notice for what's left (see dockcheck.config.j2)
|
||||||
- name: Create dockcheck wrapper script
|
- name: Create dockcheck wrapper script
|
||||||
copy:
|
copy:
|
||||||
dest: /home/phil/.local/bin/run_dockcheck.sh
|
dest: /home/phil/.local/bin/run_dockcheck.sh
|
||||||
@@ -132,13 +127,38 @@
|
|||||||
group: phil
|
group: phil
|
||||||
content: |
|
content: |
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
cd /home/phil
|
# Daily container updates (cron, 08:00). Managed by ansible (roles/cron).
|
||||||
/home/phil/.local/bin/dockcheck.sh >> /var/log/dockcheck/dockcheck.log 2>&1
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
# Save the code first: $(date) inside the echo would reset $?
|
log=/var/log/dockcheck/dockcheck.log
|
||||||
code=$?
|
cd "$HOME" || exit 1
|
||||||
echo "$(date "+%Y-%m-%d %H:%M:%S") - Dockcheck completed with exit code $code" >> /var/log/dockcheck/dockcheck.log
|
|
||||||
|
|
||||||
# The log grows by about 3 MB a year; keep a year in weekly files
|
stamp() { date "+%Y-%m-%d %H:%M:%S"; }
|
||||||
|
|
||||||
|
# Refresh regctl weekly from its latest release
|
||||||
|
regctl="$HOME/.local/bin/regctl"
|
||||||
|
if [[ ! -x $regctl || -n $(find "$regctl" -mtime +6) ]]; then
|
||||||
|
tmp=$(mktemp)
|
||||||
|
if curl -fsSL -o "$tmp" https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64 \
|
||||||
|
&& chmod 755 "$tmp" && "$tmp" version >/dev/null; then
|
||||||
|
mv "$tmp" "$regctl"
|
||||||
|
echo "$(stamp) - regctl refreshed: $("$regctl" version --format '{{ "{{" }}.VCSTag{{ "}}" }}')" >> "$log"
|
||||||
|
else
|
||||||
|
rm -f "$tmp"
|
||||||
|
echo "$(stamp) - regctl refresh failed, keeping the current one" >> "$log"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$(stamp) - Update run (labelled containers)" >> "$log"
|
||||||
|
DC_UPDATE=1 "$HOME/.local/bin/dockcheck.sh" >> "$log" 2>&1
|
||||||
|
code=$?
|
||||||
|
echo "$(stamp) - Update run completed with exit code $code" >> "$log"
|
||||||
|
|
||||||
|
echo "$(stamp) - Check run (all containers, notifies)" >> "$log"
|
||||||
|
DC_NOTIFY=1 "$HOME/.local/bin/dockcheck.sh" >> "$log" 2>&1
|
||||||
|
code=$?
|
||||||
|
echo "$(stamp) - Check run completed with exit code $code" >> "$log"
|
||||||
|
|
||||||
|
# The log grows by about 6 MB a year; keep a year in weekly files
|
||||||
- name: Rotate the dockcheck log
|
- name: Rotate the dockcheck log
|
||||||
copy:
|
copy:
|
||||||
dest: /etc/logrotate.d/dockcheck
|
dest: /etc/logrotate.d/dockcheck
|
||||||
@@ -156,7 +176,6 @@
|
|||||||
su phil phil
|
su phil phil
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create cron job for dockcheck as phil user with logging
|
|
||||||
- name: Create cron job for dockcheck container updates
|
- name: Create cron job for dockcheck container updates
|
||||||
cron:
|
cron:
|
||||||
name: "Check Docker container updates"
|
name: "Check Docker container updates"
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
# Dockcheck Configuration (options: default.config in mag37/dockcheck)
|
# Dockcheck configuration (all options: default.config in mag37/dockcheck)
|
||||||
# Auto-updates containers labelled mag37.dockcheck.update=true, and sends a
|
# Managed by ansible (roles/cron). This file is sourced as bash.
|
||||||
# Gotify notice for anything else with an update. Uncomment DontUpdate to
|
#
|
||||||
# only check.
|
# Modes, picked by run_dockcheck.sh with an environment variable:
|
||||||
# DontUpdate=true
|
# DC_UPDATE=1 auto-update containers labelled mag37.dockcheck.update=true,
|
||||||
OnlyLabel=true
|
# no notification
|
||||||
|
# DC_NOTIFY=1 check every container, send one Gotify notice for updates
|
||||||
|
# neither (running dockcheck.sh by hand) check every container, no
|
||||||
|
# updates, no notification
|
||||||
AutoMode=true
|
AutoMode=true
|
||||||
|
if [[ "${DC_UPDATE:-}" == 1 ]]; then
|
||||||
|
OnlyLabel=true
|
||||||
|
else
|
||||||
|
DontUpdate=true
|
||||||
|
fi
|
||||||
|
Notify=$([[ "${DC_NOTIFY:-}" == 1 ]] && echo true || echo false)
|
||||||
|
|
||||||
|
# dockcheck updates itself (git pull in ~/.local/share/dockcheck) each run
|
||||||
|
AutoSelfUpdate=true
|
||||||
|
|
||||||
# Only take an image once it's at least this many days old, so a broken
|
# Only take an image once it's at least this many days old, so a broken
|
||||||
# release has time to be fixed before it's applied unattended. Newer ones are
|
# release has time to be fixed before it's applied unattended. Newer ones are
|
||||||
@@ -25,9 +37,6 @@ MonoMode=true
|
|||||||
# Add release-note links (from urls.list) to each update listed
|
# Add release-note links (from urls.list) to each update listed
|
||||||
PrintReleaseURL=true
|
PrintReleaseURL=true
|
||||||
|
|
||||||
# Enable notifications
|
|
||||||
Notify=true
|
|
||||||
|
|
||||||
# Exclude containers from checking
|
# Exclude containers from checking
|
||||||
Exclude="dawarich_redis,dawarich_db"
|
Exclude="dawarich_redis,dawarich_db"
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user