Code Monkey home page Code Monkey logo

moodle-docker's Introduction

moodle-docker: Docker Containers for Moodle Developers

moodle-docker CI

This repository contains Docker configuration aimed at Moodle developers and testers to easily deploy a testing environment for Moodle.

Features:

  • All supported database servers (PostgreSQL, MySQL, Micosoft SQL Server, Oracle XE)
  • Behat/Selenium configuration for Firefox and Chrome
  • Catch-all smtp server and web interface to messages using Mailpit
  • All PHP Extensions enabled configured for external services (e.g. solr, ldap)
  • All supported PHP versions
  • Zero-configuration approach
  • Backed by automated tests

Prerequisites

  • Docker and Docker Compose installed if your Docker CLI version does not support docker compose command.
  • It's recommended to always run the latest versions of each, but at the minimum Docker v20.10.15 and Docker Compose v2.5.0 should be used.
  • 3.25GB of RAM (if you choose Microsoft SQL Server as db server)

Quick start

# Change ./moodle to your /path/to/moodle if you already have it checked out
export MOODLE_DOCKER_WWWROOT=./moodle

# Choose a db server (Currently supported: pgsql, mariadb, mysql, mssql, oracle)
export MOODLE_DOCKER_DB=pgsql

# Get Moodle code, you could select another version branch (skip this if you already got the code)
git clone -b MOODLE_403_STABLE git://git.moodle.org/moodle.git $MOODLE_DOCKER_WWWROOT

# Ensure customized config.php for the Docker containers is in place
cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php

# Start up containers
bin/moodle-docker-compose up -d

# Wait for DB to come up (important for oracle/mssql)
bin/moodle-docker-wait-for-db

# Work with the containers (see below)
# [..]

# Shut down and destroy containers
bin/moodle-docker-compose down

Run several Moodle instances

By default, the script will load a single instance. If you want to run two or more different versions of Moodle at the same time, you have to add this environment variable prior running any of the steps at Quick start:

# Define a project name; it will appear as a prefix on container names.
export COMPOSE_PROJECT_NAME=moodle34

# Use a different public web port from those already taken
export MOODLE_DOCKER_WEB_PORT=1234

# [..] run all "Quick steps" now

Having set up several Moodle instances, you need to have set up the environment variable COMPOSE_PROJECT_NAME to just refer to the instance you expect to. See envvars to see more about docker-compose environment variables.

Use containers for running behat tests

# Initialize behat environment
bin/moodle-docker-compose exec webserver php admin/tool/behat/cli/init.php
# [..]

# Run behat tests
bin/moodle-docker-compose exec -u www-data webserver php admin/tool/behat/cli/run.php --tags=@auth_manual
Running single behat site:
Moodle 3.4dev (Build: 20171006), 33a3ec7c9378e64c6f15c688a3c68a39114aa29d
Php: 7.1.9, pgsql: 9.6.5, OS: Linux 4.9.49-moby x86_64
Server OS "Linux", Browser: "firefox"
Started at 25-05-2017, 19:04
...............

2 scenarios (2 passed)
15 steps (15 passed)
1m35.32s (41.60Mb)

Notes:

  • The behat faildump directory is exposed at http://localhost:8000/_/faildumps/.
  • Use MOODLE_DOCKER_BROWSER to switch the browser you want to run the test against. You need to recreate your containers using bin/moodle-docker-compose as described below, if you change it.

Use containers for running phpunit tests

# Initialize phpunit environment
bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php
# [..]

# Run phpunit tests

bin/moodle-docker-compose exec webserver vendor/bin/phpunit auth/manual/tests/manual_test.php
Moodle 4.0.4 (Build: 20220912), ef7a51dcb8e805a6889974b04d3154ba8bd874f2
Php: 7.3.33, pgsql: 11.15 (Debian 11.15-1.pgdg90+1), OS: Linux 5.10.0-11-amd64 x86_64
PHPUnit 9.5.13 by Sebastian Bergmann and contributors.

..                                                                  2 / 2 (100%)

Time: 00:00.304, Memory: 72.50 MB

OK (2 tests, 7 assertions)

Notes:

  • If you want to run tests with code coverage reports:
# Build component configuration
bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/util.php --buildcomponentconfigs
# Execute tests for component
bin/moodle-docker-compose exec webserver php -d pcov.enabled=1 -d pcov.directory=. vendor/bin/phpunit --configuration reportbuilder --coverage-text

Use containers for manual testing

# Initialize Moodle database for manual testing
bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="Docker moodle" --shortname="docker_moodle" --summary="Docker moodle site" --adminpass="test" --adminemail="[email protected]"

Notes:

  • Moodle is configured to listen on http://localhost:8000/.
  • Mailpit is listening on http://localhost:8000/_/mail to view emails which Moodle has sent out.
  • The admin username you need to use for logging in is admin by default. You can customize it by passing --adminuser='myusername'
  • During manual testing, if you are facing that your Moodle site is logging you off continuously, putting the correct credentials, clean all cookies for your Moodle site URL (usually localhost) from your browser. More info.

Use containers for running behat tests for the Moodle App

In order to run Behat tests for the Moodle App, you need to install the local_moodleappbehat plugin in your Moodle site. Everything else should be the same as running standard Behat tests for Moodle. Make sure to filter tests using the @app tag.

