Merge pull request #2211 from acelaya-forks/feature/explicit-env-from-config

Promote installer config options as env vars explicitly
This commit is contained in:
Alejandro Celaya 2024-10-08 09:07:11 +02:00 committed by GitHub
commit a8e4b2fceb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 11 deletions

View File

@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
## [Unreleased]
### Added
* *Nothing*
### Changed
* [#2208](https://github.com/shlinkio/shlink/issues/2208) Explicitly promote installer config options as env vars, instead of as a side effect of loading the app config.
### Deprecated
* *Nothing*
### Removed
* *Nothing*
### Fixed
* *Nothing*
## [4.2.1] - 2024-10-04 ## [4.2.1] - 2024-10-04
### Added ### Added
* [#2183](https://github.com/shlinkio/shlink/issues/2183) Redis database index to be used can now be specified in the connection URI path, and Shlink will honor it. * [#2183](https://github.com/shlinkio/shlink/issues/2183) Redis database index to be used can now be specified in the connection URI path, and Shlink will honor it.

View File

@ -45,7 +45,7 @@
"ramsey/uuid": "^4.7", "ramsey/uuid": "^4.7",
"shlinkio/doctrine-specification": "^2.1.1", "shlinkio/doctrine-specification": "^2.1.1",
"shlinkio/shlink-common": "^6.3", "shlinkio/shlink-common": "^6.3",
"shlinkio/shlink-config": "^3.0", "shlinkio/shlink-config": "dev-main#76a96ee as 3.1",
"shlinkio/shlink-event-dispatcher": "^4.1", "shlinkio/shlink-event-dispatcher": "^4.1",
"shlinkio/shlink-importer": "^5.3.2", "shlinkio/shlink-importer": "^5.3.2",
"shlinkio/shlink-installer": "^9.2", "shlinkio/shlink-installer": "^9.2",

View File

@ -8,18 +8,13 @@ use Laminas\ConfigAggregator;
use Laminas\Diactoros; use Laminas\Diactoros;
use Mezzio; use Mezzio;
use Mezzio\ProblemDetails; use Mezzio\ProblemDetails;
use Shlinkio\Shlink\Config\ConfigAggregator\EnvVarLoaderProvider;
use function Shlinkio\Shlink\Config\env; use function Shlinkio\Shlink\Config\env;
use function Shlinkio\Shlink\Core\enumValues;
$isTestEnv = env('APP_ENV') === 'test'; $isTestEnv = env('APP_ENV') === 'test';
return (new ConfigAggregator\ConfigAggregator( return (new ConfigAggregator\ConfigAggregator(
providers: [ providers: [
! $isTestEnv
? new EnvVarLoaderProvider('config/params/generated_config.php', enumValues(Core\Config\EnvVars::class))
: new ConfigAggregator\ArrayProvider([]),
Mezzio\ConfigProvider::class, Mezzio\ConfigProvider::class,
Mezzio\Router\ConfigProvider::class, Mezzio\Router\ConfigProvider::class,
Mezzio\Router\FastRouteRouter\ConfigProvider::class, Mezzio\Router\FastRouteRouter\ConfigProvider::class,

View File

@ -6,13 +6,20 @@ use Laminas\ServiceManager\ServiceManager;
use Shlinkio\Shlink\Core\Config\EnvVars; use Shlinkio\Shlink\Core\Config\EnvVars;
use Symfony\Component\Lock; use Symfony\Component\Lock;
use function Shlinkio\Shlink\Config\loadEnvVarsFromConfig;
use function Shlinkio\Shlink\Core\enumValues;
use const Shlinkio\Shlink\LOCAL_LOCK_FACTORY; use const Shlinkio\Shlink\LOCAL_LOCK_FACTORY;
chdir(dirname(__DIR__)); chdir(dirname(__DIR__));
require 'vendor/autoload.php'; require 'vendor/autoload.php';
// This is one of the first files loaded. Configure the timezone here // Promote env vars from installer config
loadEnvVarsFromConfig('config/params/generated_config.php', enumValues(EnvVars::class));
// This is one of the first files loaded. Configure the timezone and memory limit here
ini_set('memory_limit', EnvVars::MEMORY_LIMIT->loadFromEnv('512M'));
date_default_timezone_set(EnvVars::TIMEZONE->loadFromEnv(date_default_timezone_get())); date_default_timezone_set(EnvVars::TIMEZONE->loadFromEnv(date_default_timezone_get()));
// This class alias tricks the ConfigAbstractFactory to return Lock\Factory instances even with a different service name // This class alias tricks the ConfigAbstractFactory to return Lock\Factory instances even with a different service name
@ -23,10 +30,6 @@ if (! class_exists(LOCAL_LOCK_FACTORY)) {
return (static function (): ServiceManager { return (static function (): ServiceManager {
$config = require __DIR__ . '/config.php'; $config = require __DIR__ . '/config.php';
// Set memory limit right after loading config, to ensure installer config has been promoted as env vars
ini_set('memory_limit', EnvVars::MEMORY_LIMIT->loadFromEnv('512M'));
$container = new ServiceManager($config['dependencies']); $container = new ServiceManager($config['dependencies']);
$container->setService('config', $config); $container->setService('config', $config);