From cb53ea9d2b38cfdeb5aa9aa601f2c1d75c7040b3 Mon Sep 17 00:00:00 2001 From: Mathias Kahl Date: Mon, 7 Oct 2024 13:50:59 +0200 Subject: [PATCH] PM-45594 allow running arbitrary Moodle versions in docker setup This now allows running main as well as stable branches. But it's not quite finished yet: Mounting the plugin folder is still missing. --- development/docker-compose.yml | 34 +++++++++++++++++---------- development/moodleimage/Dockerfile | 18 ++++++++++++++ development/moodleimage/entrypoint.sh | 9 +++++++ 3 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 development/moodleimage/Dockerfile create mode 100755 development/moodleimage/entrypoint.sh diff --git a/development/docker-compose.yml b/development/docker-compose.yml index 2eaff94..cfd3f56 100644 --- a/development/docker-compose.yml +++ b/development/docker-compose.yml @@ -1,34 +1,44 @@ -# https://hub.docker.com/r/bitnami/moodle -version: '2' +name: moodle-dev services: mariadb: - image: docker.io/bitnami/mariadb:10.6 + image: docker.io/bitnami/mariadb:10.7 ports: - '8833:3306' - '8443:443' environment: # ALLOW_EMPTY_PASSWORD is recommended only for development. - ALLOW_EMPTY_PASSWORD=yes - - MARIADB_USER=bn_moodle - - MARIADB_DATABASE=bitnami_moodle + - MARIADB_USER=moodle + - MARIADB_DATABASE=moodle - MARIADB_CHARACTER_SET=utf8mb4 - MARIADB_COLLATE=utf8mb4_unicode_ci + # liveness probe + healthcheck: + test: ["CMD", "mysqladmin", "status", "-uroot"] + interval: 2s + timeout: 1s + retries: 10 moodle: - image: docker.io/bitnami/moodle:4.4 + build: + dockerfile: Dockerfile + context: moodleimage + args: + # main (latest), MOODLE_405_STABLE etc, see https://github.com/moodle/moodle/branches + MOODLE_BRANCH: ${MOODLE_BRANCH:-main} + # 7.4, 8.0, 8.1, 8.3 etc., see https://moodledev.io/general/development/policies/php + PHP_VERSION: ${PHP_VERSION:-8.1} ports: - - '8080:8080' + - '8080:80' environment: - MOODLE_DATABASE_HOST=mariadb - MOODLE_DATABASE_PORT_NUMBER=3306 - - MOODLE_DATABASE_USER=bn_moodle - - MOODLE_DATABASE_NAME=bitnami_moodle - ALLOW_EMPTY_PASSWORD=yes - MOODLE_PASSWORD=kialo1234 # you can override the following by creating a .env file in the same directory as this file - TARGET_KIALO_URL=${TARGET_KIALO_URL:-http://localhost:5000} - - MOODLE_HOST=${MOODLE_HOST:-localhost:8080} - volumes: - - './moodle:/bitnami/moodle' + - MOODLE_HOST=http://${MOODLE_HOST:-localhost:8080} +# volumes: +# - './moodle:/var/www/html' depends_on: - mariadb moodleapp: diff --git a/development/moodleimage/Dockerfile b/development/moodleimage/Dockerfile new file mode 100644 index 0000000..8c75e89 --- /dev/null +++ b/development/moodleimage/Dockerfile @@ -0,0 +1,18 @@ +# See https://moodledev.io/general/development/policies/php for the list of available PHP versions. +# Different versions of Moodle require different versions of PHP. +ARG PHP_VERSION="8.1" + +FROM moodlehq/moodle-php-apache:${PHP_VERSION} + +# See https://moodledev.io/general/releases for the list of available versions. +# See https://github.com/moodle/moodle/branches for the available branches. +# Branch names follow the pattern MOODLE_XYZ_STABLE, e.g. MOODLE_404_STABLE for Moodle 4.4. +# main is the default and most up-to-date branch, it includes upcoming versions before they are stable. +ARG MOODLE_BRANCH="main" +ENV MOODLE_BRANCH=${MOODLE_BRANCH} + +RUN git clone git://git.moodle.org/moodle.git /var/www/html --depth=1 --branch ${MOODLE_BRANCH} + +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] +CMD ["apache2-foreground"] diff --git a/development/moodleimage/entrypoint.sh b/development/moodleimage/entrypoint.sh new file mode 100755 index 0000000..91cc35e --- /dev/null +++ b/development/moodleimage/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# see https://docs.moodle.org/404/en/Installing_Moodle#Command_line_installer +chown -R www-data /var/www/html + +# TODO: Make moodle default user "user" and not "admin" +su - www-data -s /bin/bash -c "php /var/www/html/admin/cli/install.php --non-interactive --agree-license --allow-unstable --wwwroot=$MOODLE_HOST --dataroot=/var/www/moodledata --dbtype=mariadb --dbhost=$MOODLE_DATABASE_HOST --dbname=moodle --dbuser=moodle --dbport=$MOODLE_DATABASE_PORT_NUMBER --fullname=Moodle --shortname=moodle --adminuser=user --adminpass=$MOODLE_PASSWORD --adminemail=sre@kialo.com --supportemail=sre@kialo.com" + +exec /usr/local/bin/moodle-docker-php-entrypoint "$@"