-
Notifications
You must be signed in to change notification settings - Fork 0
/
drupal-paketo-scaffold.settings.php
63 lines (55 loc) · 2.56 KB
/
drupal-paketo-scaffold.settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Do all of this file's work inside of an immediately invoked anonymous
* function in order to create a local scope for variables. The only
* side effect we want to have on the file that includes this one is to
* add to $databases and $settings.
*/
(function () use (&$databases, &$settings) {
$app_root = $_SERVER['CNB_APP_DIR'] ?? '/workspace';
// It is more secure for values of secrets to not be in environment variables.
// Docker's secrets manager passes secrets via a file, so that the environment
// variable is just the name of the file rather than its contents. The
// convention for this pattern is to correspondingly append _FILE to the name
// of the environment variable. If that doesn't exist, we fall back to the
// less secure approach of getting the secret directly from the environment
// variable for cases where Docker's secrets manager or a similar one can't be
// used.
$getSecret = function ($name) {
return isset($_SERVER[$name . '_FILE']) ? file_get_contents($_SERVER[$name . '_FILE']) : $_SERVER[$name];
};
// Add the default datatabase connection if it's not already defined.
if (!isset($databases['default']['default'])) {
$db_driver = $_SERVER['DRUPAL_DB_DRIVER'] ?? 'sqlite';
switch ($db_driver) {
case 'sqlite':
$databases['default']['default'] = [
'driver' => $db_driver,
// The name of the SQLite file within the directory doesn't matter, so use
// the same name as Drupal's web installer's default.
'database' => $app_root . '/' . $_SERVER['DRUPAL_DB_DIR'] . '/.ht.sqlite',
];
break;
case 'mysql':
case 'pgsql':
$databases['default']['default'] = [
'driver' => $db_driver,
'host' => $getSecret('DRUPAL_DB_HOST'),
'username' => $getSecret('DRUPAL_DB_USER'),
'password' => $getSecret('DRUPAL_DB_PASSWORD'),
'database' => $getSecret('DRUPAL_DB_NAME'),
];
break;
}
}
// Add the hash salt.
$settings['hash_salt'] ??= $getSecret('DRUPAL_HASH_SALT');
// Add the non-public files directories.
// - $_SERVER['DRUPAL_FILES_DIR'] should be outside of the web root.
// - The public files directory is not defined here, because we retain the
// default of sites/default/files so that it is web accessible.
$files_root = $app_root . '/' . $_SERVER['DRUPAL_FILES_DIR'];
$settings['config_sync_directory'] ??= $files_root . '/config_sync';
$settings['file_private_path'] ??= $files_root . '/private';
$settings['file_temp_path'] ??= $files_root . '/temp';
})();