diff --git a/docker/compose.yaml b/docker/compose.yaml index 8b103ef..b37ede0 100644 --- a/docker/compose.yaml +++ b/docker/compose.yaml @@ -5,7 +5,7 @@ services: php: build: context: .. - dockerfile: php/Dockerfile + dockerfile: docker/php/Dockerfile container_name: escapepage-php volumes: - ../:/var/www/html:delegated @@ -18,6 +18,23 @@ services: - backend restart: unless-stopped + php-worker: + build: + context: .. + dockerfile: docker/php/Dockerfile + container_name: escapepage-php-worker + volumes: + - ../:/var/www/html:delegated + environment: + APP_ENV: dev + depends_on: + - database + - mercure + command: ["php", "bin/console", "messenger:consume", "async", "-vv"] + networks: + - backend + restart: unless-stopped + nginx: image: nginx:1.29.4-alpine container_name: escapepage-nginx diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 41dfc85..3154c83 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -1,11 +1,20 @@ -FROM php:8.5.1-fpm-alpine3.23 +FROM php:8.3-fpm-alpine # Install system deps -RUN apk add --no-cache bash git icu-dev libzip-dev oniguruma-dev +RUN apk add --no-cache \ + bash \ + git \ + icu-dev \ + libzip-dev \ + oniguruma-dev \ + g++ \ + make \ + nodejs \ + npm # Install PHP extensions RUN docker-php-ext-configure intl \ - && docker-php-ext-install -j$(nproc) intl pdo pdo_mysql opcache + && docker-php-ext-install -j$(nproc) intl pdo pdo_mysql opcache zip # Install composer ENV COMPOSER_ALLOW_SUPERUSER=1 \ @@ -13,7 +22,7 @@ ENV COMPOSER_ALLOW_SUPERUSER=1 \ COPY --from=composer:2 /usr/bin/composer /usr/bin/composer # Configure PHP -COPY php.ini $PHP_INI_DIR/conf.d/zz-custom.ini +COPY docker/php/php.ini $PHP_INI_DIR/conf.d/zz-custom.ini WORKDIR /var/www/html diff --git a/docker/setup.sh b/docker/setup.sh old mode 100644 new mode 100755 index daad179..c6c5937 --- a/docker/setup.sh +++ b/docker/setup.sh @@ -66,12 +66,15 @@ dc up "${BUILD_ARGS[@]}" # Helper to run commands in php container pexec() { dc exec -T php "$@"; } -# Wait for database to be healthy (mariadb) +# Wait for database to be healthy (mariadb/mysql) printf "Waiting for database to be healthy..." # Use docker inspect health status DB_HEALTH="" for i in {1..60}; do - DB_HEALTH=$(docker inspect -f '{{.State.Health.Status}}' "$(docker ps --filter name=_database_ --format '{{.ID}}' | head -n1)" 2>/dev/null || true) + DB_ID=$(dc ps -q database 2>/dev/null || true) + if [ -n "$DB_ID" ]; then + DB_HEALTH=$(docker inspect -f '{{.State.Health.Status}}' "$DB_ID" 2>/dev/null || true) + fi if [ "$DB_HEALTH" = "healthy" ]; then echo " OK" break @@ -79,7 +82,7 @@ for i in {1..60}; do printf "." sleep 2 if [ "$i" -eq 60 ]; then - echo "\nWarning: database health check not healthy yet, continuing anyway." + echo -e "\nWarning: database health check not healthy yet, continuing anyway." fi done @@ -100,11 +103,23 @@ if grep -q '^APP_SECRET=$' "$ROOT_DIR/.env" 2>/dev/null; then fi # Prepare DB -pexec php bin/console doctrine:database:create --if-not-exists || true -pexec php bin/console doctrine:migrations:migrate -n || true +echo "Creating database if it doesn't exist..." +pexec php bin/console doctrine:database:create --if-not-exists +echo "Running migrations..." +pexec php bin/console doctrine:migrations:migrate -n # Import JS deps (Importmap/Asset Mapper) -pexec php bin/console importmap:install || true +if [ -f "$ROOT_DIR/importmap.php" ]; then + pexec php bin/console importmap:install || true +fi + +# Build assets if using Webpack Encore +if [ -f "$ROOT_DIR/package.json" ]; then + echo "Installing npm dependencies..." + pexec npm install + echo "Building assets..." + pexec npm run build +fi APP_URL=http://localhost:8080 MAILPIT_URL=http://localhost:8025 @@ -117,10 +132,12 @@ Open the app: $APP_URL Mailpit (dev): $MAILPIT_URL Common commands: - (cd docker && $DOCKER_COMPOSE logs -f nginx) - (cd docker && $DOCKER_COMPOSE logs -f php) - (cd docker && $DOCKER_COMPOSE exec php bash) - (cd docker && $DOCKER_COMPOSE down) + (cd "$DOCKER_DIR" && $DOCKER_COMPOSE logs -f nginx) + (cd "$DOCKER_DIR" && $DOCKER_COMPOSE logs -f php) + (cd "$DOCKER_DIR" && $DOCKER_COMPOSE logs -f php-worker) + (cd "$DOCKER_DIR" && $DOCKER_COMPOSE exec php bash) + (cd "$DOCKER_DIR" && $DOCKER_COMPOSE exec php npm run watch) + (cd "$DOCKER_DIR" && $DOCKER_COMPOSE down) You can re-run this script any time. Use --no-build to skip rebuilding images. EOT