feat(webhook): redeploy

This commit is contained in:
2026-03-10 22:14:21 +01:00
parent 723e2a571a
commit 99c12fe33a

View File

@@ -1,35 +1,37 @@
#!/bin/bash #!/bin/bash
# Auto-update Docker-Compose stacks nach Git-Pull # Auto-Restart Script für geänderte Docker-Compose Stacks
# Läuft als dockeradmin, prüft geänderte Compose-Dateien # Nur laufende, aktive Container werden neu gestartet
# Stillgelegte Container werden ignoriert # Inaktive Container bleiben unberührt
# Logs im Repo-Verzeichnis
REPO_DIR="/srv/docker" REPO_DIR="/srv/docker"
LOGFILE="/var/log/docker-update.log" LOGFILE="$REPO_DIR/scripts/docker-update.log"
INACTIVE_CONTAINERS=("adguard" "kea" "caddy" "wikijs") # Liste der inaktiven Container
INACTIVE_CONTAINERS=("adguard" "kea" "caddy")
log() { log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') | $*" | tee -a "$LOGFILE" echo "$(date '+%Y-%m-%d %H:%M:%S') | $*" | tee -a "$LOGFILE"
} }
log "===== Starting Auto-Update (changed Compose only) =====" log "===== Starting Auto-Restart (final) ====="
cd "$REPO_DIR" || { log "ERROR: Cannot enter $REPO_DIR"; exit 1; } cd "$REPO_DIR" || { log "ERROR: Cannot enter $REPO_DIR"; exit 1; }
# 1⃣ Pull neueste Änderungen # 1 Git Pull + Hard Reset (VM exakt auf Remote-Stand bringen)
git fetch --all &>/dev/null git fetch --all &>/dev/null
git reset --hard origin/main &>/dev/null git reset --hard origin/main &>/dev/null
log "Pulled latest changes from Git." log "Pulled latest changes and reset VM to remote state."
# 2⃣ Geänderte Compose-Dateien ermitteln # 2⃣ Geänderte Compose-Dateien ermitteln
CHANGED=$(git diff --name-only HEAD~1 HEAD | grep -E '^compose/.+/docker-compose\.yml$' || true) CHANGED=$(git diff --name-only HEAD~1 HEAD | grep -E '^compose/.+/docker-compose\.yml$' || true)
if [ -z "$CHANGED" ]; then if [ -z "$CHANGED" ]; then
log "No Compose files changed. Nothing to update." log "No Compose files changed. Nothing to restart."
exit 0 exit 0
fi fi
# 3⃣ Nur geänderte Container updaten # 3⃣ Nur laufende, geänderte Container neu starten
for FILE in $CHANGED; do for FILE in $CHANGED; do
CONTAINER_NAME=$(echo "$FILE" | cut -d'/' -f2) CONTAINER_NAME=$(echo "$FILE" | cut -d'/' -f2)
@@ -45,16 +47,22 @@ for FILE in $CHANGED; do
continue continue
fi fi
log "Updating container: $CONTAINER_NAME" # Prüfen, ob Container läuft
cd "$COMPOSE_DIR" || continue RUNNING=$(docker compose -f "$COMPOSE_DIR/docker-compose.yml" ps -q)
docker compose pull &>/dev/null if [ -z "$RUNNING" ]; then
docker compose up -d &>/dev/null log "Container $CONTAINER_NAME is stopped. Skipping restart."
continue
fi
log "Restarting running container: $CONTAINER_NAME"
cd "$COMPOSE_DIR" || continue
docker compose up -d &>/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
log "$CONTAINER_NAME updated successfully" log "$CONTAINER_NAME restarted successfully"
else else
log "❌ Failed to update $CONTAINER_NAME" log "❌ Failed to restart $CONTAINER_NAME"
fi fi
done done
log "===== Auto-Update Completed =====" log "===== Auto-Restart Completed ====="