FFeat: ügt Podman-Setup für Symfony-Entwicklung hinzu

This commit is contained in:
2026-05-30 01:07:33 +02:00
parent 66b2d7d786
commit 0706f1f6a5
4 changed files with 174 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
FROM docker.io/library/nginx:1.31.1-alpine
# Kopiere die Konfiguration
COPY podman/nginx/default.conf /etc/nginx/conf.d/default.conf
# Exponiere Port 80 (wird später im Pod gemappt)
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
+25
View File
@@ -0,0 +1,25 @@
server {
listen 80;
server_name localhost;
root /var/www/html/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass localhost:9000; # PHP-FPM im selben Pod
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
+30
View File
@@ -0,0 +1,30 @@
FROM docker.io/library/php:8.5-fpm
# Installiere System-Abhängigkeiten
RUN apt-get update && apt-get install -y \
# git \
curl \
# libpng-dev \
# libonig-dev \
# libxml2-dev \
# zip \
# unzip \
apt-transport-https \
gnupg \
# && docker-php-ext-install pdo pdo_pgsql mbstring exif pcntl bcmath gd \
&& curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh' | bash \
&& apt-get install -y symfony-cli \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Installiere Composer
COPY --from=docker.io/library/composer:2.10.0 /usr/bin/composer /usr/bin/composer
# Arbeitsverzeichnis
WORKDIR /var/www/html
# Benutzer für Nicht-Root-Betrieb (optional, aber empfohlen)
# Wir nutzen hier den Standard www-data User von PHP-FPM
USER www-data
CMD ["php-fpm"]
Executable
+110
View File
@@ -0,0 +1,110 @@
#!/bin/bash
# Konfiguration
POD_NAME="symfony-dev"
PROJECT_DIR="$(pwd)"
DB_PASSWORD="devpassword" # Ändere dies!
DB_NAME="symfony_db"
DB_USER="symfony_user"
DB_HOST="localhost"
DB_PORT="5432"
ENV_FILE="$PROJECT_DIR/.env"
echo "🚀 Starte Symfony Pod Setup..."
# 1. .env Datei automatisch erstellen/aktualisieren
echo "📝 Konfiguriere .env Datei..."
DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?serverVersion=16&charset=utf8"
if [ -f "$ENV_FILE" ]; then
# Datei existiert - DATABASE_URL aktualisieren oder hinzufügen
if grep -q "^DATABASE_URL=" "$ENV_FILE"; then
sed -i "s|^DATABASE_URL=.*|DATABASE_URL=\"$DATABASE_URL\"|" "$ENV_FILE"
echo " ✅ DATABASE_URL aktualisiert"
else
echo "DATABASE_URL=\"$DATABASE_URL\"" >> "$ENV_FILE"
echo " ✅ DATABASE_URL hinzugefügt"
fi
# APP_ENV sicherstellen
if ! grep -q "^APP_ENV=" "$ENV_FILE"; then
echo "APP_ENV=dev" >> "$ENV_FILE"
echo " ✅ APP_ENV hinzugefügt"
fi
else
# Neue Datei erstellen
cat > "$ENV_FILE" <<EOF
### symfony-pod environment ###
APP_ENV=dev
APP_SECRET=$(openssl rand -hex 16)
DATABASE_URL="$DATABASE_URL"
### symfony-pod environment ###
EOF
echo " ✅ .env Datei erstellt"
fi
# 2. Pod erstellen
echo "📦 Erstelle Pod '$POD_NAME'..."
podman pod create --name $POD_NAME -p 8080:80
# 3. PHP-FPM Container bauen und starten
echo "🐘 Baue und starte PHP-FPM..."
podman build -t symfony-php -f podman/php/Containerfile .
podman run -d \
--pod $POD_NAME \
--name symfony-php \
-v $PROJECT_DIR:/var/www/html:Z \
-e APP_ENV=dev \
symfony-php
# 4. Nginx Container bauen und starten
echo "🌐 Baue und starte Nginx..."
podman build -t symfony-nginx -f podman/nginx/Containerfile .
podman run -d \
--pod $POD_NAME \
--name symfony-nginx \
symfony-nginx
# 5. PostgreSQL Container starten
echo "🐘 Starte PostgreSQL..."
podman run -d \
--pod $POD_NAME \
--name symfony-db \
-e POSTGRES_DB=$DB_NAME \
-e POSTGRES_USER=$DB_USER \
-e POSTGRES_PASSWORD=$DB_PASSWORD \
-v symfony-db-data:/var/lib/postgresql/data \
docker.io/library/postgres:16-alpine
# 6. Warten auf DB Start
echo "⏳ Warte auf Datenbank-Start..."
sleep 5
# 7. Symfony Abhängigkeiten installieren (falls composer.json existiert)
if [ -f "$PROJECT_DIR/composer.json" ]; then
echo "📦 Installiere Composer Abhängigkeiten..."
podman exec -it symfony-php composer install
echo "🗄️ Erstelle Datenbank..."
podman exec -it symfony-php php bin/console doctrine:database:create --if-not-exists
echo "🔄 Führe Migrationen aus..."
podman exec -it symfony-php php bin/console doctrine:migrations:migrate --no-interaction
else
echo "️ Keine composer.json gefunden - überspringe Installation"
fi
echo ""
echo "✅ Setup abgeschlossen!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🌍 Deine App ist erreichbar unter: http://localhost:8080"
echo "🔑 DB Zugangsdaten:"
echo " Host: $DB_HOST (innerhalb des Pods)"
echo " Port: $DB_PORT"
echo " User: $DB_USER"
echo " Pass: $DB_PASSWORD"
echo " DB: $DB_NAME"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📝 .env Datei wurde automatisch konfiguriert"
echo ""