Added support to build the docker image with RoadRunner instead of openswoole

This commit is contained in:
Alejandro Celaya 2022-08-27 13:01:38 +02:00
parent 529ddacafe
commit a739eb6d60
8 changed files with 40 additions and 20 deletions

View file

@ -1,3 +1,4 @@
bin/rr
config/autoload/*local* config/autoload/*local*
data/infra data/infra
data/cache/* data/cache/*
@ -23,4 +24,3 @@ infection*
build* build*
**/.* **/.*
!config/roadrunner/.rr.yml !config/roadrunner/.rr.yml
bin/helper

View file

@ -2,6 +2,8 @@ FROM php:8.1.9-alpine3.16 as base
ARG SHLINK_VERSION=latest ARG SHLINK_VERSION=latest
ENV SHLINK_VERSION ${SHLINK_VERSION} ENV SHLINK_VERSION ${SHLINK_VERSION}
ARG SHLINK_RUNTIME=openswoole
ENV SHLINK_RUNTIME ${SHLINK_RUNTIME}
ENV OPENSWOOLE_VERSION 4.11.1 ENV OPENSWOOLE_VERSION 4.11.1
ENV PDO_SQLSRV_VERSION 5.10.1 ENV PDO_SQLSRV_VERSION 5.10.1
ENV MS_ODBC_SQL_VERSION 17.5.2.2 ENV MS_ODBC_SQL_VERSION 17.5.2.2
@ -22,8 +24,10 @@ RUN \
# Install openswoole and sqlsrv driver for x86_64 builds # Install openswoole and sqlsrv driver for x86_64 builds
RUN apk add --no-cache --virtual .phpize-deps ${PHPIZE_DEPS} unixodbc-dev && \ RUN apk add --no-cache --virtual .phpize-deps ${PHPIZE_DEPS} unixodbc-dev && \
if [ "$SHLINK_RUNTIME" == 'openswoole' ]; then \
pecl install openswoole-${OPENSWOOLE_VERSION} && \ pecl install openswoole-${OPENSWOOLE_VERSION} && \
docker-php-ext-enable openswoole && \ docker-php-ext-enable openswoole ; \
fi; \
if [ $(uname -m) == "x86_64" ]; then \ if [ $(uname -m) == "x86_64" ]; then \
wget https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_${MS_ODBC_SQL_VERSION}-1_amd64.apk && \ wget https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_${MS_ODBC_SQL_VERSION}-1_amd64.apk && \
apk add --no-cache --allow-untrusted msodbcsql17_${MS_ODBC_SQL_VERSION}-1_amd64.apk && \ apk add --no-cache --allow-untrusted msodbcsql17_${MS_ODBC_SQL_VERSION}-1_amd64.apk && \
@ -38,7 +42,12 @@ FROM base as builder
COPY . . COPY . .
COPY --from=composer:2 /usr/bin/composer ./composer.phar COPY --from=composer:2 /usr/bin/composer ./composer.phar
RUN apk add --no-cache git && \ RUN apk add --no-cache git && \
php composer.phar install --no-dev --optimize-autoloader --prefer-dist --no-progress --no-interaction && \ php composer.phar install --no-dev --prefer-dist --optimize-autoloader --no-progress --no-interaction && \
if [ "$SHLINK_RUNTIME" == 'openswoole' ]; then \
php composer.phar remove spiral/roadrunner spiral/roadrunner-jobs --with-all-dependencies --update-no-dev --optimize-autoloader --no-progress --no-interactionc ; \
elif [ $SHLINK_RUNTIME == 'rr' ]; then \
php composer.phar remove mezzio/mezzio-swoole --with-all-dependencies --update-no-dev --optimize-autoloader --no-progress --no-interaction ; \
fi; \
php composer.phar clear-cache && \ php composer.phar clear-cache && \
rm -r docker composer.* && \ rm -r docker composer.* && \
sed -i "s/%SHLINK_VERSION%/${SHLINK_VERSION}/g" config/autoload/app_options.global.php sed -i "s/%SHLINK_VERSION%/${SHLINK_VERSION}/g" config/autoload/app_options.global.php
@ -49,9 +58,12 @@ FROM base
LABEL maintainer="Alejandro Celaya <alejandro@alejandrocelaya.com>" LABEL maintainer="Alejandro Celaya <alejandro@alejandrocelaya.com>"
COPY --from=builder /etc/shlink . COPY --from=builder /etc/shlink .
RUN ln -s /etc/shlink/bin/cli /usr/local/bin/shlink RUN ln -s /etc/shlink/bin/cli /usr/local/bin/shlink && \
if [ "$SHLINK_RUNTIME" == 'rr' ]; then \
php ./vendor/bin/rr get --location bin/ && chmod +x bin/rr ; \
fi;
# Expose default openswoole port # Expose default port
EXPOSE 8080 EXPOSE 8080
# Copy config specific for the image # Copy config specific for the image

View file

