d9dd782229
Test Action / Test Base Modules Requires PHP (push) Failing after 10m29s
Test Action / Test Base Modules Installation (push) Failing after 10m31s
Test Action / Test Node (push) Failing after 10m37s
Test Action / Test Build Command (push) Failing after 14m37s
Test Action / Test Custom Server Path (push) Failing after 15m23s
Test Action / Test All Components (push) Failing after 15m25s
Test Action / Test nginx (push) Failing after 15m27s
Test Action / Test Database Configuration (push) Failing after 15m33s
Test Action / Test PHP (push) Failing after 15m35s
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Applies environment-provided overrides to a Ktrix server's config/system.php.
|
|
*
|
|
* Used by action-server-install to point a freshly checked-out server at the
|
|
* database and settings provided by the calling CI workflow, without hand
|
|
* editing the repository's committed config file.
|
|
*
|
|
* Usage: php configure-server.php <path-to-config/system.php>
|
|
*
|
|
* All overrides are read from environment variables and are optional; an
|
|
* unset or empty variable leaves the corresponding config value untouched:
|
|
* DATABASE_URI -> $config['database']['uri']
|
|
* DATABASE_NAME -> $config['database']['database']
|
|
* APP_ENVIRONMENT -> $config['environment']
|
|
* SECURITY_SALT -> $config['security.salt']
|
|
*/
|
|
|
|
$path = $argv[1] ?? null;
|
|
|
|
if (!$path || !is_file($path)) {
|
|
fwrite(STDERR, "Configuration file not found: {$path}\n");
|
|
exit(1);
|
|
}
|
|
|
|
$config = include $path;
|
|
|
|
if (!is_array($config)) {
|
|
fwrite(STDERR, "Configuration file did not return an array: {$path}\n");
|
|
exit(1);
|
|
}
|
|
|
|
// Nested overrides: env var => [top-level key, nested key]
|
|
$nestedOverrides = [
|
|
'DATABASE_URI' => ['database', 'uri'],
|
|
'DATABASE_NAME' => ['database', 'database'],
|
|
];
|
|
|
|
foreach ($nestedOverrides as $env => [$group, $key]) {
|
|
$value = getenv($env);
|
|
if ($value === false || $value === '') {
|
|
continue;
|
|
}
|
|
$config[$group][$key] = $value;
|
|
echo " - {$group}.{$key} overridden\n";
|
|
}
|
|
|
|
// Flat overrides: env var => config key
|
|
$flatOverrides = [
|
|
'APP_ENVIRONMENT' => 'environment',
|
|
'SECURITY_SALT' => 'security.salt',
|
|
];
|
|
|
|
foreach ($flatOverrides as $env => $key) {
|
|
$value = getenv($env);
|
|
if ($value === false || $value === '') {
|
|
continue;
|
|
}
|
|
$config[$key] = $value;
|
|
echo " - {$key} overridden\n";
|
|
}
|
|
|
|
$export = var_export($config, true);
|
|
file_put_contents($path, "<?php\n\nreturn {$export};\n");
|
|
|
|
echo "Configuration written to {$path}\n";
|