2026-06-09 19:42:25 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
|
STACKS_DIR="$(dirname "$SCRIPT_DIR")"
|
|
|
|
|
LOG_FILE="$SCRIPT_DIR/update.log"
|
|
|
|
|
|
|
|
|
|
set -a; source "$SCRIPT_DIR/.env"; set +a
|
|
|
|
|
|
|
|
|
|
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"; }
|
|
|
|
|
notify() {
|
|
|
|
|
local color="$1" text="$2"
|
|
|
|
|
curl -sf -o /dev/null -X POST "$WEBHOOK_URL" \
|
|
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
|
-d "{\"message\":\"$text\",\"color\":\"$color\"}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
: > "$LOG_FILE"
|
|
|
|
|
log "Starting image update check"
|
|
|
|
|
|
2026-06-12 07:58:55 +02:00
|
|
|
updated=(); failed=(); checked=0
|
2026-06-09 19:42:25 +02:00
|
|
|
|
|
|
|
|
for stack_dir in "$STACKS_DIR"/*/; do
|
|
|
|
|
stack=$(basename "$stack_dir")
|
|
|
|
|
[[ "$stack" == _* ]] && continue
|
|
|
|
|
[[ ! -f "$stack_dir/compose.yml" ]] && continue
|
|
|
|
|
|
|
|
|
|
log "Checking $stack"
|
|
|
|
|
cd "$stack_dir"
|
2026-06-12 07:58:55 +02:00
|
|
|
checked=$((checked + 1))
|
2026-06-09 19:42:25 +02:00
|
|
|
|
2026-06-12 07:58:55 +02:00
|
|
|
before=$(docker compose images -q 2>/dev/null | sort)
|
|
|
|
|
docker compose pull 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
|
after=$(docker compose images -q 2>/dev/null | sort)
|
|
|
|
|
|
|
|
|
|
if [ "$before" != "$after" ]; then
|
2026-06-09 19:42:25 +02:00
|
|
|
log " Updates found — recreating containers"
|
|
|
|
|
if docker compose up -d 2>&1 | tee -a "$LOG_FILE"; then
|
|
|
|
|
updated+=("$stack")
|
|
|
|
|
else
|
|
|
|
|
log " FAILED to recreate $stack"
|
|
|
|
|
failed+=("$stack")
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
log " Up to date"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
log "Pruning dangling images"
|
|
|
|
|
docker image prune -f 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
|
|
2026-06-12 07:58:55 +02:00
|
|
|
date_str=$(date '+%Y-%m-%d %H:%M')
|
|
|
|
|
|
|
|
|
|
if [ ${#failed[@]} -gt 0 ]; then
|
|
|
|
|
notify "#cc0000" "❌ **Update failed** — $date_str\nUpdated: ${updated[*]:-none}\nFailed: ${failed[*]}"
|
|
|
|
|
elif [ ${#updated[@]} -gt 0 ]; then
|
|
|
|
|
notify "#36a64f" "✅ **Updates applied** — $date_str\nStacks updated (${#updated[@]}/$checked): ${updated[*]}"
|
2026-06-09 19:42:25 +02:00
|
|
|
else
|
2026-06-12 07:58:55 +02:00
|
|
|
notify "#36a64f" "✅ **All up to date** — $date_str ($checked stacks checked)"
|
2026-06-09 19:42:25 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
log "Update check complete"
|