Files
eldov-win/deploy-vps.sh
T

67 lines
2.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# deploy-vps.sh — Synchronisiert den eldov-win Workspace auf den VPS-Container.
# Host: free-warez.win · Container-Pfad: /opt/containers/eldov-portfolio
#
# eldov.win läuft auf demselben VPS wie w-make.com und minecraft-portal.
# Traefik routet dort die Subdomains per Docker-Labels.
#
# Voraussetzungen:
# - ssh-Zugang zu free-warez.win ist konfiguriert
# - .env.local ist lokal vorhanden (wird NICHT übertragen)
# - auf dem VPS liegt bereits ein Container namens 'eldov-portfolio'
set -euo pipefail
VPS_HOST="${VPS_HOST:-free-warez.win}"
VPS_DIR="${VPS_DIR:-/opt/containers/eldov-portfolio}"
# 1. Check SSH connection
echo "→ Prüfe SSH-Verbindung zu $VPS_HOST..."
if ! ssh -q -o BatchMode=yes -o ConnectTimeout=10 "$VPS_HOST" exit; then
echo "❌ Keine SSH-Verbindung zu $VPS_HOST möglich."
exit 1
fi
# 2. Push git commits if in git repo
LOCAL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -d "$LOCAL_DIR/.git" ]; then
echo "→ Prüfe Git-Status..."
if ! git -C "$LOCAL_DIR" diff-index --quiet HEAD -- 2>/dev/null; then
echo "⚠️ Lokale uncommitted Änderungen vorhanden."
fi
echo "→ Pushe Commits nach Gitea..."
git -C "$LOCAL_DIR" push origin main 2>/dev/null || echo "️ Git push übersprungen oder bereits aktuell."
fi
echo "→ Synchronisiere Quelldateien nach $VPS_HOST:$VPS_DIR"
rsync -avz --delete \
--exclude ".git" \
--exclude "node_modules" \
--exclude ".next" \
--exclude "data" \
--exclude ".env.local" \
--exclude "*.log" \
./ "$VPS_HOST:$VPS_DIR/"
echo "→ Baue und starte Container auf $VPS_HOST neu"
ssh "$VPS_HOST" "cd '$VPS_DIR' && \
[ -f .env.local ] || { echo 'FEHLT: .env.local auf dem VPS — bitte anlegen'; exit 1; } && \
docker compose build app && \
docker compose up -d app && \
docker image prune -f"
echo "✓ Deploy abgeschlossen. Healthcheck in 5 s…"
sleep 5
echo -n " Docker Health: "
ssh "$VPS_HOST" "docker inspect --format='{{if .State.Health}}{{.State.Health.Status}}{{else}}no healthcheck{{end}}' eldov-portfolio"
echo -n " Public URL (https://eldov.win): "
if curl -fs -o /dev/null --resolve eldov.win:443:217.160.217.196 -m 5 "https://eldov.win/"; then
echo "✅ 200 OK"
else
echo "⚠️ Nicht erreichbar"
fi
echo "✨ Deployment erfolgreich beendet!"