diff --git a/bin/build-configs b/bin/build-configs index 072c430..09b85c3 100755 --- a/bin/build-configs +++ b/bin/build-configs @@ -78,6 +78,13 @@ $app->command( ['env.example', '.env.example'], ]); + $extraDatabases = Arr::get($configurationData, 'database.extra_databases', []); + if (count($extraDatabases) > 0) { + $filesystem = new Filesystem(); + $filesystem->mkdir("{$outputDir}/tools/docker/images/database/root/docker-entrypoint-initdb.d"); + $filesToGenerate->push(['extra-databases.sql', 'tools/docker/images/database/root/docker-entrypoint-initdb.d/extra-databases.sql']); + } + if (false !== Arr::get($configurationData, "justfile", true)) { $filesToGenerate->push(['justfile', 'justfile']); } diff --git a/src/Validator/ConfigurationValidator.php b/src/Validator/ConfigurationValidator.php index 25c9cf4..353553d 100644 --- a/src/Validator/ConfigurationValidator.php +++ b/src/Validator/ConfigurationValidator.php @@ -50,7 +50,22 @@ final class ConfigurationValidator implements ValidatorInterface new Assert\Type('string'), ], - 'database' => new Assert\Optional(), + 'database' => new Assert\Collection( + [ + 'extra_databases' => new Assert\Optional( + [ + new Assert\Type(['type' => 'array']), + new Assert\All( + [ + new Assert\Type(['type' => 'string']) + ] + ) + ], + ), + 'type' => new Assert\Type(['type' => 'string']), + 'version' => new Assert\Type(['type' => 'integer']), + ] + ), 'drupal' => new Assert\Optional(), diff --git a/templates/docker-compose.yaml.twig b/templates/docker-compose.yaml.twig index eb20f09..c4bbc63 100644 --- a/templates/docker-compose.yaml.twig +++ b/templates/docker-compose.yaml.twig @@ -82,6 +82,7 @@ services: memory: "${DOCKER_MYSQL_MEMORY:-0}" volumes: - db-data:/var/lib/mysql + {{ database.extra_databases is not empty ? '- ./tools/docker/images/database/root/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d' : '' }} env_file: - .env labels: diff --git a/templates/extra-databases.sql.twig b/templates/extra-databases.sql.twig new file mode 100644 index 0000000..bfae912 --- /dev/null +++ b/templates/extra-databases.sql.twig @@ -0,0 +1,5 @@ +{% for database in database.extra_databases %} +CREATE DATABASE {{ database }}; +GRANT ALL PRIVILEGES ON {{ database }}.* TO drupal@'%' IDENTIFIED BY 'drupal'; + +{% endfor %}