The Behat tests will be run against a container serving the mobile application, you have two options here:

  1. Use a Docker image that includes the application code. You need to specify the MOODLE_DOCKER_APP_VERSION env variable and the moodlehq/moodleapp image will be downloaded from Docker Hub. You can read about the available images in Moodle App Docker Images (for Behat, you'll want to run the ones with the -test suffix).

  2. Use a local copy of the application code and serve it through Docker, similar to how the Moodle site is being served. Set the MOODLE_DOCKER_APP_PATH env variable to the codebase in you file system. This will assume that you've already initialized the app calling npm install locally.

For both options, you also need to set MOODLE_DOCKER_BROWSER to "chrome".

# Install local_moodleappbehat plugin
git clone https://github.com/moodlehq/moodle-local_moodleappbehat "$MOODLE_DOCKER_WWWROOT/local/moodleappbehat"

# Initialize behat environment
bin/moodle-docker-compose exec webserver php admin/tool/behat/cli/init.php
# (you should see "Configured app tests for version X.X.X" here)

# Run behat tests
bin/moodle-docker-compose exec -u www-data webserver php admin/tool/behat/cli/run.php --tags="@app&&@mod_login"
Running single behat site:
Moodle 4.0dev (Build: 20200615), a2b286ce176fbe361f0889abc8f30f043cd664ae
Php: 7.2.30, pgsql: 11.8 (Debian 11.8-1.pgdg90+1), OS: Linux 5.3.0-61-generic x86_64
Server OS "Linux", Browser: "chrome"
Browser specific fixes have been applied. See http://docs.moodle.org/dev/Acceptance_testing#Browser_specific_fixes
Started at 13-07-2020, 18:34
.....................................................................

4 scenarios (4 passed)
69 steps (69 passed)
3m3.17s (55.02Mb)

If you are going with the second option, this can be used for local development of the Moodle App, given that the moodleapp container serves the app on the local 8100 port. However, this is intended to run Behat tests that require interacting with a local Moodle environment. Normal development should be easier calling npm start in the host system.

By all means, if you don't want to have npm installed locally you can go full Docker executing the following commands before starting the containers:

docker run --volume $MOODLE_DOCKER_APP_PATH:/app --workdir /app bash -c "npm install"

You can learn more about writing tests for the app in Acceptance testing for the Moodle App.

Using VNC to view behat tests

If MOODLE_DOCKER_SELENIUM_VNC_PORT is defined, selenium will expose a VNC session on the port specified so behat tests can be viewed in progress.

For example, if you set MOODLE_DOCKER_SELENIUM_VNC_PORT to 5900..

  1. Download a VNC client: https://www.realvnc.com/en/connect/download/viewer/
  2. With the containers running, enter 0.0.0.0:5900 as the port in VNC Viewer. You will be prompted for a password. The password is 'secret'.
  3. You should be able to see an empty Desktop. When you run any Javascript requiring Behat tests (e.g. those tagged @javascript) a browser will popup and you will see the tests execute.

Stop and restart containers

bin/moodle-docker-compose down which was used above after using the containers stops and destroys the containers. If you want to use your containers continuously for manual testing or development without starting them up from scratch everytime you use them, you can also just stop without destroying them. With this approach, you can restart your containers sometime later, they will keep their data and won't be destroyed completely until you run bin/moodle-docker-compose down.

# Stop containers
bin/moodle-docker-compose stop

# Restart containers
bin/moodle-docker-compose start

Environment variables

You can change the configuration of the docker images by setting various environment variables before calling bin/moodle-docker-compose up. When you change them, use bin/moodle-docker-compose down && bin/moodle-docker-compose up -d to recreate your environment.

Environment Variable Mandatory Allowed values Default value Notes
MOODLE_DOCKER_DB yes pgsql, mariadb, mysql, mssql, oracle none The database server to run against
MOODLE_DOCKER_WWWROOT yes path on your file system none The path to the Moodle codebase you intend to test
MOODLE_DOCKER_DB_VERSION no Docker tag - see relevant database page on docker-hub mysql: 8.0
pgsql: 13
mariadb: 10.7
mssql: 2017-latest
oracle: 21
The database server docker image tag
MOODLE_DOCKER_PHP_VERSION no 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6 8.1 The php version to use
MOODLE_DOCKER_BROWSER no firefox, chrome, firefox:<tag>, chrome:<tag> firefox:3 The browser to run Behat against. Supports a colon notation to specify a specific Selenium docker image version to use. e.g. firefox:2.53.1 can be used to run with older versions of Moodle (<3.5)
MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES no any value not set If set, dependencies for memcached, redis, solr, and openldap are added
MOODLE_DOCKER_BBB_MOCK no any value not set If set the BigBlueButton mock image is started and configured
MOODLE_DOCKER_MATRIX_MOCK no any value not set If set the Matrix mock image is started and configured
MOODLE_DOCKER_BEHAT_FAILDUMP no Path on your file system not set Behat faildumps are already available at http://localhost:8000/_/faildumps/ by default, this allows for mapping a specific filesystem folder to retrieve the faildumps in bulk / automated ways
MOODLE_DOCKER_DB_PORT no any integer value none If you want to bind to any host IP different from the default 127.0.0.1, you can specify it with the bind_ip:port format (0.0.0.0 means bind to all). Username is "moodle" (or "sa" for mssql) and password is "m@0dl3ing".
MOODLE_DOCKER_WEB_HOST no any valid hostname localhost The hostname for web
MOODLE_DOCKER_WEB_PORT no any integer value (or bind_ip:integer) 127.0.0.1:8000 The port number for web. If set to 0, no port is used.
If you want to bind to any host IP different from the default 127.0.0.1, you can specify it with the bind_ip:port format (0.0.0.0 means bind to all)
MOODLE_DOCKER_SELENIUM_VNC_PORT no any integer value (or bind_ip:integer) not set If set, the selenium node will expose a vnc session on the port specified. Similar to MOODLE_DOCKER_WEB_PORT, you can optionally define the host IP to bind to. If you just set the port, VNC binds to 127.0.0.1
MOODLE_DOCKER_APP_PATH no path on your file system not set If set and the chrome browser is selected, it will start an instance of the Moodle app from your local codebase
MOODLE_DOCKER_APP_VERSION no a valid app docker image version not set If set will start an instance of the Moodle app if the chrome browser is selected
MOODLE_DOCKER_TIMEOUT_FACTOR no any integer value 1 If set the timeouts in behat will be multiplied by the factor

In addition to that, MOODLE_DOCKER_RUNNING=1 env variable is defined and available in the webserver container to flag being run by moodle-docker. Developer can use this to conditionally make changes in config.php. The common case is to load test-specific configuration:

// Load moodle-docker config file if we are in moodle-docker environment
if (getenv('MOODLE_DOCKER_RUNNING')) {
    require_once(__DIR__ . '/config.docker-template.php');
}

require_once(__DIR__ . '/lib/setup.php'); // Do not edit.

Local customisations

In some situations you may wish to add local customisations, such as including additional containers, or changing existing containers.

This can be accomplished by specifying a local.yml, which will be added in and loaded with the existing yml configuration files automatically. For example:

version: "2"
services:

  # Add the adminer image at the latest tag on port 8080:8080
  adminer:
    image: adminer:latest
    restart: always
    ports:
      - 8080:8080
    depends_on:
      - "db"

  # Modify the webserver image to add another volume:
  webserver:
    volumes:
      - "/opt/data:/opt/data:cached"

Using XDebug for live debugging

The XDebug PHP Extension is not included in this setup and there are reasons not to include it by default.

However, if you want to work with XDebug, especially for live debugging, you can add XDebug to a running webserver container easily:

# Install XDebug extension with PECL
moodle-docker-compose exec webserver pecl install xdebug

# Set some wise setting for live debugging - change this as needed
read -r -d '' conf <<'EOF'
; Settings for Xdebug Docker configuration
xdebug.mode = debug
xdebug.client_host = host.docker.internal
; Some IDEs (eg PHPSTORM, VSCODE) may require configuring an IDE key, uncomment if needed
; xdebug.idekey=MY_FAV_IDE_KEY
EOF
moodle-docker-compose exec webserver bash -c "echo '$conf' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"

# Enable XDebug extension in Apache and restart the webserver container
moodle-docker-compose exec webserver docker-php-ext-enable xdebug
moodle-docker-compose restart webserver

While setting these XDebug settings depending on your local need, please take special care of the value of xdebug.client_host which is needed to connect from the container to the host. The given value host.docker.internal is a special DNS name for this purpose within Docker for Windows and Docker for Mac. If you are running on another Docker environment, you might want to try the value localhost instead or even set the hostname/IP of the host directly. Please turn off the firewall or open the port used in the xdebug.client_port.

Open the port (9003 is the default one) by using the example command for Linux Ubuntu:

sudo ufw allow 9003

After these commands, XDebug ist enabled and ready to be used in the webserver container. If you want to disable and re-enable XDebug during the lifetime of the webserver container, you can achieve this with these additional commands:

# Disable XDebug extension in Apache and restart the webserver container
moodle-docker-compose exec webserver sed -i 's/^zend_extension=/; zend_extension=/' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
moodle-docker-compose restart webserver

# Enable XDebug extension in Apache and restart the webserver container
moodle-docker-compose exec webserver sed -i 's/^; zend_extension=/zend_extension=/' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
moodle-docker-compose restart webserver

Advanced usage

As can be seen in bin/moodle-docker-compose, this repo is just a series of Docker Compose configurations and light wrapper which make use of companion docker images. Each part is designed to be reusable and you are encouraged to use the docker [compose] commands as needed.

Quick start with Gitpod

Gitpod is a free, cloud-based, development environment providing VS Code and a suitable development environment right in your browser.

When launching a workspace in Gitpod, it will automatically:

  • Clone the Moodle repo into the <workspace>/moodle folder.
  • Initialise the Moodle database.
  • Start the Moodle webserver.

Open in Gitpod

IMPORTANT: Gitpod is an alternative to local development and completely optional. We recommend setting up a local development environment if you plan to contribute regularly.

The Moodle Gitpod template supports the following environment variables:

  • MOODLE_REPOSITORY. The Moodle repository to be cloned. The value should be URL encoded. If left undefined, the default repository https://github.com/moodle/moodle.git is used.
  • MOODLE_BRANCH. The Moodle branch to be cloned. If left undefined, the default branch main is employed.
  • DATAFILE. When specified, this feature URL initializes the Moodle site with essential data. The value should be URL encoded. The content of this file adheres to the Behat generators format for creating testing scenarios.
  • INSTALLADMINER. Add this variable, set to any value, to install adminer.
  • CLONEALL. If not set, a shallow clone is created, truncating the history to reduce the clone size. Set to 1 for a full clone.

For a practical demonstration, launch a Gitpod workspace with the 'main' branch patch for MDL-79912. Simply open the following URL in your web browser (note that MOODLE_REPOSITORY should be URL encoded). The password for the admin user is test:

https://gitpod.io/#MOODLE_REPOSITORY=https%3A%2F%2Fgithub.com%2Fsarjona%2Fmoodle.git,MOODLE_BRANCH=MDL-79912-main/https://github.com/moodlehq/moodle-docker

To optimize your browsing experience, consider integrating the Tampermonkey extension into your preferred web browser for added benefits. Afterward, install the Gitpod script, which can be accessed via the following URL: Gitpod script. This script efficiently incorporates a button adjacent to each branch within the Moodle tracker, facilitating the effortless initiation of a Gitpod workspace tailored to the corresponding patch for the issue you're currently viewing.

Companion docker images

The following Moodle customised docker images are close companions of this project:

Contributions

Are extremely welcome!

moodle-docker's People

Contributors

abias avatar adrienthiery avatar andrewnicols avatar aspark21 avatar crazyserver avatar dahrens avatar danpoltawski avatar deer667 avatar fulldecent avatar jpahullo avatar junpataleta avatar kabalin avatar mattporritt avatar meirzamoodle avatar micaherne avatar mudrd8mz avatar neillm avatar nicklambellgch avatar nicoroeser avatar noeldemartin avatar paulholden avatar rlorenzo avatar sarjona avatar scara avatar skodak avatar stronk7 avatar vmdef avatar xow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moodle-docker's Issues

Can we set pathtogs in the config file?

Moodle's default pathtogs setting is /usr/bin/gs but the webserver container invoked by moodle-docker has gs at /usr/local/bin/gs. This means, for instance, that PDF annotation does not work until one updates the system paths. Is there some way that we can have the expected path on moodlehq/moodle-php-apache?

Moodle 3.2.9 on Docker

Hi,

Can someone provide me a good documentation for the installation of Moodle on docker, as the README file's documentation is not clear for someone who is new to Docker. I am trying to install only moodle version 3.2.9 with no maillog etc features.
Also I want to use external DBMS (outside container of the server itself) with reverse nginx proxy.
Because I am facing some broken css/js/php files error with local installation on the server (Centos 7).
Already posted the issue days ago but still no reply on Moodle forum.

https://moodle.org/mod/forum/discuss.php?d=374426

https://serverfault.com/questions/925791/moodle-error-during-installation

Configure the full phpunit run to use phpunit-external-services.yml and reduce skipped tests

I've got a config for various external services which a full phpunit run can use.

We should configure the full phpunit run to use this, and ideally have no phpunit skipped tests at all. Here are some of the defines needed

define('PHPUNIT_LONGTEST', true);

define('TEST_SEARCH_SOLR_HOSTNAME', 'solr');
define('TEST_SEARCH_SOLR_INDEXNAME', 'test');
define('TEST_SEARCH_SOLR_PORT', 8983);

define('TEST_SESSION_REDIS_HOST', 'redis');
define('TEST_CACHESTORE_REDIS_TESTSERVERS', 'redis');

define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://mongo:27017');

define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', "memcached0:11211\nmemcached1:11211");
define('TEST_CACHESTORE_MEMCACHE_TESTSERVERS', "memcached0:11211\nmemcached1:11211");

define('TEST_AUTH_LDAP_HOST_URL', 'ldap://ldap');
define('TEST_AUTH_LDAP_BIND_DN', 'cn=admin,dc=openstack,dc=org');
define('TEST_AUTH_LDAP_BIND_PW', 'password');
define('TEST_AUTH_LDAP_DOMAIN', 'ou=Users,dc=openstack,dc=org');

define('TEST_ENROL_LDAP_HOST_URL', 'ldap://ldap');
define('TEST_ENROL_LDAP_BIND_DN', 'cn=admin,dc=openstack,dc=org');
define('TEST_ENROL_LDAP_BIND_PW', 'password');
define('TEST_ENROL_LDAP_DOMAIN', 'ou=Users,dc=openstack,dc=org')

Add support for moosh

Based on a discussion with my colleague @Kathrin84, I was wondering if it would make sense to add official support for moosh (https://moosh-online.com / https://github.com/tmuras/moosh) by @tmuras to this project.

The main goal would be to be able to bootstrap a Moodle docker instance via CLI with some courses, test users and sample data / activities for manual testing, directly after the Moodle instance is initialized via CLI (https://github.com/moodlehq/moodle-docker/blob/master/README.md#use-containers-for-manual-testing).

I can imagine at least 4 approaches to realize this goal:

  1. Add a set of commands to https://github.com/moodlehq/moodle-docker/blob/master/README.md as instruction how to install moosh on your local system, how to wire it to a certain Moodle docker instance and how to use it on this Moodle docker instance.
  2. Add a set of commands to https://github.com/moodlehq/moodle-docker/blob/master/README.md as instruction how to install moosh on the moodle-php-apache container, how to wire it to the Moodle instance on this container and how to use it on this Moodle docker instance.
  3. Add the installation of moosh to https://github.com/moodlehq/moodle-php-apache and add instructions to https://github.com/moodlehq/moodle-docker/blob/master/README.md how to use moosh on a Moodle docker instance. I am aware that this will mess with the existing container architecture, but I just wanted to note the approach anyway.
  4. Leverage the existing docker-moosh project https://github.com/hcpss-banderson/docker-moosh by @hcpss-banderson, add it to https://github.com/moodlehq/moodle-docker and have moosh setup controlled by a new environment variable. Add instructions to https://github.com/moodlehq/moodle-docker/blob/master/README.md how to install and use moosh on a Moodle docker instance.

Any opinions?

Provide windows-variant of bin/moodle-docker-wait-for-db

I was trying to write a small batch file running

bin/moodle-docker-compose up -d
bin/moodle-docker-compose exec webserver php admin/cli/install_database.php [...]

... and it failed. Running the second command a few seconds later worked.

Here is the error message I got from the exec ... command:

Default exception handler: <p>Error: Database connection failed</p>
<p>It is possible that the database is overloaded or otherwise not running properly.</p>
<p>The site administrator should also check that the database details have been correctly specified in config.php</p> Debug: Connection refused
Error code: dbconnectionfailed
* line 543 of /lib/dml/mysqli_native_moodle_database.php: dml_connection_exception thrown
* line 344 of /lib/dmllib.php: call to mysqli_native_moodle_database->connect()
* line 615 of /lib/setup.php: call to setup_DB()
* line 90 of /config.php: call to require_once()
* line 78 of /admin/cli/install_database.php: call to require()

Add support for Global Search

Correct me if I am wrong, but I do not see Global Search support in these docker containers. Would be nice to add them in the container builds.

Add suport for .env files

docker-compose suport .env files to load environment variables.

Since the bin/moodle-docker-compose script expects two environment variables already set up, it makes impossible to let docker-compose use the content of the .env for value replacing on the configuration loaded from YML files.

Proposal:

I think it is a very easy step to check if the file exists on the / directory, and load all configuration from the .env file before guard conditions start.

Consider controlling selenium combinations per branch, or override...

Depending of the Moodle branches and browsers, there can be dependencies about which selenium/driver/browser combo to use. For example 27_STABLE may require selenium 2.47.1 and current master 2.53.1.

While having a default (surely for master normally), is nice... being able to override it can be interesting too, specially when there is some important change. Imagine tomorrow we start using, for Firefox the new Marionette driver for 3.4 and up, that requires selenium 3. Previous versions should continue using selenium...

Not sure if that's simple env variable to be used (MOODLE_DOCKER_SELENIUM_VERSION) or something to be programmatically defined (matching the Docs) or what. But right now it's not possible to play with that variable.

Ciao :-)

Firefox selenium is broken when using VNC on Mac

If you set MOODLE_DOCKER_SELENIUM_VNC_PORT (and thus we use the -debug selenium image) the selenium image dies on startup:

export MOODLE_DOCKER_DB=pgsql
export MOODLE_DOCKER_SELENIUM_VNC_PORT=5900
export MOODLE_DOCKER_WWWROOT=/Users/danp/moodles/dockertest/moodle
export SUITE=behat
./tests/setup.sh
./bin/moodle-docker-compose logs selenium
Attaching to moodledocker_selenium_1
selenium_1   | -bash: 169.254/16: No such file or directory
selenium_1   | Waiting xvfb...
selenium_1   | Waiting xvfb...
selenium_1   | Waiting xvfb...
selenium_1   | Waiting xvfb...
selenium_1   | Waiting xvfb...
selenium_1   | Waiting xvfb...
selenium_1   | Waiting xvfb...
selenium_1   | Waiting xvfb...
selenium_1   | Waiting xvfb...
selenium_1   | Waiting xvfb...

Moodle mapping to localhost not always fine

If you run the container host engine on a machine different from your local dev environment, Moodle mapping to localhost is fine for automated tests "only".

I know that you don't like too many env variables 😉 but what about using $_SERVER (e.g. SERVER_NAME or HTTP_HOST or SERVER_ADDR) or kind-of-gethostname() - via script, to get the name of the host and not the one of the container, unroutable - here being the scope of this composition mainly for dev/test purposes i.e. no need to preserve the uniqueness of URLs eventually stored in different "sessions"?
I'd be happy to contribute here according to your thoughts.

Pinging @andrewnicols too, since his proxy solution for some ancillary services has unlocked the access of those services from localhost only.

TIA,
Matteo

Unpin postgres:9.6.7

Because of a problem with PG 9.6.8 (all builds failing consistently), we have had to pin PG to 9.6.7 everywhere. That has been done @ #77 .

So this is about to understand why it's failing (it maybe a real problem in Moodle, not in PG!).

And once the problem is fixed.... proceed to the previous situations (ping just to major 9).

Rename project moodle-docker-compose?

Perhaps naming this project moodle-docker-compose would be more intuitive? Any other suggestions welcome, but docker-moodle is not really right for me.

Allow mariadb to work with 10.3.x and up

In #25 we unpinned mariadb back to 10... (right now pointing to 10.3.x)... just to discover that there are some config variables not existing anymore:

2019-01-18 22:25:48 0 [ERROR] mysqld: unknown variable 'innodb_file_format=barracuda'
2019-01-18 22:25:48 0 [ERROR] Aborting

Preventing the server to startup. So we pinned it back to 10.2.

This issue is about to try mariadb compatible with all the versions. Then we'll be really able to unpin it completely.

Ciao :-)

Moodle in Docker Having Problem to Load Images and other Files

Dear GitHub community,

I am running Moodle on Docker, with one container for moodle application and another for the moodle database (MySQL). Bother containers communicate with each other and everything is up and running, with just one exeception: the application is not finding some images (banners and logo) and other files, like .doc, .xls, .pdf, and so on. This problem is likely related to a relative path problem. I have been looking for PHP Relative Path workaround, e.g. include_path (php.ini), require_once dirname(FILE) (pluginfile.php) and related functions, with no success. Beyond that, I looked for errors log on either apache2 and php, but nothing was found. I also checked Apache2 virtualhost, but I did not have any idea about what could be going wrong. It is important to recall that such Moodle configuration is working as expected when running locally on my Ubuntu PC. This problem just happens when I run Moodle in Docker container.

Does anybody have any idea on how to deal with such kind of trouble?
moodle em docker

Enable parallel behat runs

I tried the following:

export MOODLE_DOCKER_WWWROOT=/path/to/moodle/code
export MOODLE_DOCKER_DB=pgsql
export MOODLE_DOCKER_BROWSER=chrome
cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php
bin/moodle-docker-compose up -d
bin/moodle-docker-wait-for-db
bin/moodle-docker-compose run webserver php admin/tool/behat/cli/init.php --parallel=4
bin/moodle-docker-compose run webserver php admin/tool/behat/cli/run.php

NB: I'm using this Docker VM template, which has docker-compose 1.6.2, which appears to feature run in place of exec.

I was hoping this would launch a 4-threaded behat run. The init step ran fine and installed the 4 databases, but the run step just resulted in this message:

Running single behat site:


  [Behat\Testwork\ServiceContainer\Exception\ConfigurationLoadingException]
  The requested config file does not exist


To re-run failed processes, you can use following command:
php admin/tool/behat/cli/run.php --rerun

I'm guessing there's a need to spin up extra Selenium containers and monkey around with the config.php in order to get this working. It would be lovely if there was a command to do this!

cachestore_memcached_test::test_multi_use_compatibility() is failing

This is more of an issue for https://github.com/moodlehq/moodle-php-apache but it affects the tests here..

After the move to Moodle HQ org (and new images) this is failing:

1) cachestore_memcached_test::test_multi_use_compatibility
Failed asserting that 'cachestore' is false.
/var/www/html/cache/stores/memcached/tests/memcached_test.php:324
/var/www/html/lib/phpunit/classes/advanced_testcase.php:80
To re-run:
 vendor/bin/phpunit --verbose cachestore_memcached_test cache/stores/memcached/tests/memcached_test.php

