Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 297510

Making Drupal automatically installable with default environment variables

$
0
0

Problem/Motivation

Drupal is automatically installable if there is a $databases definition and hash_salt.

We should provide default getenv calls that allow reading from environment variables. This allows bypassing needing sites/default/settings.php. Here's my normal pattern, which I'm sure many already have. The only quirk is defining SQLite or anything.

$settings['hash_salt'] = getenv('DRUPAL_HASH_SALT') ?: NULL;

$settings['deployment_identifier'] = getenv('DEPLOYMENT_IDENTIFIER')?: NULL;

if (getenv('DRUPAL_DB_DRIVER') !== 'sqlite') {
  $databases['default']['default'] = [
    'driver' => getenv('DRUPAL_DB_DRIVER'),
    'database' => getenv('DRUPAL_DATABASE_NAME'),
    'username' => getenv('DRUPAL_DATABASE_USERNAME'),
    'password' => getenv('DRUPAL_DATABASE_PASSWORD'),
    'host' => getenv('DRUPAL_DATABASE_HOST'),
    'port' => getenv('DRUPAL_DATABASE_PORT'),
  ];
}
else {
  $databases['default']['default'] = [
   // turn this to env
    'database' => '../private/db.sqlite',
    'prefix' => '',
    'namespace' => 'Drupal\\Core\\Database\\Driver\\sqlite',
    'driver' => 'sqlite',
  ];
}

Then we document that if you set these on your VM, k8s manifest, whatever, it "just works"

I'm not proposing we add vlucas/phpdotenv, we just provide support for default environment variables. Other frameworks do this and allow customizing them anyway. If the environment variables are not present, the system works as if there is nothing configured.

Steps to reproduce

Proposed resolution

TBD

Drupal assumes the $databases array will be populated by \Drupal\Core\DrupalKernel::initializeSettings.

This calls \Drupal\Core\Site\Settings::initialize which sets the database connection information:

    // Initialize databases.
    Database::setMultipleConnectionInfo($databases, $class_loader, $app_root);

Maybe in \Drupal\Core\Site\Settings::initialize or \Drupal\Core\Database\Database has a static method that the settings initialization uses.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 297510

Trending Articles