From 1fb75c9d932426b5a92b41ddbc73f2b6010aff44 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 19 Feb 2023 12:56:04 +0000 Subject: [PATCH] feat: make the Drupal docroot configurable Allow for setting a `docroot` directory for Drupal projects. By default, I've set this to `web` as that's what the Drupal Composer scaffold projects use, but other platforms such as Acquia Cloud hosting use `docroot`. This is how it can be configured in `build.yaml`: ```yaml drupal: docroot: docroot ``` Fixes #2 --- src/Console/Command/BuildConfigurationCommand.php | 9 +++++++++ templates/docker-compose.yaml.twig | 2 +- templates/web/caddy/Caddyfile.twig | 2 +- templates/web/nginx/default.conf.twig | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Console/Command/BuildConfigurationCommand.php b/src/Console/Command/BuildConfigurationCommand.php index 2b36e92..9110fd9 100644 --- a/src/Console/Command/BuildConfigurationCommand.php +++ b/src/Console/Command/BuildConfigurationCommand.php @@ -81,6 +81,8 @@ final class BuildConfigurationCommand extends Command 'database' => new Assert\Optional(), + 'drupal' => new Assert\Optional(), + 'docker-compose' => new Assert\Optional(), 'dockerfile' => new Assert\Optional(), @@ -137,6 +139,13 @@ final class BuildConfigurationCommand extends Command $this->filesToGenerate->push(['web/nginx/default.conf', 'tools/docker/images/web/root/etc/nginx/conf.d/default.conf']); } + if ('drupal-project' === Arr::get($configurationData, 'type')) { + // Ensure a "docroot" value is set. + if (null === Arr::get($configurationData, 'drupal.docroot')) { + Arr::set($configurationData, 'drupal.docroot', 'web'); + } + } + $this->generateFiles($configurationData); return Command::SUCCESS; diff --git a/templates/docker-compose.yaml.twig b/templates/docker-compose.yaml.twig index ffb1597..d83f224 100644 --- a/templates/docker-compose.yaml.twig +++ b/templates/docker-compose.yaml.twig @@ -1,6 +1,6 @@ x-app: &default-app volumes: - - "${DOCKER_WEB_VOLUME:-./web:/app/web}" + - "${DOCKER_WEB_VOLUME:-./{{ drupal.docroot }}:/app/{{ drupal.docroot }}}" env_file: - .env restart: "${DOCKER_RESTART_POLICY:-unless-stopped}" diff --git a/templates/web/caddy/Caddyfile.twig b/templates/web/caddy/Caddyfile.twig index 4a02702..83e378a 100644 --- a/templates/web/caddy/Caddyfile.twig +++ b/templates/web/caddy/Caddyfile.twig @@ -1,4 +1,4 @@ :80 -root * /app/docroot +root * /app/{{ drupal.docroot }} file_server php_fastcgi php:9000 diff --git a/templates/web/nginx/default.conf.twig b/templates/web/nginx/default.conf.twig index f941f8c..5b0024e 100644 --- a/templates/web/nginx/default.conf.twig +++ b/templates/web/nginx/default.conf.twig @@ -1,7 +1,7 @@ server { server_name _; - root /app/docroot; + root /app/{{ drupal.docroot }}; location / { try_files $uri /index.php?$query_string;