├── .gitattributes
├── db.mssql.5.6.yml
├── assets
└── web
│ ├── apache2_faildumps.conf
│ └── apache2_mailhog.conf
├── moodle-app.yml
├── db.oracle.yml
├── webserver.port.yml
├── volumes-cached.yml
├── selenium.debug.yml
├── service.mail.yml
├── selenium.chrome.yml
├── db.mssql.yml
├── moodle-app-dev.yml
├── phpunit-external-services.yml
├── bin
├── moodle-docker-wait-for-app
├── moodle-docker-wait-for-db
├── moodle-docker-compose.cmd
└── moodle-docker-compose
├── db.mariadb.yml
├── db.mysql.yml
├── tests
├── test.sh
└── setup.sh
├── base.yml
├── config.docker-template.php
├── .travis.yml
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | bin/moodle-docker-compose.cmd eol=crlf
2 |
--------------------------------------------------------------------------------
/db.mssql.5.6.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | environment:
5 | MOODLE_DOCKER_DBTYPE: mssql
6 |
--------------------------------------------------------------------------------
/assets/web/apache2_faildumps.conf:
--------------------------------------------------------------------------------
1 |
2 | Options +Indexes
3 |
4 |
5 | Alias /_/faildumps /var/www/behatfaildumps
6 |
7 |
--------------------------------------------------------------------------------
/moodle-app.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | environment:
5 | MOODLE_DOCKER_APP: "true"
6 | moodleapp:
7 | image: "moodlehq/moodleapp:${MOODLE_DOCKER_APP_VERSION}"
8 |
--------------------------------------------------------------------------------
/db.oracle.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | environment:
5 | MOODLE_DOCKER_DBTYPE: oci
6 | MOODLE_DOCKER_DBNAME: XE
7 | db:
8 | image: moodlehq/moodle-db-oracle-r2
9 |
--------------------------------------------------------------------------------
/webserver.port.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | environment:
5 | MOODLE_DOCKER_WEB_PORT: "${MOODLE_DOCKER_WEB_PORT}"
6 | ports:
7 | - "${MOODLE_DOCKER_WEB_PORT}:80"
8 |
--------------------------------------------------------------------------------
/volumes-cached.yml:
--------------------------------------------------------------------------------
1 | # Here we support https://docs.docker.com/docker-for-mac/osxfs-caching/
2 | # for improved performance on mac
3 | version: "2"
4 | services:
5 | webserver:
6 | volumes:
7 | - "${MOODLE_DOCKER_WWWROOT}:/var/www/html:cached"
8 |
--------------------------------------------------------------------------------
/selenium.debug.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | selenium:
4 | ports:
5 | - "${MOODLE_DOCKER_SELENIUM_VNC_PORT}:5900"
6 | environment:
7 | # Workaround for https://github.com/SeleniumHQ/docker-selenium/issues/227
8 | "no_proxy": localhost
9 |
--------------------------------------------------------------------------------
/service.mail.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | volumes:
5 | - "${ASSETDIR}/web/apache2_mailhog.conf:/etc/apache2/conf-enabled/apache2_mailhog.conf"
6 | depends_on:
7 | - mailhog
8 | mailhog:
9 | image: mailhog/mailhog
10 |
--------------------------------------------------------------------------------
/selenium.chrome.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | environment:
5 | MOODLE_DOCKER_BROWSER: chrome
6 | selenium:
7 | image: "selenium/standalone-chrome${MOODLE_DOCKER_SELENIUM_SUFFIX}:3"
8 | volumes:
9 | - /dev/shm:/dev/shm
10 |
--------------------------------------------------------------------------------
/db.mssql.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | environment:
5 | MOODLE_DOCKER_DBTYPE: sqlsrv
6 | MOODLE_DOCKER_DBUSER: sa
7 | db:
8 | image: moodlehq/moodle-db-mssql
9 | environment:
10 | ACCEPT_EULA: "y"
11 | SA_PASSWORD: "m@0dl3ing"
12 |
--------------------------------------------------------------------------------
/moodle-app-dev.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | environment:
5 | MOODLE_DOCKER_APP: "true"
6 | moodleapp:
7 | image: node:11
8 | working_dir: /app
9 | command: npm run ionic:serve
10 | volumes:
11 | - "${MOODLE_DOCKER_APP_PATH}:/app"
12 | expose:
13 | - 8100
14 | - 35729
15 | - 53703
16 | ports:
17 | - "8100:8100"
18 | - "35729:35729"
19 | - "53703:53703"
20 |
--------------------------------------------------------------------------------
/phpunit-external-services.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | environment:
5 | MOODLE_DOCKER_PHPUNIT_EXTRAS: "true"
6 | memcached0:
7 | image: memcached:1.4
8 | memcached1:
9 | image: memcached:1.4
10 | mongo:
11 | image: mongo:4.0
12 | redis:
13 | image: redis:3
14 | solr:
15 | image: solr:6.5
16 | entrypoint:
17 | - docker-entrypoint.sh
18 | - solr-precreate
19 | - test
20 | ldap:
21 | image: larrycai/openldap
22 |
--------------------------------------------------------------------------------
/bin/moodle-docker-wait-for-app:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
5 |
6 | if [[ ! -z "$MOODLE_DOCKER_BROWSER" ]] && [[ "$MOODLE_DOCKER_BROWSER" == "chrome" ]] && ([[ ! -z "$MOODLE_DOCKER_APP_PATH" ]] || [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]] || [[ ! -z "$MOODLE_APP_VERSION" ]]);
7 | then
8 | until $basedir/bin/moodle-docker-compose logs moodleapp | grep -q 'dev server running: ';
9 | do
10 | echo 'Waiting for Moodle app to come up...'
11 | sleep 15
12 | done
13 | fi
14 |
--------------------------------------------------------------------------------
/db.mariadb.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | environment:
5 | MOODLE_DOCKER_DBTYPE: mariadb
6 | MOODLE_DOCKER_DBCOLLATION: utf8mb4_bin
7 | db:
8 | image: mariadb:10
9 | command: >
10 | --character-set-server=utf8mb4
11 | --collation-server=utf8mb4_bin
12 | --innodb_file_per_table=On
13 | --wait-timeout=28800
14 | environment:
15 | MYSQL_ROOT_PASSWORD: "m@0dl3ing"
16 | MYSQL_USER: moodle
17 | MYSQL_PASSWORD: "m@0dl3ing"
18 | MYSQL_DATABASE: moodle
19 |
--------------------------------------------------------------------------------
/db.mysql.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | environment:
5 | MOODLE_DOCKER_DBTYPE: mysqli
6 | MOODLE_DOCKER_DBCOLLATION: utf8mb4_bin
7 | db:
8 | image: mysql:5
9 | command: >
10 | --character-set-server=utf8mb4
11 | --collation-server=utf8mb4_bin
12 | --innodb_file_format=barracuda
13 | --innodb_file_per_table=On
14 | --innodb_large_prefix=On
15 | environment:
16 | MYSQL_ROOT_PASSWORD: "m@0dl3ing"
17 | MYSQL_USER: moodle
18 | MYSQL_PASSWORD: "m@0dl3ing"
19 | MYSQL_DATABASE: moodle
20 |
--------------------------------------------------------------------------------
/bin/moodle-docker-wait-for-db:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
5 |
6 | if [ -z "$MOODLE_DOCKER_DB" ];
7 | then
8 | echo 'Error: $MOODLE_DOCKER_DB is not set'
9 | exit 1
10 | fi
11 |
12 | if [ "$MOODLE_DOCKER_DB" = "mssql" ];
13 | then
14 | $basedir/bin/moodle-docker-compose exec -T db /wait-for-mssql-to-come-up.sh
15 | elif [ "$MOODLE_DOCKER_DB" = "oracle" ];
16 | then
17 | until $basedir/bin/moodle-docker-compose logs db | grep -q 'Database opened.';
18 | do
19 | echo 'Waiting for oracle to come up...'
20 | sleep 15
21 | done
22 | else
23 | sleep 5
24 | fi
25 |
--------------------------------------------------------------------------------
/assets/web/apache2_mailhog.conf:
--------------------------------------------------------------------------------
1 |
2 | LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
3 |
4 |
5 |
6 | LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
7 |
8 |
9 |
10 | LoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so
11 |
12 |
13 | Redirect "/_/mail" "/_/mail/"
14 |
15 | ProxyPass "/_/mail/api/v2/websocket" "ws://mailhog:8025/api/v2/websocket"
16 | ProxyPassReverse "/_/mail/api/v2/websocket" "ws://mailhog:8025/api/v2/websocket"
17 |
18 | ProxyPass "/_/mail/" "http://mailhog:8025/"
19 | ProxyPassReverse "/_/mail/" "http://mailhog:8025/"
20 |
--------------------------------------------------------------------------------
/tests/test.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
5 |
6 | if [ "$SUITE" = "phpunit" ];
7 | then
8 | testcmd="bin/moodle-docker-compose exec -T webserver vendor/bin/phpunit core_dml_testcase lib/dml/tests/dml_test.php"
9 | elif [ "$SUITE" = "behat" ];
10 | then
11 | testcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/run.php --tags=@auth_manual"
12 | elif [ "$SUITE" = "phpunit-full" ];
13 | then
14 | testcmd="bin/moodle-docker-compose exec -T webserver vendor/bin/phpunit --verbose"
15 | elif [ "$SUITE" = "behat-app" ] || [ "$SUITE" = "behat-app-development" ];
16 | then
17 | testcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/run.php --tags=@app&&@mod_login"
18 | else
19 | echo "Error, unknown suite '$SUITE'"
20 | exit 1
21 | fi
22 |
23 | echo "Running: $testcmd"
24 | $basedir/$testcmd
25 |
--------------------------------------------------------------------------------
/base.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | webserver:
4 | image: "moodlehq/moodle-php-apache:${MOODLE_DOCKER_PHP_VERSION}"
5 | depends_on:
6 | - db
7 | volumes:
8 | - "${MOODLE_DOCKER_WWWROOT}:/var/www/html"
9 | - "${ASSETDIR}/web/apache2_faildumps.conf:/etc/apache2/conf-enabled/apache2_faildumps.conf"
10 | environment:
11 | MOODLE_DOCKER_DBTYPE: pgsql
12 | MOODLE_DOCKER_DBNAME: moodle
13 | MOODLE_DOCKER_DBUSER: moodle
14 | MOODLE_DOCKER_DBPASS: "m@0dl3ing"
15 | MOODLE_DOCKER_BROWSER: firefox
16 | MOODLE_DOCKER_WEB_HOST: "${MOODLE_DOCKER_WEB_HOST}"
17 | db:
18 | image: postgres:11
19 | environment:
20 | POSTGRES_USER: moodle
21 | POSTGRES_PASSWORD: "m@0dl3ing"
22 | POSTGRES_DB: moodle
23 | exttests:
24 | image: moodlehq/moodle-exttests
25 | selenium:
26 | image: "selenium/standalone-firefox${MOODLE_DOCKER_SELENIUM_SUFFIX}:2.53.1"
27 | volumes:
28 | - "${MOODLE_DOCKER_WWWROOT}:/var/www/html:ro"
29 |
--------------------------------------------------------------------------------
/tests/setup.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 | basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
4 |
5 | # Log in dockerhub if possible (to avoid pull limits for unauthenticated uses).
6 | if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_TOKEN" ]; then
7 | echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USER" --password-stdin
8 | echo "Using authenticated connection (no pull limits)"
9 | else
10 | echo "Using unauthenticated docker (pull limits may apply). Setup DOCKER_USER and DOCKER_TOKEN if needed."
11 | fi
12 |
13 | if [ "$SUITE" = "phpunit" ];
14 | then
15 | initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/phpunit/cli/init.php"
16 | elif [ "$SUITE" = "behat" ];
17 | then
18 | initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/init.php"
19 | elif [ "$SUITE" = "phpunit-full" ];
20 | then
21 | export MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES=true
22 | initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/phpunit/cli/init.php"
23 | elif [ "$SUITE" = "behat-app-development" ];
24 | then
25 | git clone --branch "v$APP_VERSION" --depth 1 git://github.com/moodlehq/moodleapp $HOME/app
26 | git clone --branch "v$APP_VERSION" --depth 1 git://github.com/moodlehq/moodle-local_moodlemobileapp $HOME/moodle/local/moodlemobileapp
27 |
28 | docker run --volume $HOME/app:/app --workdir /app node:11 npm run setup
29 | docker run --volume $HOME/app:/app --workdir /app node:11 npm ci
30 |
31 | initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/init.php"
32 | elif [ "$SUITE" = "behat-app" ];
33 | then
34 | git clone --branch "v$APP_VERSION" --depth 1 git://github.com/moodlehq/moodle-local_moodlemobileapp $HOME/moodle/local/moodlemobileapp
35 |
36 | initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/init.php"
37 | else
38 | echo "Error, unknown suite '$SUITE'"
39 | exit 1
40 | fi
41 |
42 | echo "Pulling docker images"
43 | $basedir/bin/moodle-docker-compose pull
44 | echo "Starting up container"
45 | $basedir/bin/moodle-docker-compose up -d
46 | echo "Waiting for DB to come up"
47 | $basedir/bin/moodle-docker-wait-for-db
48 | echo "Waiting for Moodle app to come up"
49 | $basedir/bin/moodle-docker-wait-for-app
50 | echo "Running: $initcmd"
51 | $basedir/$initcmd
52 |
--------------------------------------------------------------------------------
/bin/moodle-docker-compose.cmd:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 |
3 | IF NOT EXIST "%MOODLE_DOCKER_WWWROOT%" (
4 | ECHO Error: MOODLE_DOCKER_WWWROOT is not set or not an existing directory
5 | EXIT /B 1
6 | )
7 |
8 | IF "%MOODLE_DOCKER_DB%"=="" (
9 | ECHO Error: MOODLE_DOCKER_DB is not set
10 | EXIT /B 1
11 | )
12 |
13 | PUSHD %cd%
14 | CD %~dp0..
15 | SET BASEDIR=%cd%
16 | POPD
17 | SET ASSETDIR=%BASEDIR%\assets
18 |
19 | SET COMPOSE_CONVERT_WINDOWS_PATHS=true
20 |
21 | SET DOCKERCOMPOSE=docker-compose -f "%BASEDIR%\base.yml"
22 | SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\service.mail.yml"
23 |
24 | IF "%MOODLE_DOCKER_PHP_VERSION%"=="" (
25 | SET MOODLE_DOCKER_PHP_VERSION=7.3
26 | )
27 |
28 | IF NOT "%MOODLE_DOCKER_DB%"=="pgsql" (
29 | SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\db.%MOODLE_DOCKER_DB%.yml"
30 | )
31 |
32 | SET filename=%BASEDIR%\db.%MOODLE_DOCKER_DB%.%MOODLE_DOCKER_PHP_VERSION%.yml
33 | if exist %filename% (
34 | SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%filename%"
35 | )
36 |
37 | IF NOT "%MOODLE_APP_VERSION%"=="" (
38 | ECHO Warning: MOODLE_APP_VERSION is deprecated, use MOODLE_DOCKER_APP_VERSION instead
39 |
40 | IF "%MOODLE_DOCKER_APP_VERSION%"=="" (
41 | SET MOODLE_DOCKER_APP_VERSION="%MOODLE_APP_VERSION%"
42 | )
43 | )
44 |
45 | IF "%MOODLE_DOCKER_BROWSER%"=="chrome" (
46 | IF NOT "%MOODLE_DOCKER_APP_PATH%"=="" (
47 | SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\moodle-app-dev.yml"
48 | ) ELSE IF NOT "%MOODLE_DOCKER_APP_VERSION%"=="" (
49 | SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\moodle-app.yml"
50 | )
51 | )
52 |
53 | IF NOT "%MOODLE_DOCKER_BROWSER%"=="" (
54 | IF NOT "%MOODLE_DOCKER_BROWSER%"=="firefox" (
55 | SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\selenium.%MOODLE_DOCKER_BROWSER%.yml"
56 | )
57 | )
58 |
59 | IF NOT "%MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES%"=="" (
60 | SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\phpunit-external-services.yml"
61 | )
62 |
63 | IF "%MOODLE_DOCKER_WEB_HOST%"=="" (
64 | SET MOODLE_DOCKER_WEB_HOST=localhost
65 | )
66 |
67 | IF "%MOODLE_DOCKER_WEB_PORT%"=="" (
68 | SET MOODLE_DOCKER_WEB_PORT=8000
69 | )
70 |
71 | SET "TRUE="
72 | IF NOT "%MOODLE_DOCKER_WEB_PORT%"=="%MOODLE_DOCKER_WEB_PORT::=%" SET TRUE=1
73 | IF NOT "%MOODLE_DOCKER_WEB_PORT%"=="0" SET TRUE=1
74 | IF DEFINED TRUE (
75 | REM If no bind ip has been configured (bind_ip:port), default to 127.0.0.1
76 | IF "%MOODLE_DOCKER_WEB_PORT%"=="%MOODLE_DOCKER_WEB_PORT::=%" (
77 | SET MOODLE_DOCKER_WEB_PORT=127.0.0.1:%MOODLE_DOCKER_WEB_PORT%
78 | )
79 | SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\webserver.port.yml"
80 | )
81 |
82 | IF "%MOODLE_DOCKER_SELENIUM_VNC_PORT%"=="" (
83 | SET MOODLE_DOCKER_SELENIUM_SUFFIX=
84 | ) ELSE (
85 | SET "TRUE="
86 | IF NOT "%MOODLE_DOCKER_SELENIUM_VNC_PORT%"=="%MOODLE_DOCKER_SELENIUM_VNC_PORT::=%" SET TRUE=1
87 | IF NOT "%MOODLE_DOCKER_SELENIUM_VNC_PORT%"=="0" SET TRUE=1
88 | IF DEFINED TRUE (
89 | SET MOODLE_DOCKER_SELENIUM_SUFFIX=-debug
90 | SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\selenium.debug.yml"
91 | REM If no bind ip has been configured (bind_ip:port), default to 127.0.0.1
92 | IF "%MOODLE_DOCKER_SELENIUM_VNC_PORT%"=="%MOODLE_DOCKER_SELENIUM_VNC_PORT::=%" (
93 | SET MOODLE_DOCKER_SELENIUM_VNC_PORT=127.0.0.1:%MOODLE_DOCKER_SELENIUM_VNC_PORT%
94 | )
95 | )
96 | )
97 |
98 | %DOCKERCOMPOSE% %*
99 |
--------------------------------------------------------------------------------
/config.docker-template.php:
--------------------------------------------------------------------------------
1 | dbtype = getenv('MOODLE_DOCKER_DBTYPE');
8 | $CFG->dblibrary = 'native';
9 | $CFG->dbhost = 'db';
10 | $CFG->dbname = getenv('MOODLE_DOCKER_DBNAME');
11 | $CFG->dbuser = getenv('MOODLE_DOCKER_DBUSER');
12 | $CFG->dbpass = getenv('MOODLE_DOCKER_DBPASS');
13 | $CFG->prefix = 'm_';
14 | $CFG->dboptions = ['dbcollation' => getenv('MOODLE_DOCKER_DBCOLLATION')];
15 |
16 | $host = 'localhost';
17 | if (!empty(getenv('MOODLE_DOCKER_WEB_HOST'))) {
18 | $host = getenv('MOODLE_DOCKER_WEB_HOST');
19 | }
20 | $CFG->wwwroot = "http://{$host}";
21 | $port = getenv('MOODLE_DOCKER_WEB_PORT');
22 | if (!empty($port)) {
23 | // Extract port in case the format is bind_ip:port.
24 | $parts = explode(':', $port);
25 | $port = end($parts);
26 | if ((string)(int)$port === (string)$port) { // Only if it's int value.
27 | $CFG->wwwroot .= ":{$port}";
28 | }
29 | }
30 | $CFG->dataroot = '/var/www/moodledata';
31 | $CFG->admin = 'admin';
32 | $CFG->directorypermissions = 0777;
33 | $CFG->smtphosts = 'mailhog:1025';
34 | $CFG->noreplyaddress = 'noreply@example.com';
35 |
36 | // Debug options - possible to be controlled by flag in future..
37 | $CFG->debug = (E_ALL | E_STRICT); // DEBUG_DEVELOPER
38 | $CFG->debugdisplay = 1;
39 | $CFG->debugstringids = 1; // Add strings=1 to url to get string ids.
40 | $CFG->perfdebug = 15;
41 | $CFG->debugpageinfo = 1;
42 | $CFG->allowthemechangeonurl = 1;
43 | $CFG->passwordpolicy = 0;
44 | $CFG->cronclionly = 0;
45 | $CFG->pathtophp = '/usr/local/bin/php';
46 |
47 | $CFG->phpunit_dataroot = '/var/www/phpunitdata';
48 | $CFG->phpunit_prefix = 't_';
49 | define('TEST_EXTERNAL_FILES_HTTP_URL', 'http://exttests');
50 |
51 | $CFG->behat_wwwroot = 'http://webserver';
52 | $CFG->behat_dataroot = '/var/www/behatdata';
53 | $CFG->behat_prefix = 'b_';
54 | $CFG->behat_profiles = array(
55 | 'default' => array(
56 | 'browser' => getenv('MOODLE_DOCKER_BROWSER'),
57 | 'wd_host' => 'http://selenium:4444/wd/hub',
58 | ),
59 | );
60 | $CFG->behat_faildump_path = '/var/www/behatfaildumps';
61 |
62 | define('PHPUNIT_LONGTEST', true);
63 |
64 | if (getenv('MOODLE_DOCKER_APP')) {
65 | $CFG->behat_ionic_wwwroot = 'http://moodleapp:8100';
66 | }
67 |
68 | if (getenv('MOODLE_DOCKER_PHPUNIT_EXTRAS')) {
69 | define('TEST_SEARCH_SOLR_HOSTNAME', 'solr');
70 | define('TEST_SEARCH_SOLR_INDEXNAME', 'test');
71 | define('TEST_SEARCH_SOLR_PORT', 8983);
72 |
73 | define('TEST_SESSION_REDIS_HOST', 'redis');
74 | define('TEST_CACHESTORE_REDIS_TESTSERVERS', 'redis');
75 |
76 | define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://mongo:27017');
77 |
78 | define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', "memcached0:11211\nmemcached1:11211");
79 | define('TEST_CACHESTORE_MEMCACHE_TESTSERVERS', "memcached0:11211\nmemcached1:11211");
80 |
81 | define('TEST_LDAPLIB_HOST_URL', 'ldap://ldap');
82 | define('TEST_LDAPLIB_BIND_DN', 'cn=admin,dc=openstack,dc=org');
83 | define('TEST_LDAPLIB_BIND_PW', 'password');
84 | define('TEST_LDAPLIB_DOMAIN', 'ou=Users,dc=openstack,dc=org');
85 |
86 | define('TEST_AUTH_LDAP_HOST_URL', 'ldap://ldap');
87 | define('TEST_AUTH_LDAP_BIND_DN', 'cn=admin,dc=openstack,dc=org');
88 | define('TEST_AUTH_LDAP_BIND_PW', 'password');
89 | define('TEST_AUTH_LDAP_DOMAIN', 'ou=Users,dc=openstack,dc=org');
90 |
91 | define('TEST_ENROL_LDAP_HOST_URL', 'ldap://ldap');
92 | define('TEST_ENROL_LDAP_BIND_DN', 'cn=admin,dc=openstack,dc=org');
93 | define('TEST_ENROL_LDAP_BIND_PW', 'password');
94 | define('TEST_ENROL_LDAP_DOMAIN', 'ou=Users,dc=openstack,dc=org');
95 | }
96 |
97 | require_once(__DIR__ . '/lib/setup.php');
98 |
--------------------------------------------------------------------------------
/bin/moodle-docker-compose:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | if [ ! -d "$MOODLE_DOCKER_WWWROOT" ];
5 | then
6 | echo 'Error: $MOODLE_DOCKER_WWWROOT is not set or not an existing directory'
7 | exit 1
8 | fi
9 |
10 | if [ -z "$MOODLE_DOCKER_DB" ];
11 | then
12 | echo 'Error: $MOODLE_DOCKER_DB is not set'
13 | exit 1
14 | fi
15 |
16 | # Nasty portable way to the directory of this script, following symlink,
17 | # because readlink -f not on OSX. Thanks stack overflow..
18 | SOURCE="${BASH_SOURCE[0]}"
19 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
20 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
21 | SOURCE="$(readlink "$SOURCE")"
22 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
23 | done
24 | basedir="$( cd -P "$( dirname "$SOURCE" )/../" && pwd )"
25 | export ASSETDIR="${basedir}/assets"
26 |
27 |
28 | dockercompose="docker-compose -f ${basedir}/base.yml"
29 | dockercompose="${dockercompose} -f ${basedir}/service.mail.yml"
30 |
31 | # PHP Version.
32 | export MOODLE_DOCKER_PHP_VERSION=${MOODLE_DOCKER_PHP_VERSION:-7.3}
33 |
34 | # Database flavour
35 | if [ "$MOODLE_DOCKER_DB" != 'pgsql' ];
36 | then
37 | dockercompose="${dockercompose} -f ${basedir}/db.${MOODLE_DOCKER_DB}.yml"
38 |
39 | fi
40 |
41 | # Support PHP version overrides for DB..
42 | filename="${basedir}/db.${MOODLE_DOCKER_DB}.${MOODLE_DOCKER_PHP_VERSION}.yml"
43 | if [ -f $filename ]; then
44 | dockercompose="${dockercompose} -f ${filename}"
45 | fi
46 |
47 | # Mobile app deprecated variables
48 | if [ ! -z "$MOODLE_APP_VERSION" ];
49 | then
50 | echo 'Warning: $MOODLE_APP_VERSION is deprecated, use $MOODLE_DOCKER_APP_VERSION instead'
51 |
52 | if [ -z "$MOODLE_DOCKER_APP_VERSION" ];
53 | then
54 | export MOODLE_DOCKER_APP_VERSION="$MOODLE_APP_VERSION"
55 | fi
56 | fi
57 |
58 | # Mobile app for development
59 | if [[ ! -z "$MOODLE_DOCKER_BROWSER" ]] && [[ "$MOODLE_DOCKER_BROWSER" == "chrome" ]] && [[ ! -z "$MOODLE_DOCKER_APP_PATH" ]];
60 | then
61 | dockercompose="${dockercompose} -f ${basedir}/moodle-app-dev.yml"
62 | # Mobile app using a docker image
63 | elif [[ ! -z "$MOODLE_DOCKER_BROWSER" ]] && [[ "$MOODLE_DOCKER_BROWSER" == "chrome" ]] && [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]];
64 | then
65 | dockercompose="${dockercompose} -f ${basedir}/moodle-app.yml"
66 | fi
67 |
68 | # Selenium browser
69 | if [[ ! -z "$MOODLE_DOCKER_BROWSER" ]] && [[ "$MOODLE_DOCKER_BROWSER" != "firefox" ]];
70 | then
71 | dockercompose="${dockercompose} -f ${basedir}/selenium.${MOODLE_DOCKER_BROWSER}.yml"
72 | fi
73 |
74 | # Selenium VNC port
75 | export MOODLE_DOCKER_SELENIUM_SUFFIX=""
76 | if [[ $MOODLE_DOCKER_SELENIUM_VNC_PORT == *":"* ]] || [[ $MOODLE_DOCKER_SELENIUM_VNC_PORT -gt 0 ]]
77 | then
78 | export MOODLE_DOCKER_SELENIUM_SUFFIX="-debug"
79 | # If no bind ip has been configured (bind_ip:port), default to 127.0.0.1
80 | if [[ ! $MOODLE_DOCKER_SELENIUM_VNC_PORT == *":"* ]]
81 | then
82 | MOODLE_DOCKER_SELENIUM_VNC_PORT=127.0.0.1:$MOODLE_DOCKER_SELENIUM_VNC_PORT
83 | fi
84 | dockercompose="${dockercompose} -f ${basedir}/selenium.debug.yml"
85 | fi
86 |
87 | # External services
88 | if [[ ! -z "$MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES" ]];
89 | then
90 | dockercompose="${dockercompose} -f ${basedir}/phpunit-external-services.yml"
91 | fi
92 |
93 | # Webserver host
94 | export MOODLE_DOCKER_WEB_HOST=${MOODLE_DOCKER_WEB_HOST:-localhost}
95 |
96 | # Webserver port
97 | export MOODLE_DOCKER_WEB_PORT=${MOODLE_DOCKER_WEB_PORT:-8000}
98 | if [[ $MOODLE_DOCKER_WEB_PORT == *":"* ]] || [[ $MOODLE_DOCKER_WEB_PORT -gt 0 ]]
99 | then
100 | # If no bind ip has been configured (bind_ip:port), default to 127.0.0.1
101 | if [[ ! $MOODLE_DOCKER_WEB_PORT == *":"* ]]
102 | then
103 | MOODLE_DOCKER_WEB_PORT=127.0.0.1:$MOODLE_DOCKER_WEB_PORT
104 | fi
105 | dockercompose="${dockercompose} -f ${basedir}/webserver.port.yml"
106 | fi
107 |
108 |
109 | # Mac OS Compatbility
110 | if [[ "$(uname)" == "Darwin" ]]; then
111 | # Support https://docs.docker.com/docker-for-mac/osxfs-caching/
112 | dockercompose="${dockercompose} -f ${basedir}/volumes-cached.yml"
113 | fi
114 |
115 |
116 | $dockercompose "$@"
117 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: bash
2 | services: docker
3 | fast_finish: true
4 | env:
5 | # phpunit
6 | # PostgreSQL highest, lowest php supported
7 | # We have set the "phpunit-full" to run against master
8 | - "PHP=7.4 DB=pgsql GIT=master SUITE=phpunit-full"
9 | - "PHP=7.3 DB=pgsql GIT=master SUITE=phpunit-full"
10 | # Other dev branches, also "phpunit-full"
11 | - "PHP=7.4 DB=pgsql GIT=MOODLE_311_STABLE SUITE=phpunit-full"
12 | - "PHP=7.3 DB=pgsql GIT=MOODLE_311_STABLE SUITE=phpunit-full"
13 | # Simpler "phpunit" for stables
14 | - "PHP=7.4 DB=pgsql GIT=v3.10.0 SUITE=phpunit"
15 | - "PHP=7.2 DB=pgsql GIT=v3.10.0 SUITE=phpunit"
16 | - "PHP=7.4 DB=pgsql GIT=v3.9.1 SUITE=phpunit"
17 | - "PHP=7.2 DB=pgsql GIT=v3.9.1 SUITE=phpunit"
18 | - "PHP=7.4 DB=pgsql GIT=v3.8.4 SUITE=phpunit"
19 | - "PHP=7.1 DB=pgsql GIT=v3.8.4 SUITE=phpunit"
20 | - "PHP=7.2 DB=pgsql GIT=v3.5.8 SUITE=phpunit"
21 | - "PHP=7.0 DB=pgsql GIT=v3.5.8 SUITE=phpunit"
22 | # Other databases, only highest php supported
23 | - "PHP=7.4 DB=mssql GIT=v3.10.0 SUITE=phpunit"
24 | - "PHP=7.4 DB=mssql GIT=v3.9.1 SUITE=phpunit"
25 | - "PHP=7.4 DB=mssql GIT=v3.8.4 SUITE=phpunit"
26 | - "PHP=7.2 DB=mssql GIT=v3.5.8 SUITE=phpunit"
27 | - "PHP=7.4 DB=mysql GIT=v3.10.0 SUITE=phpunit"
28 | - "PHP=7.4 DB=mysql GIT=v3.9.1 SUITE=phpunit"
29 | - "PHP=7.4 DB=mysql GIT=v3.8.4 SUITE=phpunit"
30 | - "PHP=7.2 DB=mysql GIT=v3.5.8 SUITE=phpunit"
31 | - "PHP=7.4 DB=oracle GIT=v3.10.0 SUITE=phpunit"
32 | - "PHP=7.4 DB=oracle GIT=v3.9.1 SUITE=phpunit"
33 | - "PHP=7.4 DB=oracle GIT=v3.8.4 SUITE=phpunit"
34 | - "PHP=7.2 DB=oracle GIT=v3.5.8 SUITE=phpunit"
35 | # MariaDB, only lowest php supported
36 | - "PHP=7.2 DB=mariadb GIT=v3.10.0 SUITE=phpunit"
37 | - "PHP=7.2 DB=mariadb GIT=v3.9.1 SUITE=phpunit"
38 | - "PHP=7.1 DB=mariadb GIT=v3.8.4 SUITE=phpunit"
39 | - "PHP=7.0 DB=mariadb GIT=v3.5.8 SUITE=phpunit"
40 | # behat
41 | # PostgreSQL highest, lowest (2 browsers)
42 | - "PHP=7.4 DB=pgsql GIT=master SUITE=behat BROWSER=chrome"
43 | - "PHP=7.4 DB=pgsql GIT=master SUITE=behat BROWSER=firefox"
44 | - "PHP=7.3 DB=pgsql GIT=master SUITE=behat BROWSER=chrome"
45 | - "PHP=7.3 DB=pgsql GIT=master SUITE=behat BROWSER=firefox"
46 | - "PHP=7.4 DB=pgsql GIT=MOODLE_311_STABLE SUITE=behat BROWSER=chrome"
47 | - "PHP=7.4 DB=pgsql GIT=MOODLE_311_STABLE SUITE=behat BROWSER=firefox"
48 | - "PHP=7.3 DB=pgsql GIT=MOODLE_311_STABLE SUITE=behat BROWSER=chrome"
49 | - "PHP=7.3 DB=pgsql GIT=MOODLE_311_STABLE SUITE=behat BROWSER=firefox"
50 | - "PHP=7.4 DB=pgsql GIT=v3.10.0 SUITE=behat BROWSER=chrome"
51 | - "PHP=7.4 DB=pgsql GIT=v3.10.0 SUITE=behat BROWSER=firefox"
52 | - "PHP=7.2 DB=pgsql GIT=v3.10.0 SUITE=behat BROWSER=chrome"
53 | - "PHP=7.2 DB=pgsql GIT=v3.10.0 SUITE=behat BROWSER=firefox"
54 | - "PHP=7.4 DB=pgsql GIT=v3.9.1 SUITE=behat BROWSER=chrome"
55 | - "PHP=7.4 DB=pgsql GIT=v3.9.1 SUITE=behat BROWSER=firefox"
56 | - "PHP=7.2 DB=pgsql GIT=v3.9.1 SUITE=behat BROWSER=chrome"
57 | - "PHP=7.2 DB=pgsql GIT=v3.9.1 SUITE=behat BROWSER=firefox"
58 | - "PHP=7.4 DB=pgsql GIT=v3.8.4 SUITE=behat BROWSER=chrome"
59 | - "PHP=7.4 DB=pgsql GIT=v3.8.4 SUITE=behat BROWSER=firefox"
60 | - "PHP=7.1 DB=pgsql GIT=v3.8.4 SUITE=behat BROWSER=chrome"
61 | - "PHP=7.1 DB=pgsql GIT=v3.8.4 SUITE=behat BROWSER=firefox"
62 | - "PHP=7.2 DB=pgsql GIT=v3.5.8 SUITE=behat BROWSER=chrome"
63 | - "PHP=7.2 DB=pgsql GIT=v3.5.8 SUITE=behat BROWSER=firefox"
64 | - "PHP=7.0 DB=pgsql GIT=v3.5.8 SUITE=behat BROWSER=chrome"
65 | - "PHP=7.0 DB=pgsql GIT=v3.5.8 SUITE=behat BROWSER=firefox"
66 | # Other databases, only highest php supported (1 browsers)
67 | - "PHP=7.4 DB=mssql GIT=v3.10.0 SUITE=behat BROWSER=firefox"
68 | - "PHP=7.4 DB=mssql GIT=v3.9.1 SUITE=behat BROWSER=chrome"
69 | - "PHP=7.4 DB=mssql GIT=v3.8.4 SUITE=behat BROWSER=firefox"
70 | - "PHP=7.2 DB=mssql GIT=v3.5.8 SUITE=behat BROWSER=chrome"
71 | - "PHP=7.4 DB=mysql GIT=v3.10.0 SUITE=behat BROWSER=firefox"
72 | - "PHP=7.4 DB=mysql GIT=v3.9.1 SUITE=behat BROWSER=chrome"
73 | - "PHP=7.4 DB=mysql GIT=v3.8.4 SUITE=behat BROWSER=firefox"
74 | - "PHP=7.2 DB=mysql GIT=v3.5.8 SUITE=behat BROWSER=chrome"
75 | - "PHP=7.4 DB=oracle GIT=v3.10.0 SUITE=behat BROWSER=firefox"
76 | - "PHP=7.4 DB=oracle GIT=v3.9.1 SUITE=behat BROWSER=chrome"
77 | - "PHP=7.4 DB=oracle GIT=v3.8.4 SUITE=behat BROWSER=firefox"
78 | - "PHP=7.2 DB=oracle GIT=v3.5.8 SUITE=behat BROWSER=chrome"
79 | # MariaDB, only lowest php supported (1 browsers)
80 | - "PHP=7.2 DB=mariadb GIT=v3.10.0 SUITE=behat BROWSER=chrome"
81 | - "PHP=7.2 DB=mariadb GIT=v3.9.1 SUITE=behat BROWSER=firefox"
82 | - "PHP=7.2 DB=mariadb GIT=v3.8.4 SUITE=behat BROWSER=chrome"
83 | - "PHP=7.0 DB=mariadb GIT=v3.5.8 SUITE=behat BROWSER=firefox"
84 | # Mobile app
85 | - "PHP=7.4 DB=pgsql GIT=master SUITE=behat-app-development BROWSER=chrome APP_VERSION=3.9.0 APP_PATH=$HOME/app"
86 | - "PHP=7.4 DB=pgsql GIT=master SUITE=behat-app BROWSER=chrome APP_VERSION=3.9.0"
87 | install:
88 | - git clone --branch $GIT --depth 1 git://github.com/moodle/moodle $HOME/moodle
89 | - cp config.docker-template.php $HOME/moodle/config.php
90 | - export MOODLE_DOCKER_DB=$DB
91 | - export MOODLE_DOCKER_BROWSER=$BROWSER
92 | - export MOODLE_DOCKER_WWWROOT="$HOME/moodle"
93 | - export MOODLE_DOCKER_PHP_VERSION=$PHP
94 | - export MOODLE_DOCKER_APP_PATH=$APP_PATH
95 | - export MOODLE_DOCKER_APP_VERSION=$APP_VERSION
96 | before_script:
97 | - tests/setup.sh
98 | script:
99 | - tests/test.sh
100 | after_script:
101 | - bin/moodle-docker-compose down
102 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # moodle-docker: Docker Containers for Moodle Developers
2 | [](https://travis-ci.com/moodlehq/moodle-docker/branches)
3 |
4 | This repository contains Docker configuration aimed at Moodle developers and testers to easily deploy a testing environment for Moodle.
5 |
6 | ## Features:
7 | * All supported database servers (PostgreSQL, MySQL, Micosoft SQL Server, Oracle XE)
8 | * Behat/Selenium configuration for Firefox and Chrome
9 | * Catch-all smtp server and web interface to messages using [MailHog](https://github.com/mailhog/MailHog/)
10 | * All PHP Extensions enabled configured for external services (e.g. solr, ldap)
11 | * All supported PHP versions
12 | * Zero-configuration approach
13 | * Backed by [automated tests](https://travis-ci.com/moodlehq/moodle-docker/branches)
14 |
15 | ## Prerequisites
16 | * [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose/) installed
17 | * 3.25GB of RAM (if you choose [Microsoft SQL Server](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup#prerequisites) as db server)
18 |
19 | ## Quick start
20 |
21 | ```bash
22 | # Set up path to Moodle code
23 | export MOODLE_DOCKER_WWWROOT=/path/to/moodle/code
24 | # Choose a db server (Currently supported: pgsql, mariadb, mysql, mssql, oracle)
25 | export MOODLE_DOCKER_DB=pgsql
26 |
27 | # Ensure customized config.php for the Docker containers is in place
28 | cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php
29 |
30 | # Start up containers
31 | bin/moodle-docker-compose up -d
32 |
33 | # Wait for DB to come up (important for oracle/mssql)
34 | bin/moodle-docker-wait-for-db
35 |
36 | # Work with the containers (see below)
37 | # [..]
38 |
39 | # Shut down and destroy containers
40 | bin/moodle-docker-compose down
41 | ```
42 |
43 | ## Use containers for running behat tests
44 |
45 | ```bash
46 | # Initialize behat environment
47 | bin/moodle-docker-compose exec webserver php admin/tool/behat/cli/init.php
48 | # [..]
49 |
50 | # Run behat tests
51 | bin/moodle-docker-compose exec -u www-data webserver php admin/tool/behat/cli/run.php --tags=@auth_manual
52 | Running single behat site:
53 | Moodle 3.4dev (Build: 20171006), 33a3ec7c9378e64c6f15c688a3c68a39114aa29d
54 | Php: 7.1.9, pgsql: 9.6.5, OS: Linux 4.9.49-moby x86_64
55 | Server OS "Linux", Browser: "firefox"
56 | Started at 25-05-2017, 19:04
57 | ...............
58 |
59 | 2 scenarios (2 passed)
60 | 15 steps (15 passed)
61 | 1m35.32s (41.60Mb)
62 | ```
63 |
64 | Notes:
65 | * The behat faildump directory is exposed at http://localhost:8000/_/faildumps/.
66 |
67 | ## Use containers for running phpunit tests
68 |
69 | ```bash
70 | # Initialize phpunit environment
71 | bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php
72 | # [..]
73 |
74 | # Run phpunit tests
75 | bin/moodle-docker-compose exec webserver vendor/bin/phpunit auth_manual_testcase auth/manual/tests/manual_test.php
76 | Moodle 3.4dev (Build: 20171006), 33a3ec7c9378e64c6f15c688a3c68a39114aa29d
77 | Php: 7.1.9, pgsql: 9.6.5, OS: Linux 4.9.49-moby x86_64
78 | PHPUnit 5.5.7 by Sebastian Bergmann and contributors.
79 |
80 | .. 2 / 2 (100%)
81 |
82 | Time: 4.45 seconds, Memory: 38.00MB
83 |
84 | OK (2 tests, 7 assertions)
85 | ```
86 |
87 | Notes:
88 | * If you want to run test with coverage report, use command: `bin/moodle-docker-compose exec webserver phpdbg -qrr vendor/bin/phpunit --coverage-text auth_manual_testcase auth/manual/tests/manual_test.php`
89 |
90 | ## Use containers for manual testing
91 |
92 | ```bash
93 | # Initialize Moodle database for manual testing
94 | 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="admin@example.com"
95 | ```
96 |
97 | Notes:
98 | * Moodle is configured to listen on `http://localhost:8000/`.
99 | * Mailhog is listening on `http://localhost:8000/_/mail` to view emails which Moodle has sent out.
100 | * The admin `username` you need to use for logging in is `admin` by default. You can customize it by passing `--adminuser='myusername'`
101 |
102 | ## Use containers for running behat tests for the mobile app
103 |
104 | In order to run Behat tests for the mobile app, you need to install the [local_moodlemobileapp](https://github.com/moodlehq/moodle-local_moodlemobileapp) 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.
105 |
106 | The Behat tests will be run against a container serving the mobile application, you have two options here:
107 |
108 | 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](https://hub.docker.com/r/moodlehq/moodleapp) image will be downloaded from docker hub.
109 |
110 | 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` and `npm run setup` locally.
111 |
112 | For both options, you also need to set `MOODLE_DOCKER_BROWSER` to "chrome".
113 |
114 | ```bash
115 | # Install local_moodlemobileapp plugin
116 | git clone git://github.com/moodlehq/moodle-local_moodlemobileapp "$MOODLE_DOCKER_WWWROOT/local/moodlemobileapp"
117 |
118 | # Initialize behat environment
119 | bin/moodle-docker-compose exec webserver php admin/tool/behat/cli/init.php
120 | # [..]
121 |
122 | # Run behat tests
123 | bin/moodle-docker-compose exec -u www-data webserver php admin/tool/behat/cli/run.php --tags="@app&&@mod_login"
124 | Running single behat site:
125 | Moodle 4.0dev (Build: 20200615), a2b286ce176fbe361f0889abc8f30f043cd664ae
126 | Php: 7.2.30, pgsql: 11.8 (Debian 11.8-1.pgdg90+1), OS: Linux 5.3.0-61-generic x86_64
127 | Server OS "Linux", Browser: "chrome"
128 | Browser specific fixes have been applied. See http://docs.moodle.org/dev/Acceptance_testing#Browser_specific_fixes
129 | Started at 13-07-2020, 18:34
130 | .....................................................................
131 |
132 | 4 scenarios (4 passed)
133 | 69 steps (69 passed)
134 | 3m3.17s (55.02Mb)
135 | ```
136 |
137 | If you are going with the second option, this *can* be used for local development of the mobile 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.
138 |
139 | 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:
140 |
141 | ```
142 | docker run --volume $MOODLE_DOCKER_APP_PATH:/app --workdir /app node:11 npm install
143 | docker run --volume $MOODLE_DOCKER_APP_PATH:/app --workdir /app node:11 npm run setup
144 | ```
145 |
146 | ## Using VNC to view behat tests
147 |
148 | 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.
149 |
150 | For example, if you set `MOODLE_DOCKER_SELENIUM_VNC_PORT` to 5900..
151 | 1. Download a VNC client: https://www.realvnc.com/en/connect/download/viewer/
152 | 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'.
153 | 3. You should be able to see an empty Desktop. When you run any Behat tests a browser will popup and you will see the tests execute.
154 |
155 | ## Stop and restart containers
156 |
157 | `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`.
158 |
159 | ```bash
160 | # Stop containers
161 | bin/moodle-docker-compose stop
162 |
163 | # Restart containers
164 | bin/moodle-docker-compose start
165 | ```
166 |
167 | ## Environment variables
168 |
169 | You can change the configuration of the docker images by setting various environment variables before calling `bin/moodle-docker-compose up`.
170 |
171 | | Environment Variable | Mandatory | Allowed values | Default value | Notes |
172 | |-------------------------------------------|-----------|---------------------------------------|---------------|------------------------------------------------------------------------------|
173 | | `MOODLE_DOCKER_DB` | yes | pgsql, mariadb, mysql, mssql, oracle | none | The database server to run against |
174 | | `MOODLE_DOCKER_WWWROOT` | yes | path on your file system | none | The path to the Moodle codebase you intend to test |
175 | | `MOODLE_DOCKER_PHP_VERSION` | no | 7.4, 7.3, 7.2, 7.1, 7.0, 5.6 | 7.3 | The php version to use |
176 | | `MOODLE_DOCKER_BROWSER` | no | firefox, chrome | firefox | The browser to run Behat against |
177 | | `MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES` | no | any value | not set | If set, dependencies for memcached, redis, solr, and openldap are added |
178 | | `MOODLE_DOCKER_WEB_HOST` | no | any valid hostname | localhost | The hostname for web |
179 | | `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) |
180 | | `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 |
181 | | `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 |
182 | | `MOODLE_DOCKER_APP_VERSION` | no | next, latest, or an app version number| not set | If set will start an instance of the Moodle app if the chrome browser is selected |
183 |
184 | ## Using XDebug for live debugging
185 |
186 | The XDebug PHP Extension is not included in this setup and there are reasons not to include it by default.
187 |
188 | However, if you want to work with XDebug, especially for live debugging, you can add XDebug to a running webserver container easily:
189 |
190 | ```
191 | # Install XDebug extension with PECL
192 | moodle-docker-compose exec webserver pecl install xdebug
193 |
194 | # Set some wise setting for live debugging - change this as needed
195 | read -r -d '' conf <<'EOF'
196 | ; Settings for Xdebug Docker configuration
197 | xdebug.coverage_enable = 0
198 | xdebug.default_enable = 0
199 | xdebug.cli_color = 2
200 | xdebug.file_link_format = phpstorm://open?%f:%l
201 | xdebug.idekey = PHPSTORM
202 | xdebug.remote_enable = 1
203 | xdebug.remote_autostart = 1
204 | xdebug.remote_host = host.docker.internal
205 | EOF
206 | moodle-docker-compose exec webserver bash -c "echo '$conf' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
207 |
208 | # Enable XDebug extension in Apache
209 | moodle-docker-compose exec webserver docker-php-ext-enable xdebug
210 | ```
211 |
212 | While setting these XDebug settings depending on your local need, please take special care of the value of `xdebug.remote_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.
213 |
214 | After these commands, XDebug ist enabled and ready to be used in the webserver container.
215 | If you want to disable and re-enable XDebug during the lifetime of the webserver container, you can achieve this with these additional commands:
216 |
217 | ```
218 | # Disable XDebug extension in Apache and restart the webserver container
219 | moodle-docker-compose exec webserver sed -i 's/^zend_extension=/; zend_extension=/' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
220 | moodle-docker-compose restart webserver
221 |
222 | # Enable XDebug extension in Apache and restart the webserver container
223 | moodle-docker-compose exec webserver sed -i 's/^; zend_extension=/zend_extension=/' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
224 | moodle-docker-compose restart webserver
225 | ```
226 |
227 | ## Advanced usage
228 |
229 | As can be seen in [bin/moodle-docker-compose](https://github.com/moodlehq/moodle-docker/blob/master/bin/moodle-docker-compose),
230 | this repo is just a series of docker-compose configurations and light wrapper which make use of companion docker images. Each part
231 | is designed to be reusable and you are encouraged to use the docker[-compose] commands as needed.
232 |
233 | ## Companion docker images
234 |
235 | The following Moodle customised docker images are close companions of this project:
236 |
237 | * [moodle-php-apache](https://github.com/moodlehq/moodle-php-apache): Apache/PHP Environment preconfigured for all Moodle environments
238 | * [moodle-db-mssql](https://github.com/moodlehq/moodle-db-mssql): Microsoft SQL Server for Linux configured for Moodle
239 | * [moodle-db-oracle](https://github.com/moodlehq/moodle-db-oracle): Oracle XE configured for Moodle
240 |
241 | ## Contributions
242 |
243 | Are extremely welcome!
244 |
--------------------------------------------------------------------------------