feat(webhook): redeploy

This commit is contained in:
2026-03-10 21:56:24 +01:00
parent 49c86b1c85
commit 723e2a571a
18 changed files with 100 additions and 78 deletions

View File

@@ -0,0 +1,60 @@
#!/bin/bash
# Auto-update Docker-Compose stacks nach Git-Pull
# Läuft als dockeradmin, prüft geänderte Compose-Dateien
# Stillgelegte Container werden ignoriert
REPO_DIR="/srv/docker"
LOGFILE="/var/log/docker-update.log"
INACTIVE_CONTAINERS=("adguard" "kea" "caddy" "wikijs")
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') | $*" | tee -a "$LOGFILE"
}
log "===== Starting Auto-Update (changed Compose only) ====="
cd "$REPO_DIR" || { log "ERROR: Cannot enter $REPO_DIR"; exit 1; }
# 1⃣ Pull neueste Änderungen
git fetch --all &>/dev/null
git reset --hard origin/main &>/dev/null
log "Pulled latest changes from Git."
# 2⃣ Geänderte Compose-Dateien ermitteln
CHANGED=$(git diff --name-only HEAD~1 HEAD | grep -E '^compose/.+/docker-compose\.yml$' || true)
if [ -z "$CHANGED" ]; then
log "No Compose files changed. Nothing to update."
exit 0
fi
# 3⃣ Nur geänderte Container updaten
for FILE in $CHANGED; do
CONTAINER_NAME=$(echo "$FILE" | cut -d'/' -f2)
# Inaktive Container überspringen
if [[ " ${INACTIVE_CONTAINERS[@]} " =~ " ${CONTAINER_NAME} " ]]; then
log "Skipping inactive container: $CONTAINER_NAME"
continue
fi
COMPOSE_DIR="$REPO_DIR/compose/$CONTAINER_NAME"
if [ ! -d "$COMPOSE_DIR" ]; then
log "Warning: $COMPOSE_DIR does not exist, skipping..."
continue
fi
log "Updating container: $CONTAINER_NAME"
cd "$COMPOSE_DIR" || continue
docker compose pull &>/dev/null
docker compose up -d &>/dev/null
if [ $? -eq 0 ]; then
log "$CONTAINER_NAME updated successfully"
else
log "❌ Failed to update $CONTAINER_NAME"
fi
done
log "===== Auto-Update Completed ====="