chore(deploy): entkoppelte Self-Update-Skripte pro Server
Jeder Server aktualisiert sich eigenstaendig aus dem Repo – kein
Cross-Server-SSH, kein "both". 137 und 164 komplett getrennt.
- server-update.sh: laeuft AUF dem Server (git pull --ff-only → alembic
upgrade head → restart → health). Guard: bricht ab wenn venv fehlt.
- push-frontend.sh: lokal, baut Frontend + rsync dist/ an EINEN Server
(Node laeuft nicht auf den Servern, dist ist gitignored). Guard gegen
Ausfuehrung auf einem Zielserver.
- deploy.sh + update.sh stillgelegt (Abbruch-Stubs): deploy.sh rsyncte den
Arbeitsbaum in den Server-git-Baum und verschmutzte ihn (git pull brach);
update.sh koppelte beide Server ("both").
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,107 +1,14 @@
|
||||
#!/bin/bash
|
||||
# ============================================================
|
||||
# deploy.sh – Lokal ausführen, deployt auf 192.168.1.137
|
||||
# Usage:
|
||||
# ./deploy.sh → nur sync + restart
|
||||
# ./deploy.sh --migrate → sync + alembic upgrade + restart
|
||||
# ./deploy.sh --setup → erstes Setup auf dem Server
|
||||
# ============================================================
|
||||
set -e
|
||||
|
||||
SERVER="root@192.168.1.137"
|
||||
REMOTE="/opt/timemaster"
|
||||
LOCAL="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
log() { echo -e "${GREEN}==>${NC} $1"; }
|
||||
warn() { echo -e "${YELLOW}[!]${NC} $1"; }
|
||||
|
||||
# ── Erstes Setup ──────────────────────────────────────────────────────────────
|
||||
if [[ "$1" == "--setup" ]]; then
|
||||
log "Erstes Server-Setup wird ausgeführt..."
|
||||
|
||||
ssh "$SERVER" "apt-get update -q && apt-get install -y \
|
||||
python3.12 python3.12-venv python3.12-dev \
|
||||
postgresql postgresql-contrib \
|
||||
redis-server nginx \
|
||||
git build-essential libpq-dev curl"
|
||||
|
||||
ssh "$SERVER" "mkdir -p $REMOTE/backend $REMOTE/frontend/dist"
|
||||
|
||||
log "Dateien übertragen..."
|
||||
rsync -avz --exclude='__pycache__' --exclude='*.pyc' --exclude='.env' \
|
||||
--exclude='venv/' --exclude='.git/' \
|
||||
"$LOCAL/" "$SERVER:$REMOTE/"
|
||||
|
||||
ssh "$SERVER" bash << 'REMOTE_SETUP'
|
||||
set -e
|
||||
cd /opt/timemaster/backend
|
||||
|
||||
# venv
|
||||
python3.12 -m venv venv
|
||||
source venv/bin/activate
|
||||
pip install --upgrade pip -q
|
||||
pip install -r requirements.txt -q
|
||||
|
||||
# PostgreSQL
|
||||
systemctl enable --now postgresql
|
||||
sudo -u postgres psql -tc "SELECT 1 FROM pg_roles WHERE rolname='timemaster'" | grep -q 1 || \
|
||||
sudo -u postgres psql -c "CREATE ROLE timemaster LOGIN PASSWORD 'timemaster_secret_CHANGE_ME';"
|
||||
sudo -u postgres psql -tc "SELECT 1 FROM pg_database WHERE datname='timemaster_db'" | grep -q 1 || \
|
||||
sudo -u postgres psql -c "CREATE DATABASE timemaster_db OWNER timemaster;"
|
||||
|
||||
# Redis
|
||||
systemctl enable --now redis-server
|
||||
|
||||
# .env
|
||||
if [ ! -f .env ]; then
|
||||
cp .env.example .env
|
||||
echo ""
|
||||
echo "⚠️ WICHTIG: .env auf dem Server anpassen!"
|
||||
echo " ssh root@192.168.1.137 'nano /opt/timemaster/backend/.env'"
|
||||
fi
|
||||
|
||||
# systemd service
|
||||
cp /opt/timemaster/timemaster.service /etc/systemd/system/
|
||||
systemctl daemon-reload
|
||||
|
||||
echo "✓ Setup abgeschlossen"
|
||||
echo "Nächster Schritt: .env befüllen, dann: ./deploy.sh --migrate"
|
||||
REMOTE_SETUP
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ── Normaler Deploy ───────────────────────────────────────────────────────────
|
||||
log "Sync → $SERVER:$REMOTE/backend"
|
||||
rsync -avz --progress \
|
||||
--exclude='__pycache__' \
|
||||
--exclude='*.pyc' \
|
||||
--exclude='.env' \
|
||||
--exclude='venv/' \
|
||||
--exclude='.git/' \
|
||||
--exclude='tests/' \
|
||||
"$LOCAL/backend/" "$SERVER:$REMOTE/backend/"
|
||||
|
||||
# Frontend build + sync (falls vorhanden)
|
||||
if [ -d "$LOCAL/frontend/dist" ]; then
|
||||
log "Frontend sync..."
|
||||
rsync -avz "$LOCAL/frontend/dist/" "$SERVER:$REMOTE/frontend/dist/"
|
||||
fi
|
||||
|
||||
# ── Migration (optional) ──────────────────────────────────────────────────────
|
||||
if [[ "$1" == "--migrate" ]]; then
|
||||
log "Alembic upgrade head..."
|
||||
ssh "$SERVER" "cd $REMOTE/backend && source venv/bin/activate && alembic upgrade head"
|
||||
fi
|
||||
|
||||
# ── Service neu starten ───────────────────────────────────────────────────────
|
||||
log "Service restart..."
|
||||
ssh "$SERVER" "systemctl restart timemaster && sleep 2 && systemctl is-active timemaster"
|
||||
|
||||
log "Logs (letzte 20 Zeilen):"
|
||||
ssh "$SERVER" "journalctl -u timemaster -n 20 --no-pager"
|
||||
|
||||
log "✓ Deploy abgeschlossen → http://192.168.1.137:8000/health"
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# STILLGELEGT – nicht mehr verwenden.
|
||||
#
|
||||
# Dieses Skript rsyncte das lokale Arbeitsverzeichnis in den git-Baum des
|
||||
# Servers und verschmutzte ihn dadurch (spätere 'git pull' schlugen fehl).
|
||||
#
|
||||
# Neuer, entkoppelter Ablauf (jeder Server macht sich selbst):
|
||||
# 1. Lokal: git add -A && git commit && git push origin main
|
||||
# 2. Server: ssh root@<host> 'cd /opt/timemaster && ./server-update.sh'
|
||||
# 3. Frontend (falls geändert, lokal): ./push-frontend.sh <137|164>
|
||||
# =============================================================================
|
||||
echo "deploy.sh ist stillgelegt. Nutze: git push → server-update.sh (auf dem Server) → push-frontend.sh (lokal)." >&2
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user