https://travis-ci.org/moodlehq/moodle-docker/jobs/272055922#L1464

This appeared to be working on previous runs:
https://travis-ci.org/moodlehq/moodle-docker/jobs/260956011#L1459

So the main change is probably that we've rebuilt against the latest upstream php image..

PHP is missing a temporary folder.

When testing file upload manually we get the error "PHP is missing a temporary folder."

Looks like we are just missing some configuration perhaps upload_tmp_dir = "/tmp/moodle"

Still investigating exactly how to fix it. Will update here if I find anything more

Don't expose web port and vnc port to the world by default

I have seen that - at least on my Docker for Mac installation - the web port (default: 8000) and the vnc port (default: 5900) of a running Moodle docker instance is exposed to the world and can be reached from outside my computer.

While I can prevent unauthorized access to these ports with a firewall on my Mac and while I can see situations where accessing the Moodle docker instance from the outside can be useful, I think exposing the ports to the world is a exception for development and testing and thus should not be the default.

Is there a possibility to disable exposing the ports from within the moodle-docker configuration and, if yes, can we create a env variable to control exposing the ports, defaulting to no?

Unable to install Moodle on Oracle via CLI - only via web

With MOODLE_DOCKER_DB=oracle I get:

mudrd8mz@glux ~/git/moodle-docker $ bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="Docker moodle" --shortname="docker_moodle" --adminpass="test" --adminemail="[email protected]"
Default exception handler: Exception - Call to a member function is_temptable() on null Debug:
Error code: generalexceptionmessage
* line 229 of /lib/ddl/sql_generator.php: Error thrown
* line 100 of /lib/ddl/database_manager.php: call to sql_generator->table_exists()
* line 466 of /question/engine/upgrade/upgradelib.php: call to database_manager->table_exists()
* line 729 of /lib/environmentlib.php: call to quiz_attempts_upgraded()
* line 475 of /lib/environmentlib.php: call to environment_custom_checks()
* line 106 of /lib/environmentlib.php: call to environment_check()
* line 161 of /admin/cli/install_database.php: call to check_moodle_environment()

