Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow integration in traefik #104

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ 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 |
| `MOODLE_DOCKER_TRAEFIK_HTTPS` | no | any value | not set | If set, use an https url in traefik |

## Advanced usage

Expand Down
8 changes: 7 additions & 1 deletion bin/moodle-docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion config.docker-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
}
$CFG->wwwroot = "http://{$host}";
$port = getenv('MOODLE_DOCKER_WEB_PORT');
if (!empty($port)) {
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';
Expand Down
27 changes: 27 additions & 0 deletions traefik.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "2"
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}"
- 'traefik.docker.network=traefik_default'
networks:
- default
- traefik
exttests:
networks:
- default
- traefik
selenium:
networks:
- default
- traefik

networks:
default:
traefik:
external:
name: traefik_default