mindboost-infrastructure/scripts/start/deploy-all.sh

110 lines
3.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
source ../setup/set-project-root.sh
source ../setup/set-global-env.sh
source ../setup/set-proxy-env.sh
source ../setup/generate-secrets.sh
# Pfad zur .env.all Datei
ENV_FILE="../../env/.env.all"
# Funktion zum Auslesen von Variablen aus der .env.all Datei
get_env_var() {
grep "^$1=" "$ENV_FILE" | cut -d '=' -f2
}
# Auslesen der INFRASTRUCTURE und ENVIRONMENT Variablen
INFRASTRUCTURE=$(get_env_var "INFRASTRUCTURE_LABEL")
ENVIRONMENT=$(get_env_var "ENVIRONMENT")
SERVER_IP=$(curl -s https://api.ipify.org)
# Liste aller Stacks
STACKS=("administration" "frontend" "develop" "database" "proxy" "tools" "website" "backend")
# Liste aller Environments
ENVIRONMENTS=("development" "staging" "production")
# Funktion zum Überprüfen der Existenz einer Datei
check_file_exists() {
if [ ! -f "$1" ]; then
echo "Fehler: Die Datei $1 existiert nicht."
return 1
fi
}
# Prüfe, ob das Skript nur in der Entwicklungsumgebung ausgeführt wird
if [ "$ENVIRONMENT" == "development" ]; then
# Sicherstellen, dass acme_letsencrypt.json existiert und korrekte Berechtigungen hat
ACME_FILE="../apps/proxy/traefik/acme_letsencrypt.json"
if [ ! -f "$ACME_FILE" ]; then
echo "🔹 Erstelle $ACME_FILE..."
touch "$ACME_FILE"
fi
echo "🔹 Setze Berechtigungen für $ACME_FILE auf 600..."
chmod 600 "$ACME_FILE"
echo "🔹 ENVIRONMENT ist 'development' Hosts aus .env.proxy werden hinzugefügt und Container gestartet."
# Pfad zur Proxy-Env-Datei
ENV_PROXY_FILE="../../env/development/.env.proxy"
# Hosts-Datei Pfad (Linux/macOS)
HOSTS_FILE="/etc/hosts"
# Prüfe, ob die Env-Datei existiert
if [ ! -f "$ENV_PROXY_FILE" ]; then
echo "❌ Fehler: Die Datei $ENV_PROXY_FILE existiert nicht!"
exit 1
fi
# Lese alle Zeilen, die auf *_DOMAIN= enden und extrahiere die Werte
DOMAINS=($(grep -E '^[A-Z_]+_DOMAIN=' "$ENV_PROXY_FILE" | cut -d '=' -f2))
# Füge jede Domain zur /etc/hosts Datei hinzu, falls sie fehlt
for DOMAIN in "${DOMAINS[@]}"; do
if ! grep -q "$DOMAIN" "$HOSTS_FILE"; then
echo "127.0.0.1 $DOMAIN" | sudo tee -a "$HOSTS_FILE" > /dev/null
echo "$DOMAIN zu /etc/hosts hinzugefügt"
else
echo "$DOMAIN ist bereits in /etc/hosts vorhanden"
fi
done
else
echo "❌ ENVIRONMENT ist nicht 'development' Routing über externen DNS erwartet"
fi
# Überprüfe die Existenz von .env.all
check_file_exists "../../env/.env.all"
# Überprüfe die Existenz aller Stack-spezifischen .env Dateien
missing_files=0
for stack in "${STACKS[@]}"; do
env_file="../../env/${ENVIRONMENT:-development}/.env.${stack}"
if ! check_file_exists "$env_file"; then
missing_files=$((missing_files + 1))
fi
done
if [ $missing_files -eq 0 ]; then
echo "Alle erforderlichen .env Dateien sind vorhanden."
else
echo "WARNUNG: $missing_files .env Datei(en) fehlen. Einige Stacks könnten nicht korrekt funktionieren."
fi
# Ausgabe der Variablen
echo "Deploying to:"
echo "INFRASTRUCTURE: ${INFRASTRUCTURE:-Not set}"
echo "ENVIRONMENT: ${ENVIRONMENT:-Not set}"
echo "-----------------------------------"
# Check for the --build argument
BUILD_OPTION=""
if [[ "$1" == "--build" ]]; then
BUILD_OPTION="--build"
fi
# Ausführen des Docker Compose Befehls
docker compose -f ../../apps/docker-compose.all.yml -p ${INFRASTRUCTURE:-my} --env-file ../../env/.env.all --env-file ../../env/${ENVIRONMENT:-development}/.env.proxy --profile backend up --remove-orphans $BUILD_OPTION