From e6a31b16eda7ae5f6b78726d7649fca457b97765 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 16 Apr 2023 13:10:24 +0200 Subject: [PATCH 1/3] Switch to roadrunner as default docker runtime --- .github/workflows/publish-docker-image.yml | 29 ++++++++++++---------- Dockerfile | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index 7fb52fe1..f9e1630c 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -2,8 +2,6 @@ name: Build and publish docker image on: push: - branches: - - develop paths-ignore: - 'LICENSE' - '.*' @@ -12,24 +10,29 @@ on: - '*.yml*' - '*.json5' - '*.neon' + branches: + - develop tags: - 'v*' jobs: - build-openswoole: + build-image: + strategy: + matrix: + include: + - runtime: 'rr' + platforms: 'linux/arm64/v8,linux/amd64' + - runtime: 'rr' + tag-suffix: 'roadrunner' + platforms: 'linux/arm64/v8,linux/amd64' + - runtime: 'openswoole' + tag-suffix: 'openswoole' uses: shlinkio/github-actions/.github/workflows/docker-build-and-publish.yml@main secrets: inherit with: image-name: shlinkio/shlink version-arg-name: SHLINK_VERSION - - build-roadrunner: - uses: shlinkio/github-actions/.github/workflows/docker-build-and-publish.yml@main - secrets: inherit - with: - image-name: shlinkio/shlink - version-arg-name: SHLINK_VERSION - platforms: 'linux/arm64/v8,linux/amd64' - tags-suffix: roadrunner + platforms: ${{ matrix.platforms }} + tags-suffix: ${{ matrix.tag-suffix }} extra-build-args: | - SHLINK_RUNTIME=rr + SHLINK_RUNTIME=${{ matrix.runtime }} diff --git a/Dockerfile b/Dockerfile index c0120921..10897176 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM php:8.2-alpine3.17 as base ARG SHLINK_VERSION=latest ENV SHLINK_VERSION ${SHLINK_VERSION} -ARG SHLINK_RUNTIME=openswoole +ARG SHLINK_RUNTIME=rr ENV SHLINK_RUNTIME ${SHLINK_RUNTIME} ENV OPENSWOOLE_VERSION 22.0.0 ENV PDO_SQLSRV_VERSION 5.10.1 From 28d93ea5e06c2f90440aa63b2068eb154abda958 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 16 Apr 2023 13:14:54 +0200 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40be8aad..ab9409d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this ### Changed * [#1755](https://github.com/shlinkio/shlink/issues/1755) Update to roadrunner 2023 +* [#1745](https://github.com/shlinkio/shlink/issues/1745) Roadrunner is now the default docker runtime. + + There are now three different docker images published: + + * Versions without suffix (like `3.6.0`) will contain the default runtime, whichever it is. + * Versions with `-roadrunner` suffix (like `3.6.0-roadrunner`) will always use roadrunner as the runtime, even if default one changes in the future. + * Versions with `-openswoole` suffix (like `3.6.0-openswoole`) will always use openswoole as the runtime, even if default one changes in the future. ### Deprecated * *Nothing* From a797b74a70e1e4f199f6a1776705eb2aac98469a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 7 May 2023 13:18:19 +0200 Subject: [PATCH 3/3] Standardize logger for all Shlink execution contexts --- composer.json | 2 +- config/autoload/logger.global.php | 82 +++++++++++-------- config/autoload/logger.local.php.dist | 8 +- .../autoload/middleware-pipeline.global.php | 2 + config/roadrunner/.rr.dev.yml | 2 +- config/roadrunner/.rr.yml | 2 +- config/test/test_config.global.php | 1 + docker/config/shlink_in_docker.local.php | 4 +- 8 files changed, 56 insertions(+), 47 deletions(-) diff --git a/composer.json b/composer.json index 719d392d..2bce658c 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "php-middleware/request-id": "^4.1", "pugx/shortid-php": "^1.1", "ramsey/uuid": "^4.7", - "shlinkio/shlink-common": "dev-main#29dd933 as 5.5", + "shlinkio/shlink-common": "dev-main#88a34f1 as 5.5", "shlinkio/shlink-config": "^2.4", "shlinkio/shlink-event-dispatcher": "dev-main#8c677ae as 3.0", "shlinkio/shlink-importer": "dev-main#6b63b12 as 5.1", diff --git a/config/autoload/logger.global.php b/config/autoload/logger.global.php index 2da1eda3..1820c480 100644 --- a/config/autoload/logger.global.php +++ b/config/autoload/logger.global.php @@ -4,51 +4,63 @@ declare(strict_types=1); namespace Shlinkio\Shlink; +use Laminas\ServiceManager\Factory\InvokableFactory; use Monolog\Level; use Monolog\Logger; use PhpMiddleware\RequestId; use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Shlinkio\Shlink\Common\Logger\LoggerFactory; use Shlinkio\Shlink\Common\Logger\LoggerType; +use Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware; -$common = [ - 'level' => Level::Info->value, - 'processors' => [RequestId\MonologProcessor::class], - 'line_format' => '[%datetime%] [%extra.request_id%] %channel%.%level_name% - %message%', -]; +use function Shlinkio\Shlink\Config\runningInRoadRunner; -return [ +return (static function (): array { + $common = [ + 'level' => Level::Info->value, + 'processors' => [RequestId\MonologProcessor::class], + 'line_format' => '[%datetime%] [%extra.request_id%] %channel%.%level_name% - %message%', + ]; - 'logger' => [ - 'Shlink' => [ - 'type' => LoggerType::FILE->value, - ...$common, - ], - 'Access' => [ - 'type' => LoggerType::STREAM->value, - ...$common, - ], - ], + return [ - 'dependencies' => [ - 'factories' => [ - 'Logger_Shlink' => [LoggerFactory::class, 'Shlink'], - 'Logger_Access' => [LoggerFactory::class, 'Access'], - ], - 'aliases' => [ - 'logger' => 'Logger_Shlink', - Logger::class => 'Logger_Shlink', - LoggerInterface::class => 'Logger_Shlink', - ], - ], - - 'mezzio-swoole' => [ - 'swoole-http-server' => [ - 'logger' => [ - 'logger-name' => 'Logger_Access', - 'format' => '%u "%r" %>s %B', + 'logger' => [ + 'Shlink' => [ + 'type' => LoggerType::FILE->value, + ...$common, + ], + 'Access' => [ + 'type' => LoggerType::STREAM->value, + 'destination' => 'php://stderr', + 'add_new_line' => ! runningInRoadRunner(), + ...$common, ], ], - ], -]; + 'dependencies' => [ + 'factories' => [ + 'Logger_Shlink' => [LoggerFactory::class, 'Shlink'], + 'Logger_Access' => [LoggerFactory::class, 'Access'], + NullLogger::class => InvokableFactory::class, + ], + 'aliases' => [ + 'logger' => 'Logger_Shlink', + Logger::class => 'Logger_Shlink', + LoggerInterface::class => 'Logger_Shlink', + AccessLogMiddleware::LOGGER_SERVICE_NAME => 'Logger_Access', + ], + ], + + 'mezzio-swoole' => [ + 'swoole-http-server' => [ + 'logger' => [ + // Let's disable mezio-swoole access logging, so that we can provide our own implementation, + // consistent for roadrunner and openswoole + 'logger-name' => NullLogger::class, + ], + ], + ], + + ]; +})(); diff --git a/config/autoload/logger.local.php.dist b/config/autoload/logger.local.php.dist index 919f6cdb..fe2c8c54 100644 --- a/config/autoload/logger.local.php.dist +++ b/config/autoload/logger.local.php.dist @@ -5,16 +5,12 @@ declare(strict_types=1); use Monolog\Level; use Shlinkio\Shlink\Common\Logger\LoggerType; -use function Shlinkio\Shlink\Config\runningInOpenswoole; - -$logToStream = runningInOpenswoole(); - return [ 'logger' => [ 'Shlink' => [ - // For openswoole, send logs as stream - 'type' => $logToStream ? LoggerType::STREAM->value : LoggerType::FILE->value, + 'type' => LoggerType::STREAM->value, + 'destination' => 'php://stderr', 'level' => Level::Debug->value, ], ], diff --git a/config/autoload/middleware-pipeline.global.php b/config/autoload/middleware-pipeline.global.php index 25db6b7b..cb8045e9 100644 --- a/config/autoload/middleware-pipeline.global.php +++ b/config/autoload/middleware-pipeline.global.php @@ -9,6 +9,7 @@ use Mezzio\ProblemDetails; use Mezzio\Router; use PhpMiddleware\RequestId\RequestIdMiddleware; use RKA\Middleware\IpAddress; +use Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware; use Shlinkio\Shlink\Common\Middleware\ContentLengthMiddleware; return [ @@ -16,6 +17,7 @@ return [ 'middleware_pipeline' => [ 'error-handler' => [ 'middleware' => [ + AccessLogMiddleware::class, ContentLengthMiddleware::class, RequestIdMiddleware::class, ErrorHandler::class, diff --git a/config/roadrunner/.rr.dev.yml b/config/roadrunner/.rr.dev.yml index cc0bbf29..9038c07e 100644 --- a/config/roadrunner/.rr.dev.yml +++ b/config/roadrunner/.rr.dev.yml @@ -31,7 +31,7 @@ logs: mode: development channels: http: - level: debug + mode: 'off' # Disable logging as Shlink handles it internally server: level: debug metrics: diff --git a/config/roadrunner/.rr.yml b/config/roadrunner/.rr.yml index d44801ee..b4074f96 100644 --- a/config/roadrunner/.rr.yml +++ b/config/roadrunner/.rr.yml @@ -31,6 +31,6 @@ logs: mode: production channels: http: - level: info # Log all http requests, set to info to disable + mode: 'off' # Disable logging as Shlink handles it internally server: level: debug # Everything written to worker stderr is logged diff --git a/config/test/test_config.global.php b/config/test/test_config.global.php index ac62f8a6..1beed0e3 100644 --- a/config/test/test_config.global.php +++ b/config/test/test_config.global.php @@ -121,6 +121,7 @@ $buildTestLoggerConfig = static fn (string $filename) => [ 'level' => Level::Debug->value, 'type' => LoggerType::STREAM->value, 'destination' => sprintf('data/log/api-tests/%s', $filename), + 'add_new_line' => true, ]; return [ diff --git a/docker/config/shlink_in_docker.local.php b/docker/config/shlink_in_docker.local.php index 9dc99351..2d5d6a06 100644 --- a/docker/config/shlink_in_docker.local.php +++ b/docker/config/shlink_in_docker.local.php @@ -6,14 +6,12 @@ namespace Shlinkio\Shlink; use Shlinkio\Shlink\Common\Logger\LoggerType; -use function Shlinkio\Shlink\Config\runningInRoadRunner; - return [ 'logger' => [ 'Shlink' => [ 'type' => LoggerType::STREAM->value, - 'destination' => runningInRoadRunner() ? 'php://stderr' : 'php://stdout', + 'destination' => 'php://stderr', ], ],