From 3065597f64211e55b3c59162d7ef821dc04a49a0 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 4 Apr 2024 19:09:53 +0100 Subject: [PATCH] Add Apache support to Drupal --- justfile | 4 ++-- src/Action/CreateListOfFilesToGenerate.php | 17 +++++++++++++++++ src/DataTransferObject/ConfigDto.php | 2 +- src/Enum/WebServer.php | 1 + templates/php/drupal/Dockerfile.twig | 4 ++++ .../php/drupal/apache/000-default.conf.twig | 8 ++++++++ vendor-bin/box/composer.lock | 2 +- 7 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 templates/php/drupal/apache/000-default.conf.twig diff --git a/justfile b/justfile index 87bf6a4..a79f24e 100644 --- a/justfile +++ b/justfile @@ -11,8 +11,8 @@ build: composer dump-env prod - ./build-configs cache:clear - ./build-configs cache:warmup + ./bin/build-configs cache:clear + ./bin/build-configs cache:warmup # Generate the phar file. box compile --config box.json.dist diff --git a/src/Action/CreateListOfFilesToGenerate.php b/src/Action/CreateListOfFilesToGenerate.php index b33eaf8..2f216d4 100644 --- a/src/Action/CreateListOfFilesToGenerate.php +++ b/src/Action/CreateListOfFilesToGenerate.php @@ -113,6 +113,14 @@ final class CreateListOfFilesToGenerate path: 'tools/docker/images/php/root/usr/local/etc/php', )); + if (static::isApache(Arr::get($configurationData, 'web.type'))) { + $filesToGenerate[] = new TemplateFile( + data: 'php/drupal/apache/000-default.conf', + name: '000-default.conf', + path: 'tools/docker/images/php/root/etc/apache2/sites-available', + ); + } + if (static::isCaddy(Arr::get($configurationData, 'web.type'))) { $filesToGenerate[] = new TemplateFile( data: 'php/drupal/caddy/Caddyfile', @@ -170,6 +178,15 @@ final class CreateListOfFilesToGenerate return $next([$configurationData, $configDto, $filesToGenerate]); } + private static function isApache(?string $webServer): bool + { + if (is_null($webServer)) { + return false; + } + + return $webServer === WebServer::Apache->value; + } + private static function isCaddy(?string $webServer): bool { if (is_null($webServer)) { diff --git a/src/DataTransferObject/ConfigDto.php b/src/DataTransferObject/ConfigDto.php index eb7e21f..391f2a2 100644 --- a/src/DataTransferObject/ConfigDto.php +++ b/src/DataTransferObject/ConfigDto.php @@ -251,7 +251,7 @@ final class ConfigDto #[Assert\Collection([ 'type' => new Assert\Required([ - new Assert\Choice(choices: ['nginx', 'caddy']), + new Assert\Choice(choices: ['apache', 'caddy', 'nginx']), ]), ])] public array $web; diff --git a/src/Enum/WebServer.php b/src/Enum/WebServer.php index dcf7e00..0b3d4f2 100644 --- a/src/Enum/WebServer.php +++ b/src/Enum/WebServer.php @@ -6,6 +6,7 @@ namespace App\Enum; enum WebServer: string { + case Apache = 'apache'; case Caddy = 'caddy'; case Nginx = 'nginx'; } diff --git a/templates/php/drupal/Dockerfile.twig b/templates/php/drupal/Dockerfile.twig index b1f9f16..38b2aa3 100644 --- a/templates/php/drupal/Dockerfile.twig +++ b/templates/php/drupal/Dockerfile.twig @@ -65,7 +65,11 @@ RUN {{ command }} COPY --chown=app:app tools/docker/images/php/root / ENTRYPOINT ["/usr/local/bin/docker-entrypoint-php"] +{% if web.type == "apache" %} +CMD ["apache2-foreground"] +{% else %} CMD ["php-fpm"] +{% endif %} {% if dockerfile.stages.test %} ################################################################################ diff --git a/templates/php/drupal/apache/000-default.conf.twig b/templates/php/drupal/apache/000-default.conf.twig new file mode 100644 index 0000000..66012fd --- /dev/null +++ b/templates/php/drupal/apache/000-default.conf.twig @@ -0,0 +1,8 @@ +# {{ managedText|raw }} + + + DocumentRoot /var/www/html/{{ drupal.docroot }} + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + diff --git a/vendor-bin/box/composer.lock b/vendor-bin/box/composer.lock index fadacec..3fc14e2 100644 --- a/vendor-bin/box/composer.lock +++ b/vendor-bin/box/composer.lock @@ -3100,5 +3100,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" }