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
+93
-74
@@ -29,45 +29,70 @@
|
||||
owner: phil
|
||||
group: phil
|
||||
|
||||
# Install dockcheck in phil's .local/bin, pinned to dockcheck_version.
|
||||
# force: a version bump replaces the file (get_url otherwise never re-downloads).
|
||||
- name: Download dockcheck.sh script
|
||||
get_url:
|
||||
url: "https://raw.githubusercontent.com/mag37/dockcheck/{{ dockcheck_version }}/dockcheck.sh"
|
||||
dest: /home/phil/.local/bin/dockcheck.sh
|
||||
force: true
|
||||
mode: '0755'
|
||||
owner: phil
|
||||
group: phil
|
||||
# --- Dockcheck (container updates) ---
|
||||
# dockcheck lives in a git clone and updates itself on every run
|
||||
# (AutoSelfUpdate does a `git pull`, which also brings new notify templates
|
||||
# and urls.list). Ansible only makes the first clone and never resets it.
|
||||
- name: Clone dockcheck
|
||||
become_user: phil
|
||||
git:
|
||||
repo: https://github.com/mag37/dockcheck.git
|
||||
dest: /home/phil/.local/share/dockcheck
|
||||
version: main
|
||||
update: false
|
||||
|
||||
# dockcheck only downloads regctl when it's missing, so it never updates by itself
|
||||
- name: Download regctl
|
||||
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
|
||||
# Keep the old path working for running it by hand
|
||||
- name: Link dockcheck.sh into .local/bin
|
||||
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
|
||||
loop:
|
||||
- notify_templates
|
||||
- notify_v2.sh
|
||||
- urls.list
|
||||
- snooze.list
|
||||
|
||||
# Create .config directory for phil user
|
||||
- name: Ensure .config directory exists for phil
|
||||
file:
|
||||
path: /home/phil/.config
|
||||
@@ -76,36 +101,6 @@
|
||||
owner: 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
|
||||
template:
|
||||
src: dockcheck.config.j2
|
||||
@@ -114,7 +109,6 @@
|
||||
owner: phil
|
||||
group: phil
|
||||
|
||||
# Create log directory for dockcheck
|
||||
- name: Create dockcheck log directory
|
||||
file:
|
||||
path: /var/log/dockcheck
|
||||
@@ -123,7 +117,8 @@
|
||||
owner: 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
|
||||
copy:
|
||||
dest: /home/phil/.local/bin/run_dockcheck.sh
|
||||
@@ -132,13 +127,38 @@
|
||||
group: phil
|
||||
content: |
|
||||
#!/bin/bash
|
||||
cd /home/phil
|
||||
/home/phil/.local/bin/dockcheck.sh >> /var/log/dockcheck/dockcheck.log 2>&1
|
||||
# Save the code first: $(date) inside the echo would reset $?
|
||||
code=$?
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") - Dockcheck completed with exit code $code" >> /var/log/dockcheck/dockcheck.log
|
||||
# Daily container updates (cron, 08:00). Managed by ansible (roles/cron).
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
log=/var/log/dockcheck/dockcheck.log
|
||||
cd "$HOME" || exit 1
|
||||
|
||||
# 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
|
||||
copy:
|
||||
dest: /etc/logrotate.d/dockcheck
|
||||
@@ -156,7 +176,6 @@
|
||||
su phil phil
|
||||
}
|
||||
|
||||
# Create cron job for dockcheck as phil user with logging
|
||||
- name: Create cron job for dockcheck container updates
|
||||
cron:
|
||||
name: "Check Docker container updates"
|
||||
|
||||
Reference in new issue
Block a user