Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Failing after 10m14s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Has been skipped
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
Security Vulnerability Scan / Check for Dependency Changes (push) Failing after 11m25s
Security Vulnerability Scan / Composer Security Audit (push) Has been cancelled
- Remove middleware reference from Gitea Traefik labels (caused routing issues) - Optimize Gitea connection pool settings (MAX_IDLE_CONNS=30, authentication_timeout=180s) - Add explicit service reference in Traefik labels - Fix intermittent 504 timeouts by improving PostgreSQL connection handling Fixes Gitea unreachability via git.michaelschiemer.de
320 lines
9.7 KiB
Bash
Executable File
320 lines
9.7 KiB
Bash
Executable File
#!/bin/bash
|
||
# Production Quick-Start Script
|
||
# Automatisiert häufige Production-Deployment-Aufgaben
|
||
|
||
set -e
|
||
|
||
# Colors for output
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
NC='\033[0m' # No Color
|
||
|
||
# Configuration
|
||
STACKS_BASE_PATH="${STACKS_BASE_PATH:-~/deployment/stacks}"
|
||
POSTGRESQL_PRODUCTION_PATH="${STACKS_BASE_PATH}/postgresql-production"
|
||
PRODUCTION_STACK_PATH="${STACKS_BASE_PATH}/production"
|
||
|
||
# Functions
|
||
print_header() {
|
||
echo ""
|
||
echo -e "${BLUE}========================================${NC}"
|
||
echo -e "${BLUE}$1${NC}"
|
||
echo -e "${BLUE}========================================${NC}"
|
||
echo ""
|
||
}
|
||
|
||
print_success() {
|
||
echo -e "${GREEN}✅ $1${NC}"
|
||
}
|
||
|
||
print_error() {
|
||
echo -e "${RED}❌ $1${NC}"
|
||
}
|
||
|
||
print_warning() {
|
||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||
}
|
||
|
||
print_info() {
|
||
echo -e "${BLUE}ℹ️ $1${NC}"
|
||
}
|
||
|
||
check_docker() {
|
||
if ! command -v docker &> /dev/null; then
|
||
print_error "Docker ist nicht installiert oder nicht im PATH"
|
||
exit 1
|
||
fi
|
||
|
||
if ! docker ps &> /dev/null; then
|
||
print_error "Docker daemon läuft nicht oder keine Berechtigung"
|
||
exit 1
|
||
fi
|
||
|
||
print_success "Docker ist verfügbar"
|
||
}
|
||
|
||
check_networks() {
|
||
print_header "Networks prüfen"
|
||
|
||
local networks=("traefik-public" "postgres-production-internal" "app-internal")
|
||
local all_exist=true
|
||
|
||
for network in "${networks[@]}"; do
|
||
if docker network inspect "$network" &> /dev/null; then
|
||
print_success "Network '$network' existiert"
|
||
else
|
||
print_warning "Network '$network' existiert nicht"
|
||
all_exist=false
|
||
fi
|
||
done
|
||
|
||
if [ "$all_exist" = false ]; then
|
||
print_info "Fehlende Networks werden beim Stack-Start automatisch erstellt"
|
||
fi
|
||
}
|
||
|
||
start_postgresql_production() {
|
||
print_header "PostgreSQL-Production Stack starten"
|
||
|
||
if [ ! -d "$POSTGRESQL_PRODUCTION_PATH" ]; then
|
||
print_error "PostgreSQL-Production Stack nicht gefunden: $POSTGRESQL_PRODUCTION_PATH"
|
||
return 1
|
||
fi
|
||
|
||
cd "$POSTGRESQL_PRODUCTION_PATH"
|
||
|
||
# Check if .env exists
|
||
if [ ! -f ".env" ]; then
|
||
print_warning ".env-Datei nicht gefunden. Erstelle Beispiel-Konfiguration..."
|
||
cat > .env <<EOF
|
||
POSTGRES_DB=michaelschiemer
|
||
POSTGRES_USER=postgres
|
||
POSTGRES_PASSWORD=CHANGE_ME_STRONG_PASSWORD
|
||
BACKUP_RETENTION_DAYS=7
|
||
BACKUP_SCHEDULE=0 2 * * *
|
||
EOF
|
||
print_warning "Bitte POSTGRES_PASSWORD in .env anpassen!"
|
||
return 1
|
||
fi
|
||
|
||
print_info "Starte PostgreSQL-Production Stack..."
|
||
docker compose up -d
|
||
|
||
# Wait for PostgreSQL to be ready
|
||
print_info "Warte auf PostgreSQL-Production..."
|
||
local max_attempts=30
|
||
local attempt=0
|
||
|
||
while [ $attempt -lt $max_attempts ]; do
|
||
if docker exec postgres-production pg_isready -U postgres -d michaelschiemer &> /dev/null; then
|
||
print_success "PostgreSQL-Production ist bereit"
|
||
return 0
|
||
fi
|
||
attempt=$((attempt + 1))
|
||
sleep 2
|
||
done
|
||
|
||
print_error "PostgreSQL-Production ist nicht bereit nach $max_attempts Versuchen"
|
||
return 1
|
||
}
|
||
|
||
verify_connections() {
|
||
print_header "Datenbank-Verbindungen verifizieren"
|
||
|
||
# Check Production
|
||
if docker ps | grep -q postgres-production; then
|
||
print_info "Teste Production-Datenbank-Verbindung..."
|
||
if docker exec postgres-production pg_isready -U postgres -d michaelschiemer &> /dev/null; then
|
||
print_success "PostgreSQL-Production erreichbar"
|
||
else
|
||
print_error "PostgreSQL-Production nicht erreichbar"
|
||
fi
|
||
else
|
||
print_warning "PostgreSQL-Production Container läuft nicht"
|
||
fi
|
||
}
|
||
|
||
show_status() {
|
||
print_header "Container-Status"
|
||
|
||
echo "PostgreSQL-Production Container:"
|
||
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "postgres-production" || echo "Keine PostgreSQL-Production Container gefunden"
|
||
|
||
echo ""
|
||
echo "Production Application Container:"
|
||
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "^(app|php|queue-worker|scheduler|nginx)" || echo "Keine Production-Container gefunden"
|
||
}
|
||
|
||
show_logs() {
|
||
local container=$1
|
||
local lines=${2:-50}
|
||
|
||
if docker ps --format "{{.Names}}" | grep -q "^${container}$"; then
|
||
print_header "Logs: $container (letzte $lines Zeilen)"
|
||
docker logs --tail "$lines" "$container"
|
||
else
|
||
print_warning "Container '$container' läuft nicht"
|
||
fi
|
||
}
|
||
|
||
test_production_connection() {
|
||
print_header "Production-Datenbank-Verbindung testen"
|
||
|
||
local app_container="php"
|
||
if ! docker ps --format "{{.Names}}" | grep -q "^${app_container}$"; then
|
||
# Try alternative names
|
||
app_container=$(docker ps --format "{{.Names}}" | grep -E "^(app|php)" | head -1)
|
||
if [ -z "$app_container" ]; then
|
||
print_warning "Production Application Container läuft nicht"
|
||
return 1
|
||
fi
|
||
fi
|
||
|
||
print_info "Teste Verbindung von $app_container zu postgres-production..."
|
||
|
||
# Test network connectivity
|
||
if docker exec "$app_container" nc -zv postgres-production 5432 &> /dev/null; then
|
||
print_success "Network-Verbindung zu postgres-production erfolgreich"
|
||
else
|
||
print_error "Network-Verbindung zu postgres-production fehlgeschlagen"
|
||
print_info "Prüfe, ob $app_container im postgres-production-internal Network ist"
|
||
return 1
|
||
fi
|
||
|
||
# Test database connection
|
||
print_info "Teste Datenbank-Verbindung..."
|
||
if docker exec "$app_container" php -r "
|
||
\$host = getenv('DB_HOST') ?: 'postgres-production';
|
||
\$db = getenv('DB_DATABASE') ?: 'michaelschiemer';
|
||
\$user = getenv('DB_USERNAME') ?: 'postgres';
|
||
\$pass = getenv('DB_PASSWORD') ?: file_get_contents(getenv('DB_PASSWORD_FILE') ?: '/dev/null');
|
||
if (!\$pass) {
|
||
echo 'DB_PASSWORD nicht verfügbar\n';
|
||
exit(1);
|
||
}
|
||
try {
|
||
\$dsn = \"pgsql:host=\$host;port=5432;dbname=\$db\";
|
||
\$pdo = new PDO(\$dsn, \$user, trim(\$pass));
|
||
echo 'Connection successful: ' . \$pdo->query('SELECT version()')->fetchColumn() . \"\n\";
|
||
exit(0);
|
||
} catch (Exception \$e) {
|
||
echo 'Connection failed: ' . \$e->getMessage() . \"\n\";
|
||
exit(1);
|
||
}
|
||
" 2>&1; then
|
||
print_success "Datenbank-Verbindung erfolgreich"
|
||
else
|
||
print_warning "Datenbank-Verbindungstest fehlgeschlagen (DB_PASSWORD möglicherweise nicht gesetzt)"
|
||
fi
|
||
}
|
||
|
||
health_check() {
|
||
print_header "Health-Checks"
|
||
|
||
# Basic health check
|
||
print_info "Basic Health Check: https://michaelschiemer.de/health"
|
||
if curl -f -k -s https://michaelschiemer.de/health > /dev/null 2>&1; then
|
||
print_success "Basic Health Check erfolgreich"
|
||
else
|
||
print_warning "Basic Health Check fehlgeschlagen (Service möglicherweise nicht verfügbar)"
|
||
fi
|
||
|
||
# Extended health check
|
||
print_info "Extended Health Check: https://michaelschiemer.de/admin/health/api/summary"
|
||
local health_summary=$(curl -f -k -s https://michaelschiemer.de/admin/health/api/summary 2>/dev/null || echo "")
|
||
if [ -n "$health_summary" ]; then
|
||
local overall_status=$(echo "$health_summary" | grep -o '"overall_status":"[^"]*"' | cut -d'"' -f4 || echo "unknown")
|
||
print_info "Overall Health Status: $overall_status"
|
||
if [ "$overall_status" = "healthy" ]; then
|
||
print_success "Extended Health Check erfolgreich"
|
||
else
|
||
print_warning "Extended Health Check zeigt: $overall_status"
|
||
fi
|
||
else
|
||
print_warning "Extended Health Check Endpoint nicht verfügbar"
|
||
fi
|
||
}
|
||
|
||
# Main menu
|
||
show_menu() {
|
||
echo ""
|
||
echo -e "${BLUE}========================================${NC}"
|
||
echo -e "${BLUE} Production Quick-Start Script${NC}"
|
||
echo -e "${BLUE}========================================${NC}"
|
||
echo ""
|
||
echo "1) PostgreSQL-Production Stack starten"
|
||
echo "2) Networks prüfen"
|
||
echo "3) Container-Status anzeigen"
|
||
echo "4) Production-Datenbank-Verbindung testen"
|
||
echo "5) Health-Checks durchführen"
|
||
echo "6) Logs anzeigen (PostgreSQL-Production)"
|
||
echo "7) Logs anzeigen (Production App)"
|
||
echo "8) Alles verifizieren"
|
||
echo "0) Beenden"
|
||
echo ""
|
||
read -p "Wähle eine Option: " choice
|
||
}
|
||
|
||
# Main execution
|
||
main() {
|
||
print_header "Production Quick-Start Script"
|
||
|
||
check_docker
|
||
|
||
while true; do
|
||
show_menu
|
||
|
||
case $choice in
|
||
1)
|
||
start_postgresql_production
|
||
;;
|
||
2)
|
||
check_networks
|
||
;;
|
||
3)
|
||
show_status
|
||
;;
|
||
4)
|
||
test_production_connection
|
||
;;
|
||
5)
|
||
health_check
|
||
;;
|
||
6)
|
||
show_logs "postgres-production" 50
|
||
;;
|
||
7)
|
||
local app_container=$(docker ps --format "{{.Names}}" | grep -E "^(app|php)" | head -1)
|
||
if [ -n "$app_container" ]; then
|
||
show_logs "$app_container" 50
|
||
else
|
||
print_warning "Production Application Container läuft nicht"
|
||
fi
|
||
;;
|
||
8)
|
||
check_networks
|
||
verify_connections
|
||
show_status
|
||
test_production_connection
|
||
health_check
|
||
;;
|
||
0)
|
||
print_info "Beende..."
|
||
exit 0
|
||
;;
|
||
*)
|
||
print_error "Ungültige Option"
|
||
;;
|
||
esac
|
||
|
||
echo ""
|
||
read -p "Drücke Enter um fortzufahren..."
|
||
done
|
||
}
|
||
|
||
# Run main function
|
||
main "$@"
|
||
|