Remove remaining local config files

This commit is contained in:
Alejandro Celaya 2024-10-23 10:53:09 +02:00
parent 442eea0ea7
commit f3244b35e3
16 changed files with 52 additions and 121 deletions

View file

@ -61,7 +61,6 @@ EXPOSE 8080
# Copy config specific for the image
COPY docker/docker-entrypoint.sh docker-entrypoint.sh
COPY docker/config/shlink_in_docker.local.php config/autoload/shlink_in_docker.local.php
COPY docker/config/php.ini ${PHP_INI_DIR}/conf.d/
USER ${USER_ID}

View file

@ -1,2 +0,0 @@
local.php
*.local.php

View file

@ -2,11 +2,13 @@
declare(strict_types=1);
use Shlinkio\Shlink\Core\Config\EnvVars;
return [
'app_options' => [
'name' => 'Shlink',
'version' => '%SHLINK_VERSION%',
'version' => EnvVars::isDevEnv() ? 'latest' : '%SHLINK_VERSION%',
],
];

View file

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
return [
'app_options' => [
'version' => 'latest',
],
];

View file

@ -3,13 +3,18 @@
declare(strict_types=1);
use Laminas\ConfigAggregator\ConfigAggregator;
use Shlinkio\Shlink\Core\Config\EnvVars;
return [
return (function () {
$isDev = EnvVars::isDevEnv();
'debug' => false,
return [
// Disabling config cache for cli, ensures it's never used for RoadRunner, and also that console
// commands don't generate a cache file that's then used by php-fpm web executions
ConfigAggregator::ENABLE_CACHE => PHP_SAPI !== 'cli',
'debug' => $isDev,
];
// Disabling config cache for cli, ensures it's never used for RoadRunner, and also that console
// commands don't generate a cache file that's then used by php-fpm web executions
ConfigAggregator::ENABLE_CACHE => ! $isDev && PHP_SAPI !== 'cli',
];
})();

View file

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use Laminas\ConfigAggregator\ConfigAggregator;
return [
'debug' => true,
ConfigAggregator::ENABLE_CACHE => false,
];

View file

@ -11,6 +11,7 @@ use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Shlinkio\Shlink\Core\Config\EnvVars;
use Spiral\RoadRunner\Http\PSR7Worker;
use Spiral\RoadRunner\WorkerInterface;
use Symfony\Component\Filesystem\Filesystem;
@ -36,7 +37,7 @@ return [
'lazy_services' => [
'proxies_target_dir' => 'data/proxies',
'proxies_namespace' => 'ShlinkProxy',
'write_proxy_files' => true,
'write_proxy_files' => EnvVars::isProdEnv(),
],
],

View file

@ -1,24 +0,0 @@
<?php
declare(strict_types=1);
use Psr\Container\ContainerInterface;
use Psr\Log;
return [
'dependencies' => [
'lazy_services' => [
'write_proxy_files' => false,
],
'initializers' => [
function (ContainerInterface $container, $instance): void {
if ($instance instanceof Log\LoggerAwareInterface) {
$instance->setLogger($container->get(Log\LoggerInterface::class));
}
},
],
],
];

View file

