diff --git a/.dockerignore b/.dockerignore index ac530ed3e..beca6373a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ +bin/rr config/autoload/*local* data/infra data/cache/* @@ -23,4 +24,3 @@ infection* build* **/.* !config/roadrunner/.rr.yml -bin/helper diff --git a/Dockerfile b/Dockerfile index 2944db45d..bc0f4fe21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,8 @@ FROM php:8.1.9-alpine3.16 as base ARG SHLINK_VERSION=latest ENV SHLINK_VERSION ${SHLINK_VERSION} +ARG SHLINK_RUNTIME=openswoole +ENV SHLINK_RUNTIME ${SHLINK_RUNTIME} ENV OPENSWOOLE_VERSION 4.11.1 ENV PDO_SQLSRV_VERSION 5.10.1 ENV MS_ODBC_SQL_VERSION 17.5.2.2 @@ -22,8 +24,10 @@ RUN \ # Install openswoole and sqlsrv driver for x86_64 builds RUN apk add --no-cache --virtual .phpize-deps ${PHPIZE_DEPS} unixodbc-dev && \ - pecl install openswoole-${OPENSWOOLE_VERSION} && \ - docker-php-ext-enable openswoole && \ + if [ "$SHLINK_RUNTIME" == 'openswoole' ]; then \ + pecl install openswoole-${OPENSWOOLE_VERSION} && \ + docker-php-ext-enable openswoole ; \ + fi; \ 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 && \ apk add --no-cache --allow-untrusted msodbcsql17_${MS_ODBC_SQL_VERSION}-1_amd64.apk && \ @@ -38,7 +42,12 @@ FROM base as builder COPY . . COPY --from=composer:2 /usr/bin/composer ./composer.phar 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 && \ rm -r docker composer.* && \ sed -i "s/%SHLINK_VERSION%/${SHLINK_VERSION}/g" config/autoload/app_options.global.php @@ -49,9 +58,12 @@ FROM base LABEL maintainer="Alejandro Celaya " 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 # Copy config specific for the image diff --git a/composer.json b/composer.json index 54d180e35..d8b2874fe 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "pugx/shortid-php": "^1.0", "ramsey/uuid": "^4.3", "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-importer": "^4.0", "shlinkio/shlink-installer": "^8.1", diff --git a/config/autoload/url-shortener.local.php.dist b/config/autoload/url-shortener.local.php.dist index 1ed5a47e2..f49570e1c 100644 --- a/config/autoload/url-shortener.local.php.dist +++ b/config/autoload/url-shortener.local.php.dist @@ -2,8 +2,8 @@ declare(strict_types=1); -use function Shlinkio\Shlink\Config\env; -use function Shlinkio\Shlink\Config\swooleIsInstalled; +use function Shlinkio\Shlink\Config\runningInOpenswoole; +use function Shlinkio\Shlink\Config\runningInRoadRunner; return [ @@ -11,9 +11,9 @@ return [ 'domain' => [ 'schema' => 'http', 'hostname' => sprintf('localhost:%s', match (true) { - PHP_SAPI === 'cli' && env('RR_MODE') !== null => '8800', // Roadrunner - swooleIsInstalled() => '8080', // Swoole - default => '8000', // FPM + runningInRoadRunner() => '8800', + runningInOpenswoole() => '8080', + default => '8000', }), ], 'auto_resolve_titles' => true, diff --git a/config/config.php b/config/config.php index cacf9bcd6..1c4fa40b3 100644 --- a/config/config.php +++ b/config/config.php @@ -13,13 +13,14 @@ use function class_exists; 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; $isTestEnv = env('APP_ENV') === 'test'; -$isRR = env('RR_MODE') !== null; -$enableSwoole = PHP_SAPI === 'cli' && ! $isRR && swooleIsInstalled(); +// TODO Could check for actual openswoole with runningInOpenswoole()?? +$enableSwoole = PHP_SAPI === 'cli' && ! runningInRoadRunner() && openswooleIsInstalled(); return (new ConfigAggregator\ConfigAggregator([ ! $isTestEnv diff --git a/config/roadrunner/.rr.dev.yml b/config/roadrunner/.rr.dev.yml index 7f06fc9f1..df6e29930 100644 --- a/config/roadrunner/.rr.dev.yml +++ b/config/roadrunner/.rr.dev.yml @@ -46,8 +46,8 @@ reload: patterns: ['.php'] services: http: - dirs: ['../../bin', '../../config', '../../data/migrations', '../../docker', '../../module', '../../vendor'] + dirs: ['../../bin', '../../config', '../../data/migrations', '../../module', '../../vendor'] recursive: true jobs: - dirs: ['../../bin', '../../config', '../../data/migrations', '../../docker', '../../module', '../../vendor'] + dirs: ['../../bin', '../../config', '../../data/migrations', '../../module', '../../vendor'] recursive: true diff --git a/docker/config/shlink_in_docker.local.php b/docker/config/shlink_in_docker.local.php index 4fba24b6d..9dc99351d 100644 --- a/docker/config/shlink_in_docker.local.php +++ b/docker/config/shlink_in_docker.local.php @@ -6,11 +6,14 @@ 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', ], ], diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index f1c4c4956..c191afe70 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -31,6 +31,10 @@ if [ $ENABLE_PERIODIC_VISIT_LOCATE ]; then /usr/sbin/crond & fi -# 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 -until php vendor/bin/laminas mezzio:swoole:start; do sleep 1 ; done +if [ "$SHLINK_RUNTIME" == 'openswoole' ]; then + # 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 + 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