From 00a96e621583d695aa114e543f3fbfde5f2a190e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 3 Oct 2020 11:49:25 +0200 Subject: [PATCH 1/4] Allowed to change swoole port in docker image by using the PORT env var --- Dockerfile | 6 +++--- docker/config/shlink_in_docker.local.php | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1cd764e0..0c5411e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM php:7.4.9-alpine3.12 as base -ARG SHLINK_VERSION=2.2.2 +ARG SHLINK_VERSION=2.3.0 ENV SHLINK_VERSION ${SHLINK_VERSION} ENV SWOOLE_VERSION 4.5.2 ENV LC_ALL "C" @@ -44,7 +44,7 @@ RUN apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS && \ # Install shlink FROM base as builder COPY . . -COPY --from=composer:1.10.1 /usr/bin/composer ./composer.phar +COPY --from=composer:1.10.13 /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 clear-cache && \ @@ -59,7 +59,7 @@ LABEL maintainer="Alejandro Celaya " COPY --from=builder /etc/shlink . RUN ln -s /etc/shlink/bin/cli /usr/local/bin/shlink -# Expose swoole port +# Expose default swoole port EXPOSE 8080 # Expose params config dir, since the user is expected to provide custom config from there diff --git a/docker/config/shlink_in_docker.local.php b/docker/config/shlink_in_docker.local.php index 8d3c55fa..8efee8a4 100644 --- a/docker/config/shlink_in_docker.local.php +++ b/docker/config/shlink_in_docker.local.php @@ -159,6 +159,7 @@ return [ 'mezzio-swoole' => [ 'swoole-http-server' => [ + 'port' => (int) env('PORT', 8080), 'options' => [ 'worker_num' => (int) env('WEB_WORKER_NUM', 16), 'task_worker_num' => (int) env('TASK_WORKER_NUM', 16), From c8d7413dd46118106bf8fc8cffddac0c61711c70 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 3 Oct 2020 11:52:27 +0200 Subject: [PATCH 2/4] Documented support for PORT env var in Docker image --- docker/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docker/README.md b/docker/README.md index 89c9565b..2cc0b5b9 100644 --- a/docker/README.md +++ b/docker/README.md @@ -176,15 +176,17 @@ This is the complete list of supported env vars: * `ANONYMIZE_REMOTE_ADDR`: Tells if IP addresses from visitors should be obfuscated before storing them in the database. Default value is `true`. **Careful!** Setting this to `false` will make your Shlink instance no longer be in compliance with the GDPR and other similar data protection regulations. * `REDIRECT_STATUS_CODE`: Either **301** or **302**. Used to determine if redirects from short to long URLs should be done with a 301 or 302 status. Defaults to 302. * `REDIRECT_CACHE_LIFETIME`: Allows to set the amount of seconds that redirects should be cached when redirect status is 301. Default values is 30. +* `PORT`: Can be used to set the port in which shlink listens. Defaults to 8080 (Some cloud providers, like Google cloud or Heroku, expect to be able to customize exposed port by providing this env var). An example using all env vars could look like this: ```bash docker run \ --name shlink \ - -p 8080:8080 \ + -p 8080:8888 \ -e SHORT_DOMAIN_HOST=doma.in \ -e SHORT_DOMAIN_SCHEMA=https \ + -e PORT=8888 \ -e DB_DRIVER=mysql \ -e DB_NAME=shlink \ -e DB_USER=root \ @@ -257,7 +259,8 @@ The whole configuration should have this format, but it can be split into multip "mercure_jwt_secret": "super_secret_key", "anonymize_remote_addr": false, "redirect_status_code": 301, - "redirect_cache_lifetime": 90 + "redirect_cache_lifetime": 90, + "port": 8888 } ``` From 450eea64aa5338fad4b4545270d800e5b529fff1 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 3 Oct 2020 11:54:31 +0200 Subject: [PATCH 3/4] Added support for port option in SimplifiedConfigParser --- module/Core/src/Config/SimplifiedConfigParser.php | 1 + module/Core/test/Config/SimplifiedConfigParserTest.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/module/Core/src/Config/SimplifiedConfigParser.php b/module/Core/src/Config/SimplifiedConfigParser.php index 38fbdea3..aebeb2c3 100644 --- a/module/Core/src/Config/SimplifiedConfigParser.php +++ b/module/Core/src/Config/SimplifiedConfigParser.php @@ -40,6 +40,7 @@ class SimplifiedConfigParser 'anonymize_remote_addr' => ['url_shortener', 'anonymize_remote_addr'], 'redirect_status_code' => ['url_shortener', 'redirect_status_code'], 'redirect_cache_lifetime' => ['url_shortener', 'redirect_cache_lifetime'], + 'port' => ['mezzio-swoole', 'swoole-http-server', 'port'], ]; private const SIMPLIFIED_CONFIG_SIDE_EFFECTS = [ 'delete_short_url_threshold' => [ diff --git a/module/Core/test/Config/SimplifiedConfigParserTest.php b/module/Core/test/Config/SimplifiedConfigParserTest.php index 9d4bca69..dc85196a 100644 --- a/module/Core/test/Config/SimplifiedConfigParserTest.php +++ b/module/Core/test/Config/SimplifiedConfigParserTest.php @@ -67,6 +67,7 @@ class SimplifiedConfigParserTest extends TestCase 'anonymize_remote_addr' => false, 'redirect_status_code' => 301, 'redirect_cache_lifetime' => 90, + 'port' => 8888, ]; $expected = [ 'app_options' => [ @@ -132,6 +133,7 @@ class SimplifiedConfigParserTest extends TestCase 'mezzio-swoole' => [ 'swoole-http-server' => [ + 'port' => 8888, 'options' => [ 'task_worker_num' => 50, ], From c6c78f383f335e823d4fdb957e3ffd13f217f91a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 3 Oct 2020 11:56:09 +0200 Subject: [PATCH 4/4] Updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba16ae5e..df10baf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this * REST endpoint: `GET /rest/v2/domains` * CLI Command: `domain:list` +* [#832](https://github.com/shlinkio/shlink/issues/832) Added support to customize the port in which the docker image listens by using the `PORT` env var or the `port` config option. + #### Changed * [#836](https://github.com/shlinkio/shlink/issues/836) Added support for the `-` notation while determining how to order the short URLs list, as in `?orderBy=shortCode-DESC`. This effectively deprecates the array notation (`?orderBy[shortCode]=DESC`), that will be removed in Shlink 3.0.0