From 53a2007d1e352e0347c9a1fecf6fac8adffc8344 Mon Sep 17 00:00:00 2001 From: Mathias Kahl Date: Tue, 8 Oct 2024 11:23:32 +0200 Subject: [PATCH] PM-45594 improved docker setup --- .github/workflows/moodle-ci.yml | 2 +- development/.gitignore | 1 + development/config/config.php | 84 --------------------------- development/docker-compose.yml | 6 +- development/moodleimage/Dockerfile | 2 + development/moodleimage/config.php | 39 +++++++++++++ development/moodleimage/entrypoint.sh | 8 ++- development/sync.sh | 8 +-- development/tests-init.sh | 2 +- development/tests-privacy.sh | 5 +- development/tests-run-all.sh | 5 +- development/tests-run.sh | 5 +- 12 files changed, 65 insertions(+), 102 deletions(-) delete mode 100644 development/config/config.php create mode 100644 development/moodleimage/config.php diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index 336e536..53c873d 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -11,7 +11,7 @@ # name: Moodle Plugin CI -on: [ push, pull_request ] +on: [ push, pull_request, workflow_dispatch ] jobs: test: diff --git a/development/.gitignore b/development/.gitignore index 60675ec..3534072 100644 --- a/development/.gitignore +++ b/development/.gitignore @@ -1,4 +1,5 @@ moodle/ +moodle_mod/ .env ## Bundle diff --git a/development/config/config.php b/development/config/config.php deleted file mode 100644 index be1081b..0000000 --- a/development/config/config.php +++ /dev/null @@ -1,84 +0,0 @@ -. - -// Moodle configuration file. -// Will be copied to Moodle when starting the docker compose setup. -// -// phpcs:disable - -unset($CFG); -global $CFG; -$CFG = new stdClass(); - -$CFG->dbtype = 'mariadb'; -$CFG->dblibrary = 'native'; -$CFG->dbhost = 'mariadb'; -$CFG->dbname = 'bitnami_moodle'; -$CFG->dbuser = 'bn_moodle'; -$CFG->dbpass = ''; -$CFG->prefix = 'mdl_'; -$CFG->dboptions = array ( - 'dbpersist' => 0, - 'dbport' => 3306, - 'dbsocket' => '', - 'dbcollation' => 'utf8mb4_unicode_ci', -); - -if (empty($_SERVER['HTTP_HOST'])) { - $_SERVER['HTTP_HOST'] = '127.0.0.1:8080'; -} -if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { - $CFG->wwwroot = 'https://' . $_SERVER['HTTP_HOST']; -} else { - $CFG->wwwroot = 'http://' . $_SERVER['HTTP_HOST']; -} -$CFG->dataroot = '/bitnami/moodledata'; -$CFG->admin = 'admin'; - -$CFG->directorypermissions = 02775; - -//========================================================================= -// PHPUNIT SUPPORT -//========================================================================= - $CFG->phpunit_prefix = 'phpu_'; - $CFG->phpunit_dataroot = '/bitnami/moodledata/phpunit'; - $CFG->phpunit_directorypermissions = 02777; // optional - $CFG->phpunit_profilingenabled = true; // optional to profile PHPUnit runs. - -//========================================================================= -// Custom settings for development -//========================================================================= - -// Force a debugging mode regardless the settings in the site administration - @error_reporting(E_ALL | E_STRICT); // NOT FOR PRODUCTION SERVERS! - @ini_set('display_errors', '1'); // NOT FOR PRODUCTION SERVERS! - $CFG->debug = (E_ALL | E_STRICT); // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS! - $CFG->debugdisplay = 1; // NOT FOR PRODUCTION SERVERS! - -// disable some caching so that we don't constantly have to manually purge caches in the web UI -$CFG->cachetemplates = false; -$CFG->langstringcache = false; - -// This setting is only used during the installation process. So once the Moodle site is installed, it is ignored. -$CFG->setsitepresetduringinstall = 'kialo-admin-preset.xml'; - -// Make sure that the temp directories are not deleted during the backup process. Allows easier testing of the backup process. -$CFG->keeptempdirectoriesonbackup = true; - -require_once(__DIR__ . '/lib/setup.php'); - -// There is no php closing tag in this file, -// it is intentional because it prevents trailing whitespace problems! diff --git a/development/docker-compose.yml b/development/docker-compose.yml index cfd3f56..44edb3d 100644 --- a/development/docker-compose.yml +++ b/development/docker-compose.yml @@ -1,4 +1,4 @@ -name: moodle-dev +name: mod_kialo services: mariadb: image: docker.io/bitnami/mariadb:10.7 @@ -37,8 +37,8 @@ services: # you can override the following by creating a .env file in the same directory as this file - TARGET_KIALO_URL=${TARGET_KIALO_URL:-http://localhost:5000} - MOODLE_HOST=http://${MOODLE_HOST:-localhost:8080} -# volumes: -# - './moodle:/var/www/html' + volumes: + - './moodle_mod:/var/www/html/mod/kialo' depends_on: - mariadb moodleapp: diff --git a/development/moodleimage/Dockerfile b/development/moodleimage/Dockerfile index 8c75e89..b9ca5c7 100644 --- a/development/moodleimage/Dockerfile +++ b/development/moodleimage/Dockerfile @@ -14,5 +14,7 @@ ENV MOODLE_BRANCH=${MOODLE_BRANCH} RUN git clone git://git.moodle.org/moodle.git /var/www/html --depth=1 --branch ${MOODLE_BRANCH} COPY entrypoint.sh /usr/local/bin/entrypoint.sh +COPY config.php /var/www/html/config_kialo.php + ENTRYPOINT ["entrypoint.sh"] CMD ["apache2-foreground"] diff --git a/development/moodleimage/config.php b/development/moodleimage/config.php new file mode 100644 index 0000000..02a3a0e --- /dev/null +++ b/development/moodleimage/config.php @@ -0,0 +1,39 @@ +wwwroot = 'https://' . $_SERVER['HTTP_HOST']; +} else { + $CFG->wwwroot = 'http://' . $_SERVER['HTTP_HOST']; +} + +//========================================================================= +// PHPUNIT SUPPORT +//========================================================================= + $CFG->phpunit_prefix = 'phpu_'; + $CFG->phpunit_dataroot = '/var/www/moodledata/phpunit'; + $CFG->phpunit_directorypermissions = 02777; // optional + $CFG->phpunit_profilingenabled = true; // optional to profile PHPUnit runs. + +//========================================================================= +// Custom settings for development +//========================================================================= + +// Force a debugging mode regardless the settings in the site administration + @error_reporting(E_ALL | E_STRICT); // NOT FOR PRODUCTION SERVERS! + @ini_set('display_errors', '1'); // NOT FOR PRODUCTION SERVERS! + $CFG->debug = (E_ALL | E_STRICT); // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS! + $CFG->debugdisplay = 1; // NOT FOR PRODUCTION SERVERS! + +// Make sure that the temp directories are not deleted during the backup process. Allows easier testing of the backup process. +$CFG->keeptempdirectoriesonbackup = true; + +require_once(__DIR__ . '/lib/setup.php'); diff --git a/development/moodleimage/entrypoint.sh b/development/moodleimage/entrypoint.sh index 91cc35e..a403526 100755 --- a/development/moodleimage/entrypoint.sh +++ b/development/moodleimage/entrypoint.sh @@ -1,9 +1,11 @@ #!/bin/bash -# see https://docs.moodle.org/404/en/Installing_Moodle#Command_line_installer +# Install Moodle. See https://docs.moodle.org/404/en/Installing_Moodle#Command_line_installer chown -R www-data /var/www/html - -# TODO: Make moodle default user "user" and not "admin" su - www-data -s /bin/bash -c "php /var/www/html/admin/cli/install.php --non-interactive --agree-license --allow-unstable --wwwroot=$MOODLE_HOST --dataroot=/var/www/moodledata --dbtype=mariadb --dbhost=$MOODLE_DATABASE_HOST --dbname=moodle --dbuser=moodle --dbport=$MOODLE_DATABASE_PORT_NUMBER --fullname=Moodle --shortname=moodle --adminuser=user --adminpass=$MOODLE_PASSWORD --adminemail=sre@kialo.com --supportemail=sre@kialo.com" +# Amend the config.php file to include our own config for development. +# The line should be added before the last line "require_once(__DIR__ . '/lib/setup.php');". +sed -i '/require_once/i\require_once(__DIR__ . "/config_kialo.php");' /var/www/html/config.php + exec /usr/local/bin/moodle-docker-php-entrypoint "$@" diff --git a/development/sync.sh b/development/sync.sh index 41f9bf3..8ec55e0 100755 --- a/development/sync.sh +++ b/development/sync.sh @@ -1,12 +1,6 @@ # Ensure this script is executed in the same folder cd "$(dirname "$0")" -# Ensure the directory exists -mkdir -p ./moodle/mod/kialo - # syncs the content of the development version of this plugin to the copy in the docker moodle installation (/moodle/mod/kialo) -rsync -atm --delete --delete-excluded --exclude={'/development','/.[!.]*'} .. ./moodle/mod/kialo +rsync -atm --delete --delete-excluded --exclude={'/development','/.[!.]*'} .. ./moodle_mod echo "Synced plugin." - -cp config/config.php moodle/config.php -echo "Synced config.php" diff --git a/development/tests-init.sh b/development/tests-init.sh index 87956b3..13ff589 100755 --- a/development/tests-init.sh +++ b/development/tests-init.sh @@ -1,2 +1,2 @@ # needs to run once initially and again whenever new tests are added -docker exec -i development-moodle-1 /bin/bash -c "cd /bitnami/moodle; php admin/tool/phpunit/cli/init.php" +docker exec -i mod_kialo-moodle-1 /bin/bash -c "cd /var/www/html; php admin/tool/phpunit/cli/init.php" diff --git a/development/tests-privacy.sh b/development/tests-privacy.sh index 8c60748..6e6ef34 100755 --- a/development/tests-privacy.sh +++ b/development/tests-privacy.sh @@ -1,2 +1,5 @@ +# Ensure files are up-to-date +./sync.sh + # Run the tests -docker exec -i development-moodle-1 /bin/bash -c "cd /bitnami/moodle; vendor/bin/phpunit --testsuite core_privacy_testsuite --filter kialo" +docker exec -i mod_kialo-moodle-1 /bin/bash -c "cd /var/www/html; vendor/bin/phpunit --testsuite core_privacy_testsuite --filter kialo" diff --git a/development/tests-run-all.sh b/development/tests-run-all.sh index 96ffe17..62ad3a3 100755 --- a/development/tests-run-all.sh +++ b/development/tests-run-all.sh @@ -1,2 +1,5 @@ +# Ensure files are up-to-date +./sync.sh + # Run the tests -docker exec -i development-moodle-1 /bin/bash -c "cd /bitnami/moodle; vendor/bin/phpunit --testsuite mod_kialo_testsuite" +docker exec -i mod_kialo-moodle-1 /bin/bash -c "cd /var/www/html; vendor/bin/phpunit --testsuite mod_kialo_testsuite" diff --git a/development/tests-run.sh b/development/tests-run.sh index 6ebbe9a..78c3831 100755 --- a/development/tests-run.sh +++ b/development/tests-run.sh @@ -1,3 +1,6 @@ +# Ensure files are up-to-date +./sync.sh + # Run a specific test file (path relative to mod/kialo/tests) # Example: ./tests-run.sh classes/mod_kialo_test.php -docker exec -i development-moodle-1 /bin/bash -c "cd /bitnami/moodle; vendor/bin/phpunit mod/kialo/tests/$1" +docker exec -i mod_kialo-moodle-1 /bin/bash -c "cd /var/www/html; vendor/bin/phpunit mod/kialo/tests/$1"