Improve deploy.sh: show commit details, warn if unpushed
- Display current branch, local/remote main commit with message - Warn if local main is ahead of Gitea remote - Show last 5 commits on main before deploying - Update server address to deployment@217.154.84.225 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
59
deploy.sh
59
deploy.sh
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
# deploy.sh — Deploy main branch to production (vhtv-stiftung.de)
|
||||
# deploy.sh — Deploy main branch to production (217.154.84.225)
|
||||
#
|
||||
# Usage:
|
||||
# ./deploy.sh # Deploy current main to production
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SERVER="${DEPLOY_SERVER:-remmer@vhtv-stiftung.de}"
|
||||
SERVER="${DEPLOY_SERVER:-deployment@217.154.84.225}"
|
||||
PROD_DIR="${DEPLOY_DIR:-/opt/stiftung}"
|
||||
COMPOSE_FILE="compose.yml"
|
||||
DRY_RUN=false
|
||||
@@ -28,9 +28,54 @@ echo "Path: $PROD_DIR"
|
||||
echo "Compose: $COMPOSE_FILE"
|
||||
echo ""
|
||||
|
||||
# Verify local main is up to date with remote
|
||||
LOCAL_MAIN=$(git rev-parse main 2>/dev/null || echo "unknown")
|
||||
echo "Local main: $LOCAL_MAIN"
|
||||
# --- Pre-deploy checks ---
|
||||
CURRENT_BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
|
||||
echo "Aktueller Branch: $CURRENT_BRANCH"
|
||||
|
||||
# Check if main branch exists
|
||||
if ! git rev-parse --verify main &>/dev/null; then
|
||||
echo ""
|
||||
echo "FEHLER: Branch 'main' existiert nicht lokal."
|
||||
echo "Bist du im richtigen Repository?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LOCAL_MAIN=$(git rev-parse --short main 2>/dev/null)
|
||||
LOCAL_MAIN_FULL=$(git rev-parse main 2>/dev/null)
|
||||
echo "Local main: $LOCAL_MAIN ($(git log -1 --format='%s' main 2>/dev/null))"
|
||||
|
||||
# Check if main is pushed to Gitea
|
||||
git fetch origin --quiet 2>/dev/null || true
|
||||
REMOTE_MAIN=$(git rev-parse --short origin/main 2>/dev/null || echo "unknown")
|
||||
echo "Remote main: $REMOTE_MAIN (origin = Gitea)"
|
||||
|
||||
if [[ "$REMOTE_MAIN" != "unknown" && "$LOCAL_MAIN" != "$REMOTE_MAIN" ]]; then
|
||||
UNPUSHED=$(git log --oneline origin/main..main 2>/dev/null | wc -l | tr -d ' ')
|
||||
echo ""
|
||||
echo "WARNUNG: Local main ist $UNPUSHED Commit(s) vor origin/main!"
|
||||
echo "Du musst erst 'git push origin main' ausführen, sonst deployed der Server den alten Stand."
|
||||
if [[ "$DRY_RUN" != true ]]; then
|
||||
echo ""
|
||||
read -p "Trotzdem fortfahren? [y/N] " -n 1 -r
|
||||
echo ""
|
||||
[[ $REPLY =~ ^[Yy]$ ]] || exit 0
|
||||
fi
|
||||
elif [[ "$REMOTE_MAIN" == "unknown" ]]; then
|
||||
echo ""
|
||||
echo "WARNUNG: Konnte Gitea-Remote nicht erreichen. Status unbekannt."
|
||||
fi
|
||||
|
||||
# Show what the server will get
|
||||
echo ""
|
||||
echo "Der Server wird diesen Stand deployen:"
|
||||
echo " Commit: $LOCAL_MAIN"
|
||||
echo " $(git log -1 --format='%ai — %s' main 2>/dev/null)"
|
||||
RECENT_COMMITS=$(git log --oneline -5 main 2>/dev/null)
|
||||
if [[ -n "$RECENT_COMMITS" ]]; then
|
||||
echo ""
|
||||
echo "Letzte 5 Commits auf main:"
|
||||
echo "$RECENT_COMMITS" | sed 's/^/ /'
|
||||
fi
|
||||
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
echo ""
|
||||
@@ -45,10 +90,10 @@ if [[ "$DRY_RUN" == true ]]; then
|
||||
fi
|
||||
|
||||
echo ""
|
||||
read -p "Deploy main ($LOCAL_MAIN) to production? [y/N] " -n 1 -r
|
||||
read -p "Deploy main ($LOCAL_MAIN) auf Produktion? [y/N] " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Aborted."
|
||||
echo "Abgebrochen."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user