Skip to content

Commit

Permalink
Added support to build the docker image with RoadRunner instead of op…
Browse files Browse the repository at this point in the history
…enswoole
  • Loading branch information
acelaya committed Aug 27, 2022
1 parent 529ddac commit a739eb6
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
@@ -1,3 +1,4 @@
bin/rr
config/autoload/*local*
data/infra
data/cache/*
Expand All @@ -23,4 +24,3 @@ infection*
build*
**/.*
!config/roadrunner/.rr.yml
bin/helper
22 changes: 17 additions & 5 deletions Dockerfile
Expand Up @@ -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
Expand All @@ -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 && \
Expand All @@ -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
Expand All @@ -49,9 +58,12 @@ FROM base
LABEL maintainer="Alejandro Celaya <alejandro@alejandrocelaya.com>"

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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions config/autoload/url-shortener.local.php.dist
Expand Up @@ -2,18 +2,18 @@

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 [

'url_shortener' => [
'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,
Expand Down
7 changes: 4 additions & 3 deletions config/config.php
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/roadrunner/.rr.dev.yml
Expand Up @@ -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
3 changes: 3 additions & 0 deletions docker/config/shlink_in_docker.local.php
Expand Up @@ -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',
],
],

Expand Down
10 changes: 7 additions & 3 deletions docker/docker-entrypoint.sh
Expand Up @@ -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

0 comments on commit a739eb6

Please sign in to comment.