@ -44,7 +44,7 @@
"pugx/shortid-php": "^1.0", "pugx/shortid-php": "^1.0",
"ramsey/uuid": "^4.3", "ramsey/uuid": "^4.3",
"shlinkio/shlink-common": "^5.0", "shlinkio/shlink-common": "^5.0",
"shlinkio/shlink-config": "dev-main#24ccd64 as 2.1", "shlinkio/shlink-config": "dev-main#33004e6 as 2.1",
"shlinkio/shlink-event-dispatcher": "dev-main#48c0137 as 2.6", "shlinkio/shlink-event-dispatcher": "dev-main#48c0137 as 2.6",
"shlinkio/shlink-importer": "^4.0", "shlinkio/shlink-importer": "^4.0",
"shlinkio/shlink-installer": "^8.1", "shlinkio/shlink-installer": "^8.1",

View file

@ -2,8 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
use function Shlinkio\Shlink\Config\env; use function Shlinkio\Shlink\Config\runningInOpenswoole;
use function Shlinkio\Shlink\Config\swooleIsInstalled; use function Shlinkio\Shlink\Config\runningInRoadRunner;
return [ return [
@ -11,9 +11,9 @@ return [
'domain' => [ 'domain' => [
'schema' => 'http', 'schema' => 'http',
'hostname' => sprintf('localhost:%s', match (true) { 'hostname' => sprintf('localhost:%s', match (true) {
PHP_SAPI === 'cli' && env('RR_MODE') !== null => '8800', // Roadrunner runningInRoadRunner() => '8800',
swooleIsInstalled() => '8080', // Swoole runningInOpenswoole() => '8080',
default => '8000', // FPM default => '8000',
}), }),
], ],
'auto_resolve_titles' => true, 'auto_resolve_titles' => true,

View file

@ -13,13 +13,14 @@ use Shlinkio\Shlink\Config\ConfigAggregator\EnvVarLoaderProvider;
use function class_exists; use function class_exists;
use function Shlinkio\Shlink\Config\env; use function Shlinkio\Shlink\Config\env;
use function Shlinkio\Shlink\Config\swooleIsInstalled; use function Shlinkio\Shlink\Config\openswooleIsInstalled;
use function Shlinkio\Shlink\Config\runningInRoadRunner;
use const PHP_SAPI; use const PHP_SAPI;
$isTestEnv = env('APP_ENV') === 'test'; $isTestEnv = env('APP_ENV') === 'test';
$isRR = env('RR_MODE') !== null; // TODO Could check for actual openswoole with runningInOpenswoole()??
$enableSwoole = PHP_SAPI === 'cli' && ! $isRR && swooleIsInstalled(); $enableSwoole = PHP_SAPI === 'cli' && ! runningInRoadRunner() && openswooleIsInstalled();
return (new ConfigAggregator\ConfigAggregator([ return (new ConfigAggregator\ConfigAggregator([
! $isTestEnv ! $isTestEnv

View file

@ -46,8 +46,8 @@ reload:
patterns: ['.php'] patterns: ['.php']
services: services:
http: http:
dirs: ['../../bin', '../../config', '../../data/migrations', '../../docker', '../../module', '../../vendor'] dirs: ['../../bin', '../../config', '../../data/migrations', '../../module', '../../vendor']
recursive: true recursive: true
jobs: jobs:
dirs: ['../../bin', '../../config', '../../data/migrations', '../../docker', '../../module', '../../vendor'] dirs: ['../../bin', '../../config', '../../data/migrations', '../../module', '../../vendor']
recursive: true recursive: true

View file

@ -6,11 +6,14 @@ namespace Shlinkio\Shlink;
use Shlinkio\Shlink\Common\Logger\LoggerType; use Shlinkio\Shlink\Common\Logger\LoggerType;
use function Shlinkio\Shlink\Config\runningInRoadRunner;
return [ return [
'logger' => [ 'logger' => [
'Shlink' => [ 'Shlink' => [
'type' => LoggerType::STREAM->value, 'type' => LoggerType::STREAM->value,
'destination' => runningInRoadRunner() ? 'php://stderr' : 'php://stdout',
], ],
], ],

View file

@ -31,6 +31,10 @@ if [ $ENABLE_PERIODIC_VISIT_LOCATE ]; then
/usr/sbin/crond & /usr/sbin/crond &
fi fi
if [ "$SHLINK_RUNTIME" == 'openswoole' ]; then
# When restarting the container, openswoole might think it is already in execution # When restarting the container, openswoole might think it is already in execution
# This forces the app to be started every second until the exit code is 0 # This forces the app to be started every second until the exit code is 0
until php vendor/bin/laminas mezzio:swoole:start; do sleep 1 ; done until php vendor/bin/laminas mezzio:swoole:start; do sleep 1 ; done
elif [ "$SHLINK_RUNTIME" == 'rr' ]; then
./bin/rr serve -c config/roadrunner/.rr.yml
fi