Feat: Ändert Datenbank auf redis

This commit is contained in:
2026-05-30 19:45:25 +02:00
parent 0706f1f6a5
commit 1873d54a5d
+28 -38
View File
@@ -3,11 +3,8 @@
# Konfiguration # Konfiguration
POD_NAME="symfony-dev" POD_NAME="symfony-dev"
PROJECT_DIR="$(pwd)" PROJECT_DIR="$(pwd)"
DB_PASSWORD="devpassword" # Ändere dies! REDIS_HOST="localhost"
DB_NAME="symfony_db" REDIS_PORT="6379"
DB_USER="symfony_user"
DB_HOST="localhost"
DB_PORT="5432"
ENV_FILE="$PROJECT_DIR/.env" ENV_FILE="$PROJECT_DIR/.env"
@@ -15,16 +12,16 @@ echo "🚀 Starte Symfony Pod Setup..."
# 1. .env Datei automatisch erstellen/aktualisieren # 1. .env Datei automatisch erstellen/aktualisieren
echo "📝 Konfiguriere .env Datei..." echo "📝 Konfiguriere .env Datei..."
DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?serverVersion=16&charset=utf8" REDIS_URL="redis://${REDIS_HOST}:${REDIS_PORT}"
if [ -f "$ENV_FILE" ]; then if [ -f "$ENV_FILE" ]; then
# Datei existiert - DATABASE_URL aktualisieren oder hinzufügen # Datei existiert - REDIS_URL aktualisieren oder hinzufügen
if grep -q "^DATABASE_URL=" "$ENV_FILE"; then if grep -q "^REDIS_URL=" "$ENV_FILE"; then
sed -i "s|^DATABASE_URL=.*|DATABASE_URL=\"$DATABASE_URL\"|" "$ENV_FILE" sed -i "s|^REDIS_URL=.*|REDIS_URL=\"$REDIS_URL\"|" "$ENV_FILE"
echo " ✅ DATABASE_URL aktualisiert" echo " ✅ REDIS_URL aktualisiert"
else else
echo "DATABASE_URL=\"$DATABASE_URL\"" >> "$ENV_FILE" echo "REDIS_URL=\"$REDIS_URL\"" >> "$ENV_FILE"
echo " ✅ DATABASE_URL hinzugefügt" echo " ✅ REDIS_URL hinzugefügt"
fi fi
# APP_ENV sicherstellen # APP_ENV sicherstellen
@@ -38,7 +35,7 @@ else
### symfony-pod environment ### ### symfony-pod environment ###
APP_ENV=dev APP_ENV=dev
APP_SECRET=$(openssl rand -hex 16) APP_SECRET=$(openssl rand -hex 16)
DATABASE_URL="$DATABASE_URL" REDIS_URL="$REDIS_URL"
### symfony-pod environment ### ### symfony-pod environment ###
EOF EOF
echo " ✅ .env Datei erstellt" echo " ✅ .env Datei erstellt"
@@ -51,7 +48,7 @@ podman pod create --name $POD_NAME -p 8080:80
# 3. PHP-FPM Container bauen und starten # 3. PHP-FPM Container bauen und starten
echo "🐘 Baue und starte PHP-FPM..." echo "🐘 Baue und starte PHP-FPM..."
podman build -t symfony-php -f podman/php/Containerfile . podman build -t symfony-php -f podman/php/Containerfile .
podman run -d \ podman run --replace -d \
--pod $POD_NAME \ --pod $POD_NAME \
--name symfony-php \ --name symfony-php \
-v $PROJECT_DIR:/var/www/html:Z \ -v $PROJECT_DIR:/var/www/html:Z \
@@ -61,36 +58,31 @@ podman run -d \
# 4. Nginx Container bauen und starten # 4. Nginx Container bauen und starten
echo "🌐 Baue und starte Nginx..." echo "🌐 Baue und starte Nginx..."
podman build -t symfony-nginx -f podman/nginx/Containerfile . podman build -t symfony-nginx -f podman/nginx/Containerfile .
podman run -d \ podman run --replace -d \
--pod $POD_NAME \ --pod $POD_NAME \
--name symfony-nginx \ --name symfony-nginx \
symfony-nginx symfony-nginx
# 5. PostgreSQL Container starten # 5. Redis Container starten
echo "🐘 Starte PostgreSQL..." echo "🔴 Starte Redis..."
podman run -d \ podman run --replace -d \
--pod $POD_NAME \ --pod $POD_NAME \
--name symfony-db \ --name symfony-redis \
-e POSTGRES_DB=$DB_NAME \ -v symfony-redis-data:/data \
-e POSTGRES_USER=$DB_USER \ docker.io/library/redis:8-alpine \
-e POSTGRES_PASSWORD=$DB_PASSWORD \ redis-server --appendonly yes
-v symfony-db-data:/var/lib/postgresql/data \
docker.io/library/postgres:16-alpine
# 6. Warten auf DB Start # 6. Warten auf Redis Start
echo "⏳ Warte auf Datenbank-Start..." echo "⏳ Warte auf Redis-Start..."
sleep 5 sleep 3
# 7. Symfony Abhängigkeiten installieren (falls composer.json existiert) # 7. Symfony Abhängigkeiten installieren (falls composer.json existiert)
if [ -f "$PROJECT_DIR/composer.json" ]; then if [ -f "$PROJECT_DIR/composer.json" ]; then
echo "📦 Installiere Composer Abhängigkeiten..." echo "📦 Installiere Composer Abhängigkeiten..."
podman exec -it symfony-php composer install podman exec -it symfony-php composer install
echo "🗄️ Erstelle Datenbank..." echo "🧹 Leere Symfony Cache..."
podman exec -it symfony-php php bin/console doctrine:database:create --if-not-exists podman exec -it symfony-php php bin/console cache:clear
echo "🔄 Führe Migrationen aus..."
podman exec -it symfony-php php bin/console doctrine:migrations:migrate --no-interaction
else else
echo "️ Keine composer.json gefunden - überspringe Installation" echo "️ Keine composer.json gefunden - überspringe Installation"
fi fi
@@ -99,12 +91,10 @@ echo ""
echo "✅ Setup abgeschlossen!" echo "✅ Setup abgeschlossen!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🌍 Deine App ist erreichbar unter: http://localhost:8080" echo "🌍 Deine App ist erreichbar unter: http://localhost:8080"
echo "🔑 DB Zugangsdaten:" echo "🔴 Redis Zugangsdaten:"
echo " Host: $DB_HOST (innerhalb des Pods)" echo " Host: $REDIS_HOST (innerhalb des Pods)"
echo " Port: $DB_PORT" echo " Port: $REDIS_PORT"
echo " User: $DB_USER" echo " URL: $REDIS_URL"
echo " Pass: $DB_PASSWORD"
echo " DB: $DB_NAME"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📝 .env Datei wurde automatisch konfiguriert" echo "📝 .env Datei wurde automatisch konfiguriert"
echo "" echo ""