!!! Exception - Call to a member function is_temptable() on null !!!
!!
Error code: generalexceptionmessage !!
!! Stack trace: * line 229 of /lib/ddl/sql_generator.php: Error thrown
* line 100 of /lib/ddl/database_manager.php: call to sql_generator-&gt;table_exists()
* line 466 of /question/engine/upgrade/upgradelib.php: call to database_manager-&gt;table_exists()
* line 729 of /lib/environmentlib.php: call to quiz_attempts_upgraded()
* line 475 of /lib/environmentlib.php: call to environment_custom_checks()
* line 106 of /lib/environmentlib.php: call to environment_check()
* line 161 of /admin/cli/install_database.php: call to check_moodle_environment()
 !!

However, I can still install it by going to http://localhost:8000

Not sure if this is the moodle-docker bug or the moodle core bug?

Automated testing for moodle-docker-compose.cmd

I did some experiments using appveyor to test this project on windows - but appveyor sadly doesn't support the docker environment.

But moodle-docker-compose.cmd still gives me the spooks because I (and i'm sure many contributors) aren't working on windows with batch scripts much.

I suggest that we create some test for the script - perhaps with a fake docker-compose fixture which echos flags and we can test the output to make sure it's doing what we expect.

Add better support for multiple concurrent container setups

With this project, you can currently build and spin up one container setup aka. Moodle instance which will get its configuration from the MOODLE_DOCKER_* environment variables and will be named after the name of the directory where this repository was cloned into.

So, if you cloned this repository into ~/moodle-docker and run bin/moodle-docker-compose up -d, you will have four containers named

  • moodle_webserver_1
  • moodle_db_1
  • moodle_selenium_1
  • moodle_mailhog_1

If you run bin/moodle-docker-compose up -d a second time, docker-compose only checks if the service configuration or images were changed after the containers' creation (see https://docs.docker.com/compose/reference/up/) and does recreate a container if needed. But it does not spin up another container setup aka. Moodle instance like you might expect.

If you want now to run multiple container setups concurrently, for example if you want to test the same Moodle codebase on two different DBMS concurrently or if you want to test two plugin versions concurrently, this isn't officially supported by this project and you are on your own.

Luckily, you can define the container prefix for docker-compose. To test the same Moodle codebase on two different DBMS, you can run these commands in two different terminals:

Terminal 1:

# Set up environment for this project
export COMPOSE_PROJECT_NAME=moodle-pgsql
export MOODLE_DOCKER_WWWROOT=~/moodle
export MOODLE_DOCKER_DB=pgsql
export MOODLE_DOCKER_WEB_PORT=8000

# Start up containers
bin/moodle-docker-compose up -d

Terminal 2:

# Set up environment for this project
export COMPOSE_PROJECT_NAME=moodle-mysql
export MOODLE_DOCKER_WWWROOT=~/moodle
export MOODLE_DOCKER_DB=mysql
export MOODLE_DOCKER_WEB_PORT=8001

# Start up containers
bin/moodle-docker-compose up -d

This will spin up two Moodle instances on Port 8000 and 8001 concurrently. Unfortunately, this approach isn't really bullet-proof. You will have to set the correct environment variables everytime you run a bin/moodle-docker-compose command to target the correct Moodle instance. And you will have to have one terminal open per Moodle instance to prevent conflicts of the environment variables.

So: How about adding official support for multiple concurrent container setups?
If you say "YES!", we should think about useful implementation approachs. There may be simple approachs and there might be more sophisticated approachs like @Dagefoerde already built in his https://github.com/Dagefoerde/Moodledocker project.

Thanks,
Alex

Persistance, for 'manual' testing

For doing manual testing, we don't want our docker environments to be completely torn down and recreated each time.

Need to investigate this:

  1. I think docker-compose does some sort of volume persistance itself, especially if you use stop rather than down. But I have not looked into this at all
  2. We might want explict mounted data directories

So far i've been focused initially on quick manual tests and automated testing and haven't examined this case at all, but manual testing is very much part of the usecase for this project.

CAS server

We should add a CAS server which does the basic user/password static verififcations.

I have tried to use apereo/cas:v5.0.6 but got lost with the lack of documentation and then ended up using sergiofbsilva/cas-dev because it was plug and play enough to go (I had to add a docker.local hostname)

Reconsider branching strategy for versions

I am not sure if using branches of this project is the best way to manage php versions, it might be better to control it with an environment variable a bit like i have done with the browser. Needs some consideration.

PHP: upload_max_filesize set to 2MB

The PHP container seems to default to 2MB in its php.ini config for upload_max_filesize.

Can the upload_max_filesize and post_max_size configs be set to higher values, like 2GB?

Make integration with ngrok easier

Attempting to access the docker instances via ngrok URL requires some extra setup that may not be obvious to new comers.

In the config.docker-template.php file:

  • $CFG->wwwroot is hard-coded to use http only
  • The MOODLE_DOCKER_WEB_PORT is always added to it

In my case (which I think may be considered typical), I wanted to run the docker instance on http://localhost:8000 and access that via a public URL like http(s)://63f7d74b.ngrok.io

Problems I was facing (initial impression without looking deeply into the code):

  • Shall I set MOODLE_DOCKER_WEB_HOST to 63f7d74b.ngrok.io or leave it localhost?
  • Shall I set MOODLE_DOCKER_WEB_PORT to 8000 or 80 or what?
  • How do I switch to HTTPS?

Some suggestions quickly coming to my mind:

  • Introduce a new optional environment like MOODLE_DOCKER_WEB_RPROXY (better name welcome) where I could define strings like 63f7d74b.ngrok.io or https://63f7d74b.ngrok.io (defaults to http or https?)
  • If that is set, it would be used as $CFG->wwwroot
  • If that starts with https:// then $CFG->sslproxy would be set, too.

Happy to discuss alternatives, thanks.

Behat @auth_manual is failing on selenium/standalone-chrome:3.5.3

This is almost certainly due to an new chrome release - probably needs reporting to MDL

Moodle 3.3 (Build: 20170515), b87a580aa3eb23d5f05d7f619fc40a89e0f86fe5
Php: 7.1.9, pgsql: 9.6.5, OS: Linux 4.4.0-93-generic x86_64
Server OS "Linux", Browser: "chrome"
Browser specific fixes have been applied. See http://docs.moodle.org/dev/Acceptance_testing#Browser_specific_fixes
Started at 14-09-2017, 18:11
...F----.......
--- Failed steps:
001 Scenario: Check login works with javascript.                       # /var/www/html/auth/manual/tests/behat/auth_manual.feature:13
      And I click on "Log in" "link" in the ".logininfo" "css_element" # /var/www/html/auth/manual/tests/behat/auth_manual.feature:16
        unknown error: Element is not clickable at point (212, 849)
          (Session info: chrome=61.0.3163.79)
          (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Linux 4.4.0-93-generic x86_64) (WebDriver\Exception\UnknownError)
2 scenarios (1 passed, 1 failed)
15 steps (10 passed, 1 failed, 4 skipped)
0m29.28s (42.17Mb)
To re-run failed processes, you can use following command:
php admin/tool/behat/cli/run.php --tags="@auth_manual" --rerun

https://travis-ci.org/moodlehq/moodle-docker/jobs/275401533

Moodle refuses to setup on the Oracle image

When using the Oracle image and I try to initialise either behat or phpunit

I get the following error:

'The site administrator should verify server configuration

Oracle PL/SQL Moodle support package MOODLELIB is not installed! Database administrator has to execute /lib/dml/oci_native_moodle_package.sql script.'

The database logs from the docker instance:

db_1 | Starting Oracle Net Listener.
db_1 | Starting Oracle Database 11g Express Edition instance.
db_1 | ERROR:
db_1 | ORA-28002: the password will expire within 7 days
db_1 | System altered.
db_1 | /usr/sbin/startup.sh: running /docker-entrypoint-initdb.d/01-moodle-package.sql
db_1 | SQL*Plus: Release 11.2.0.2.0 Production on Thu Aug 17 10:43:56 2017
db_1 | Copyright (c) 1982, 2011, Oracle. All rights reserved.
db_1 | ERROR:
db_1 | ORA-28002: the password will expire within 7 days
db_1 | Connected to:
db_1 | Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
db_1 | Connected.
db_1 | Package created.
db_1 | Package body created.
db_1 | No errors.
db_1 | Package body created.
db_1 | SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
db_1 | /usr/sbin/startup.sh: running /docker-entrypoint-initdb.d/02-moodle-user.sql
db_1 | SQL*Plus: Release 11.2.0.2.0 Production on Thu Aug 17 10:43:57 2017
db_1 | Copyright (c) 1982, 2011, Oracle. All rights reserved.
db_1 | ERROR:
db_1 | ORA-28002: the password will expire within 7 days
db_1 | Connected to:
db_1 | Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
db_1 | Connected.
db_1 | Profile altered.
db_1 | User created.
db_1 | Grant succeeded.
db_1 | Grant succeeded.
db_1 | Grant succeeded.
db_1 | Grant succeeded.
db_1 | Grant succeeded.
db_1 | System altered.
db_1 | Database altered.
db_1 | Database closed.
db_1 | Database dismounted.
db_1 | ORACLE instance shut down.
db_1 | ORACLE instance started.
db_1 | Total System Global Area 601272320 bytes
db_1 | Fixed Size 2228848 bytes
db_1 | Variable Size 180358544 bytes
db_1 | Database Buffers 415236096 bytes
db_1 | Redo Buffers 3448832 bytes
db_1 | Database mounted.
db_1 | Database opened.
db_1 | SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

I an running it on Windows 7 via the Docker Toolbox

Docker version 17.06.0-ce, build 02c1d87

Folder Duplication in URL path (/moodle/moodle/...)

Dear community,

We are running Moodle at micro-service architecture (Docker), in such a way that we have application in one container and database in another. They communicate with each other, and we can navigate normally through the application, without any kind of trouble. However, when we try to modify Moodle resources, like creating a course, new user, editing its content and so on, it is duplicating the folder "/moodle/" in the URL path, which is causing 404 Error (Not Found).

For instance, if we try to create a new user, the application tries to find "/moodle/moodle/login/signup.php". See that it is duplicating folder moodle in this path. How can I workaround this problem?

Make it possible to test @_file_upload

An email from Alain Corbière:

Thank you for this version of docker for Moodle.

On the basis of this interesting work, I suggest a very small patch to give the possibility to test the features with the tag @_file_upload.

By example, the file empty.txt (/var/www/html/lib/tests/fixtures/) is now accessible from the selenium container.
Alain

diff -ENwbur ./original/docker-moodle/base.yml ./new/docker-moodle/base.yml
--- ./original/docker-moodle/base.yml	2017-07-11 19:47:42.485105900 +0200
+++ ./new/docker-moodle/base.yml	2017-07-11 19:49:26.706340300 +0200
@@ -22,3 +22,5 @@
       POSTGRES_DB: moodle
   selenium:
     image: selenium/standalone-firefox:2.53.1
+    volumes:
+      - "${MOODLE_DOCKER_WWWROOT}:/var/www/html"
diff -ENwbur ./original/docker-moodle/config.docker-template.php ./new/docker-moodle/config.docker-template.php
--- ./original/docker-moodle/config.docker-template.php	2017-07-11 19:47:42.492106800 +0200
+++ ./new/docker-moodle/config.docker-template.php	2017-07-11 19:49:13.306638700 +0200
@@ -28,7 +28,6 @@
     'default' => array(
         'browser' => getenv('MOODLE_DOCKER_BROWSER'),
         'wd_host' => 'http://selenium:4444/wd/hub',
-        'tags' => '~@_file_upload',
     ),
 );

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.