@ -14,23 +14,33 @@ use Shlinkio\Shlink\Common\Logger\LoggerFactory;
use Shlinkio\Shlink\Common\Logger\LoggerType;
use Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware;
use Shlinkio\Shlink\Common\Middleware\RequestIdMiddleware;
use Shlinkio\Shlink\Core\Config\EnvVars;
use Shlinkio\Shlink\Core\EventDispatcher\Helper\RequestIdProvider;
use Shlinkio\Shlink\EventDispatcher\Util\RequestIdProviderInterface;
use function Shlinkio\Shlink\Config\env;
use function Shlinkio\Shlink\Config\runningInRoadRunner;
return (static function (): array {
$isDev = EnvVars::isDevEnv();
$common = [
'level' => Level::Info->value,
'level' => $isDev ? Level::Debug->value : Level::Info->value,
'processors' => [RequestIdMiddleware::class],
'line_format' =>
'[%datetime%] [%extra.' . RequestIdMiddleware::ATTRIBUTE . '%] %channel%.%level_name% - %message%',
];
// In dev env or the docker container, stream Shlink logs to stderr, otherwise send them to a file
$useStreamForShlinkLogger = $isDev || env('SHLINK_RUNTIME') !== null;
return [
'logger' => [
'Shlink' => [
'Shlink' => $useStreamForShlinkLogger ? [
'type' => LoggerType::STREAM->value,
'destination' => 'php://stderr',
...$common,
] : [
'type' => LoggerType::FILE->value,
...$common,
],

View file

@ -1,18 +0,0 @@
<?php
declare(strict_types=1);
use Monolog\Level;
use Shlinkio\Shlink\Common\Logger\LoggerType;
return [
'logger' => [
'Shlink' => [
'type' => LoggerType::STREAM->value,
'destination' => 'php://stderr',
'level' => Level::Debug->value,
],
],
];

View file

@ -13,7 +13,7 @@ return [
'fastroute' => [
// Disabling config cache for cli, ensures it's never used for RoadRunner, and also that console
// commands don't generate a cache file that's then used by php-fpm web executions
FastRouteRouter::CONFIG_CACHE_ENABLED => PHP_SAPI !== 'cli',
FastRouteRouter::CONFIG_CACHE_ENABLED => EnvVars::isProdEnv() && PHP_SAPI !== 'cli',
FastRouteRouter::CONFIG_CACHE_FILE => 'data/cache/fastroute_cached_routes.php',
],
],

View file

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
use Mezzio\Router\FastRouteRouter;
return [
'router' => [
'fastroute' => [
FastRouteRouter::CONFIG_CACHE_ENABLED => false,
],
],
];

View file

@ -8,10 +8,7 @@ use Laminas\ConfigAggregator;
use Laminas\Diactoros;
use Mezzio;
use Mezzio\ProblemDetails;
use function Shlinkio\Shlink\Config\env;
$isTestEnv = env('APP_ENV') === 'test';
use Shlinkio\Shlink\Core\Config\EnvVars;
return (new ConfigAggregator\ConfigAggregator(
providers: [
@ -29,10 +26,10 @@ return (new ConfigAggregator\ConfigAggregator(
CLI\ConfigProvider::class,
Rest\ConfigProvider::class,
new ConfigAggregator\PhpFileProvider('config/autoload/{,*.}global.php'),
// Local config should not be loaded during tests, whereas test config should be loaded ONLY during tests
new ConfigAggregator\PhpFileProvider(
$isTestEnv ? 'config/test/*.global.php' : 'config/autoload/{,*.}local.php',
),
// Test config should be loaded ONLY during tests
EnvVars::isTestEnv()
? new ConfigAggregator\PhpFileProvider('config/test/*.global.php')
: new ConfigAggregator\ArrayProvider([]),
// Routes have to be loaded last
new ConfigAggregator\PhpFileProvider('config/autoload/routes.config.php'),
],

View file

@ -1,18 +0,0 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink;
use Shlinkio\Shlink\Common\Logger\LoggerType;
return [
'logger' => [
'Shlink' => [
'type' => LoggerType::STREAM->value,
'destination' => 'php://stderr',
],
],
];

View file

@ -27,6 +27,7 @@ use const Shlinkio\Shlink\DEFAULT_SHORT_CODES_LENGTH;
enum EnvVars: string
{
case APP_ENV = 'APP_ENV';
case DELETE_SHORT_URL_THRESHOLD = 'DELETE_SHORT_URL_THRESHOLD';
case DB_DRIVER = 'DB_DRIVER';
case DB_NAME = 'DB_NAME';
@ -117,6 +118,7 @@ enum EnvVars: string
private function defaultValue(): string|int|bool|null
{
return match ($this) {
self::APP_ENV => 'prod',
self::MEMORY_LIMIT => '512M',
self::TIMEZONE => date_default_timezone_get(),
@ -174,4 +176,19 @@ enum EnvVars: string
{
return $this->loadFromEnv() !== null;
}
public static function isProdEnv(): bool
{
return self::APP_ENV->loadFromEnv() === 'prod';
}
public static function isDevEnv(): bool
{
return self::APP_ENV->loadFromEnv() === 'dev';
}
public static function isTestEnv(): bool
{
return self::APP_ENV->loadFromEnv() === 'test';
}
}

View file

@ -1,5 +1,5 @@
LC_ALL=C
#APP_ENV=dev
APP_ENV=dev
#GEOLITE_LICENSE_KEY=
# URL shortener