Skip to content

Commit

Permalink
Merge pull request #850 from acelaya-forks/feature/env-docker-port
Browse files Browse the repository at this point in the history
Feature/env docker port
  • Loading branch information
acelaya committed Oct 3, 2020
2 parents b15e904 + c6c78f3 commit d426dbc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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 `<field>-<dir>` 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
Expand Down
6 changes: 3 additions & 3 deletions 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"
Expand Down Expand Up @@ -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 && \
Expand All @@ -59,7 +59,7 @@ LABEL maintainer="Alejandro Celaya <alejandro@alejandrocelaya.com>"
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
Expand Down
7 changes: 5 additions & 2 deletions docker/README.md
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
}
```

Expand Down
1 change: 1 addition & 0 deletions docker/config/shlink_in_docker.local.php
Expand Up @@ -159,6 +159,7 @@ public function getMercureConfig(): array

'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),
Expand Down
1 change: 1 addition & 0 deletions module/Core/src/Config/SimplifiedConfigParser.php
Expand Up @@ -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' => [
Expand Down
2 changes: 2 additions & 0 deletions module/Core/test/Config/SimplifiedConfigParserTest.php
Expand Up @@ -67,6 +67,7 @@ public function properlyMapsSimplifiedConfig(): void
'anonymize_remote_addr' => false,
'redirect_status_code' => 301,
'redirect_cache_lifetime' => 90,
'port' => 8888,
];
$expected = [
'app_options' => [
Expand Down Expand Up @@ -132,6 +133,7 @@ public function properlyMapsSimplifiedConfig(): void

'mezzio-swoole' => [
'swoole-http-server' => [
'port' => 8888,
'options' => [
'task_worker_num' => 50,
],
Expand Down

0 comments on commit d426dbc

Please sign in to comment.