From 1210f8e20542cc886d4893e16639e7b070943d29 Mon Sep 17 00:00:00 2001 From: Didier 'OdyX' Raboud Date: Wed, 26 Jun 2019 14:33:36 +0200 Subject: [PATCH 1/2] Allow integrating docker containers in traefik --- README.md | 1 + bin/moodle-docker-compose | 8 +++++++- config.docker-template.php | 2 +- traefik.yml | 26 ++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 traefik.yml diff --git a/README.md b/README.md index c4bbaae1493..989ffe1e5aa 100755 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ You can change the configuration of the docker images by setting various environ | `MOODLE_DOCKER_WEB_HOST` | no | any valid hostname | localhost | The hostname for web | | `MOODLE_DOCKER_WEB_PORT` | no | any integer value | 8000 | The port number for web. If set to 0, no port is used | | `MOODLE_DOCKER_SELENIUM_VNC_PORT` | no | any integer value | not set | If set, the selenium node will expose a vnc session on the port specified | +| `MOODLE_DOCKER_TRAEFIK` | no | any value | not set | If set, integrate the docker containers in traefik | ## Advanced usage diff --git a/bin/moodle-docker-compose b/bin/moodle-docker-compose index b354fc2ef83..9dde0e8dcb7 100755 --- a/bin/moodle-docker-compose +++ b/bin/moodle-docker-compose @@ -31,6 +31,12 @@ dockercompose="${dockercompose} -f ${basedir}/service.mail.yml" # PHP Version. export MOODLE_DOCKER_PHP_VERSION=${MOODLE_DOCKER_PHP_VERSION:-7.1} +# Enable Traefik +if [ -n "$MOODLE_DOCKER_TRAEFIK" ]; +then + dockercompose="${dockercompose} -f ${basedir}/traefik.yml" +fi + # Database flavour if [ "$MOODLE_DOCKER_DB" != 'pgsql' ]; then @@ -69,7 +75,7 @@ export MOODLE_DOCKER_WEB_HOST=${MOODLE_DOCKER_WEB_HOST:-localhost} # Webserver port export MOODLE_DOCKER_WEB_PORT=${MOODLE_DOCKER_WEB_PORT:-8000} -if [[ $MOODLE_DOCKER_WEB_PORT -gt 0 ]] +if [[ $MOODLE_DOCKER_WEB_PORT -gt 0 ]] && [ -z "$MOODLE_DOCKER_TRAEFIK" ] then dockercompose="${dockercompose} -f ${basedir}/webserver.port.yml" fi diff --git a/config.docker-template.php b/config.docker-template.php index 4d54a487252..8f975cb1b8b 100755 --- a/config.docker-template.php +++ b/config.docker-template.php @@ -19,7 +19,7 @@ } $CFG->wwwroot = "http://{$host}"; $port = getenv('MOODLE_DOCKER_WEB_PORT'); -if (!empty($port)) { +if (!empty($port) && empty(getenv('MOODLE_DOCKER_TRAEFIK'))) { $CFG->wwwroot .= ":{$port}"; } $CFG->dataroot = '/var/www/moodledata'; diff --git a/traefik.yml b/traefik.yml new file mode 100644 index 00000000000..d151720d261 --- /dev/null +++ b/traefik.yml @@ -0,0 +1,26 @@ +version: "2" +services: + webserver: + environment: + MOODLE_DOCKER_TRAEFIK: "${MOODLE_DOCKER_TRAEFIK}" + labels: + - "traefik.enable=true" + - "traefik.frontend.rule=Host:${MOODLE_DOCKER_WEB_HOST}" + - 'traefik.docker.network=traefik_default' + networks: + - default + - traefik + exttests: + networks: + - default + - traefik + selenium: + networks: + - default + - traefik + +networks: + default: + traefik: + external: + name: traefik_default From db1c0178d3648926481aa82da7e3666bdad4c9d8 Mon Sep 17 00:00:00 2001 From: Didier 'OdyX' Raboud Date: Wed, 26 Jun 2019 15:08:12 +0200 Subject: [PATCH 2/2] Allow HTTPS for traefik --- README.md | 1 + config.docker-template.php | 7 ++++++- traefik.yml | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 989ffe1e5aa..b4f7374b9ef 100755 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ You can change the configuration of the docker images by setting various environ | `MOODLE_DOCKER_WEB_PORT` | no | any integer value | 8000 | The port number for web. If set to 0, no port is used | | `MOODLE_DOCKER_SELENIUM_VNC_PORT` | no | any integer value | not set | If set, the selenium node will expose a vnc session on the port specified | | `MOODLE_DOCKER_TRAEFIK` | no | any value | not set | If set, integrate the docker containers in traefik | +| `MOODLE_DOCKER_TRAEFIK_HTTPS` | no | any value | not set | If set, use an https url in traefik | ## Advanced usage diff --git a/config.docker-template.php b/config.docker-template.php index 8f975cb1b8b..ba9bf455d83 100755 --- a/config.docker-template.php +++ b/config.docker-template.php @@ -19,7 +19,12 @@ } $CFG->wwwroot = "http://{$host}"; $port = getenv('MOODLE_DOCKER_WEB_PORT'); -if (!empty($port) && empty(getenv('MOODLE_DOCKER_TRAEFIK'))) { +if (!empty(getenv('MOODLE_DOCKER_TRAEFIK'))) { + if (!empty(getenv('MOODLE_DOCKER_TRAEFIK_HTTPS'))) { + $CFG->sslproxy = true; + $CFG->wwwroot = "https://{$host}"; + } +} else if (!empty($port)) { $CFG->wwwroot .= ":{$port}"; } $CFG->dataroot = '/var/www/moodledata'; diff --git a/traefik.yml b/traefik.yml index d151720d261..da7ec4926c7 100644 --- a/traefik.yml +++ b/traefik.yml @@ -3,6 +3,7 @@ services: webserver: environment: MOODLE_DOCKER_TRAEFIK: "${MOODLE_DOCKER_TRAEFIK}" + MOODLE_DOCKER_TRAEFIK_HTTPS: "${MOODLE_DOCKER_TRAEFIK_HTTPS}" labels: - "traefik.enable=true" - "traefik.frontend.rule=Host:${MOODLE_DOCKER_WEB_HOST}"