Skip to content

Commit

Permalink
PM-45594 improved docker setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-kialo committed Oct 8, 2024
1 parent 20d15ef commit 53a2007
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
name: Moodle Plugin CI

on: [ push, pull_request ]
on: [ push, pull_request, workflow_dispatch ]

jobs:
test:
Expand Down
1 change: 1 addition & 0 deletions development/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
moodle/
moodle_mod/
.env

## Bundle
Expand Down
84 changes: 0 additions & 84 deletions development/config/config.php

This file was deleted.

6 changes: 3 additions & 3 deletions development/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: moodle-dev
name: mod_kialo
services:
mariadb:
image: docker.io/bitnami/mariadb:10.7
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions development/moodleimage/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
39 changes: 39 additions & 0 deletions development/moodleimage/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

// phpcs:ignoreFile
// Custom Moodle configuration. Is appended to Moodle's own config.php.

global $CFG;

// Allow arbitrary hostname (by default it's hardcoded).
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'];
}

//=========================================================================
// 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');
8 changes: 5 additions & 3 deletions development/moodleimage/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 [email protected] [email protected]"

# 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 "$@"
8 changes: 1 addition & 7 deletions development/sync.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion development/tests-init.sh
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 4 additions & 1 deletion development/tests-privacy.sh
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 4 additions & 1 deletion development/tests-run-all.sh
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 4 additions & 1 deletion development/tests-run.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 53a2007

Please sign in to comment.