From 1172503188f219fda7a4f0977fb8ffcc74617eed Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Fri, 16 Jul 2021 15:09:12 +1000 Subject: [PATCH 01/11] Add feature to be able to run several containers at the same time --- README.md | 62 +++++++++---- control | 149 ++++++++++++++++++++++++++++-- docker-compose.yml | 8 +- docker/moodle/Dockerfile | 3 +- docker/moodle/custom-php-fpm.conf | 2 + docker/moodle/entrypoint.sh | 2 + docker/moodle/nginx-site | 2 +- docker/moodle/php.ini | 2 +- docker/moodle/xdebug.ini | 2 +- moodle-config | 5 +- 10 files changed, 205 insertions(+), 32 deletions(-) create mode 100644 docker/moodle/custom-php-fpm.conf diff --git a/README.md b/README.md index b8e36635ec1..c39f6ac7528 100644 --- a/README.md +++ b/README.md @@ -4,32 +4,61 @@ - Docker - Docker-compose +- Nginx -## Usage +## Set up -1. Clone this repository +1. Clone this repository to the folder where all your moodle projects are stored (e.g ~/projects) ``` -git clone git@github.com:catalyst/docker_moodle.git docker_moodle +git clone git@github.com:catalyst/docker_moodle.git ~/projects/docker_moodle ``` -2. Clone Moodle code into siteroot +2. Set environment variable PROJECTS_DIR to where all your moodle projects are stored (including just cloned docker_moodle) ``` -cd docker_moodle -git clone git@github.com:moodle/moodle.git siteroot + echo "export PROJECTS_DIR=/home/dmitriim/projects" >> ~/.bashrc + source ~/.bashrc ``` -3. Copy site config across +2. Symlink control file to your /usr/local/bin/control ``` -cp moodle-config siteroot/config.php +sudo ln -s ~/project/docker_moodle/control /usr/local/bin/control +``` + +## Usage + + +1. Clone Moodle code to your to where all your moodle projects are stored (e.g ~/projects) + +``` +git clone git@github.com:moodle/moodle.git ~/projects/moodle +``` + +2. Create project (a name of the project should match the folder where your moodle code is located) + +``` +sudo control create moodle + ``` 4. Start containers ``` -docker-compose up + control start moodle +``` + +4. Stop containers + +``` + control stop moodle +``` + +4. Delete project + +``` + sudo control delete moodle ``` ## Utility Commands @@ -42,25 +71,25 @@ To change container names, change name in yaml file and control file. Enter web container: ``` -./control web +control web moodle ``` Enter db container: ``` -./control db +control db moodle ``` Enter test database container: ``` -./control testdb +control testdb moodle ``` Restore db locally: ``` -./control dbrestore +control dbrestore moodle ``` ## Running Tests @@ -68,14 +97,13 @@ Restore db locally: To setup the testing environment run: ``` -./control web -composer install +control web moodle php admin/tool/phpunit/cli/init.php ``` To run tests: ``` -./control web -./vendor/bin/phpunit +control web +/vendor/bin/phpunit ``` diff --git a/control b/control index 768ae8c3be0..e1bb32f8583 100755 --- a/control +++ b/control @@ -1,28 +1,161 @@ #! /bin/bash -## Change to directory of where this script is located -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -cd "$DIR" || exit; +projecsdir=$PROJECTS_DIR + +ok="$(tput setaf 2)OK:$(tput sgr0)" +error="$(tput setaf 1)ERROR:$(tput sgr0)" case "$1" in web) - webcont="$(docker-compose ps -q moodle)" + webcont="$(docker ps -q -f name=$2_moodle)" docker exec -ti $webcont bash ;; db) - dbcont="$(docker-compose ps -q db)" + dbcont="$(docker ps -q -f name=$2_db)" docker exec -ti $dbcont psql -U moodle_user moodle ;; testdb) - dbtestcont="$(docker-compose ps -q test-db)" + dbtestcont="$(docker ps -q -f name=$2_test-db)" docker exec -ti $dbtestcont psql -U moodle_user moodle ;; dbrestore) - dbcont="$(docker-compose ps -q db)" - gunzip < $2 | docker exec -i $dbcont psql -U moodle_user postgres + dbcont="$(docker ps -q -f name=$2_db)" + gunzip < $3 | docker exec -i $dbcont psql -U moodle_user postgres + ;; + + start) + export COMPOSE_PROJECT_NAME=$2 + export MOODLE_WWWROOT=$projecsdir/$2 + export MOODLE_NAME=$2 + siteport="$(cat $MOODLE_WWWROOT/~siteport)" + export MOODLE_PORT=$siteport + + cd $projecsdir/docker_moodle + + docker-compose up + ;; + + stop) + export COMPOSE_PROJECT_NAME=$2 + export MOODLE_WWWROOT=$projecsdir/$2 + export MOODLE_NAME=$2 + siteport="$(cat $MOODLE_WWWROOT/~siteport)" + export MOODLE_PORT=$siteport + + cd $projecsdir/docker_moodle + + docker-compose stop + ;; + + create) + if [ "$(whoami)" != 'root' ]; then + echo $error You have no permission to run $0 as non-root user. Use sudo! + exit 1; + fi + + sitehost=$2.docker + siteport="$(shuf -i 500-1000 -n 1)" + + export COMPOSE_PROJECT_NAME=$2 + export MOODLE_WWWROOT=$projecsdir/$2 + export MOODLE_NAME=$2 + export MOODLE_PORT=$siteport + + cd $projecsdir/docker_moodle + + # Backing up exiting config.php + cp $MOODLE_WWWROOT/config.php $MOODLE_WWWROOT/config.php-backup + echo $ok Backed up existing config.php "($MOODLE_WWWROOT/config.php-backup)" + + # Creating a new config.ph from the template. + cp moodle-config $MOODLE_WWWROOT/config.php + echo $ok Created config.php "($MOODLE_WWWROOT/config.php)" + + # Saving the project port. + echo $siteport > $MOODLE_WWWROOT/~siteport + echo $ok Saved the project port "($MOODLE_WWWROOT/~siteport)" + + # Creating a local nginx rule. + if ! echo " + server { + listen 80; + server_name $sitehost; + + location / { + proxy_pass http://localhost:$siteport; + } + } + " > /etc/nginx/sites-available/$sitehost + then + echo $error There is an ERROR creating $sitehost file + exit; + else + echo $ok New nginx site created "(/etc/nginx/sites-available/$sitehost)" + fi + + # Enabling a local nginx site. + if ! ln -s /etc/nginx/sites-available/$sitehost /etc/nginx/sites-enabled/$sitehost + then + echo $error There is an ERROR creating $sitehost symlink + exit; + else + echo $ok New nginx site enabled "(/etc/nginx/sites-enabled/$sitehost)" + fi + + # Add a new host to /etc/hosts. + if ! echo "127.0.0.1 $sitehost" >> /etc/hosts + then + echo $error ERROR: Not able to write in /etc/hosts + exit; + else + echo $ok New host name added to /etc/hosts file "($sitehost)" + fi + + service nginx restart + echo $ok Local Nginx restarted + echo $ok Start your project using $0 start $2. + echo $ok To access the project, navigate to http://$sitehost in your browser. + ;; + + delete) + if [ "$(whoami)" != 'root' ]; then + echo You have no permission to run $0 as non-root user. Use sudo! + exit 1; + fi + + export COMPOSE_PROJECT_NAME=$2 + export MOODLE_WWWROOT=$projecsdir/$2 + export MOODLE_NAME=$2 + + sitehost=$2.docker + siteport="$(cat $MOODLE_WWWROOT/~siteport)" + + export MOODLE_PORT=$siteport + + rm -rf /etc/nginx/sites-available/$sitehost + echo "$ok Deleted nginx site enabled (/etc/nginx/sites-enabled/$sitehost)" + + rm -rf /etc/nginx/sites-enabled/$sitehost + echo $ok New nginx site enabled "(/etc/nginx/sites-enabled/$sitehost)" + + rm $MOODLE_WWWROOT/~siteport + echo $ok New nginx site enabled "(/etc/nginx/sites-enabled/$sitehost)" + + service nginx restart + + sed -i "/$sitehost/d" /etc/hosts + echo $ok Deleted host name from /etc/hosts file "($sitehost)" + + cd $projecsdir/docker_moodle + + echo $ok Removing docker components... + + docker-compose down + docker image rm $2_moodle + echo $ok Project deleted ;; *) diff --git a/docker-compose.yml b/docker-compose.yml index 9b6027e68e6..17d1cfa8b85 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,9 +4,13 @@ services: moodle: build: ./docker/moodle ports: - - "127.0.0.1:80:80" + - "127.0.0.1:${MOODLE_PORT}:80" volumes: - - ./siteroot:/siteroot + - ${MOODLE_WWWROOT}:/var/www/site + environment: + MOODLE_NAME: "${MOODLE_NAME}" + MOODLE_PORT: "${MOODLE_PORT}" + MOODLE_WWWROOT: "${MOODLE_WWWROOT}" db: image: postgres:10.15 environment: diff --git a/docker/moodle/Dockerfile b/docker/moodle/Dockerfile index 7096385f6d4..be46709de9a 100644 --- a/docker/moodle/Dockerfile +++ b/docker/moodle/Dockerfile @@ -40,10 +40,11 @@ COPY nginx-site /etc/nginx/sites-available/default COPY nginx.conf /etc/nginx/nginx.conf COPY xdebug.ini /etc/php/7.4/mods-available/xdebug.ini COPY php.ini /etc/php/7.4/fpm/php.ini +COPY custom-php-fpm.conf /etc/php/7.4/fpm/pool.d/custom-php-fpm.conf COPY entrypoint.sh / RUN chmod +x /entrypoint.sh -WORKDIR /siteroot +WORKDIR /var/www/site ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/docker/moodle/custom-php-fpm.conf b/docker/moodle/custom-php-fpm.conf new file mode 100644 index 00000000000..d873b954928 --- /dev/null +++ b/docker/moodle/custom-php-fpm.conf @@ -0,0 +1,2 @@ +[www] +clear_env = no diff --git a/docker/moodle/entrypoint.sh b/docker/moodle/entrypoint.sh index ef28cfbf8ae..5e7b7c4b42c 100644 --- a/docker/moodle/entrypoint.sh +++ b/docker/moodle/entrypoint.sh @@ -1,5 +1,7 @@ #!/bin/bash +echo "env[MOODLE_NAME] = ${MOODLE_NAME}" >> /etc/php/7.4/fpm/pool.d/custom-php-fpm.conf + service php7.4-fpm start exec "nginx" \ No newline at end of file diff --git a/docker/moodle/nginx-site b/docker/moodle/nginx-site index 7624ebae560..5a4d152e3f4 100644 --- a/docker/moodle/nginx-site +++ b/docker/moodle/nginx-site @@ -1,7 +1,7 @@ server { listen 80 default_server; - root /siteroot; + root /var/www/site; index index.php index.html index.htm; diff --git a/docker/moodle/php.ini b/docker/moodle/php.ini index 6552ce8565a..3c8e24abffb 100644 --- a/docker/moodle/php.ini +++ b/docker/moodle/php.ini @@ -640,7 +640,7 @@ report_memleaks = On ; Development Value: "GPCS" ; Production Value: "GPCS"; ; http://php.net/variables-order -variables_order = "GPCS" +variables_order = "EGPCS" ; This directive determines which super global data (G,P & C) should be ; registered into the super global array REQUEST. If so, it also determines diff --git a/docker/moodle/xdebug.ini b/docker/moodle/xdebug.ini index 4a5c3180556..9b1832a0cb0 100644 --- a/docker/moodle/xdebug.ini +++ b/docker/moodle/xdebug.ini @@ -1,6 +1,6 @@ zend_extension=xdebug.so xdebug.remote_handler=dbgp -xdebug.remote_port=9000 +xdebug.remote_port=9003 xdebug.remote_autostart=1 xdebug.remote_enable=1 xdebug.remote_connect_back=1 diff --git a/moodle-config b/moodle-config index 689ac248819..37b787e8a65 100644 --- a/moodle-config +++ b/moodle-config @@ -26,7 +26,10 @@ $CFG->phpunit_dbpass = 'password'; $CFG->phpunit_prefix = 'phpu_'; $CFG->phpunit_dataroot = '/var/lib/testsitedata'; -$CFG->wwwroot = 'http://localhost'; +$name = getenv('MOODLE_NAME'); + +$CFG->wwwroot = "http://{$name}.docker"; +$CFG->reverseproxy = true; $CFG->dataroot = '/var/lib/sitedata'; From c216e1b10aeb5d856e2f8f73a2b42f81b28aa3e8 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Fri, 16 Jul 2021 15:52:39 +1000 Subject: [PATCH 02/11] Fix an issues in docs when root didn't get --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index c39f6ac7528..48909c477ec 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ git clone git@github.com:catalyst/docker_moodle.git ~/projects/docker_moodle 2. Set environment variable PROJECTS_DIR to where all your moodle projects are stored (including just cloned docker_moodle) +``` +sudo bash -c 'echo "PROJECTS_DIR=/home/dmitriim/projects" >> /etc/environment' + +``` + ``` echo "export PROJECTS_DIR=/home/dmitriim/projects" >> ~/.bashrc source ~/.bashrc From 97544d413463ba8c718aebad6dc0c46345b6277f Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Fri, 16 Jul 2021 16:01:49 +1000 Subject: [PATCH 03/11] Use file that ignored by git ofr storing project port --- control | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/control b/control index e1bb32f8583..778143e87e7 100755 --- a/control +++ b/control @@ -30,7 +30,7 @@ case "$1" in export COMPOSE_PROJECT_NAME=$2 export MOODLE_WWWROOT=$projecsdir/$2 export MOODLE_NAME=$2 - siteport="$(cat $MOODLE_WWWROOT/~siteport)" + siteport="$(cat $MOODLE_WWWROOT/siteport~)" export MOODLE_PORT=$siteport cd $projecsdir/docker_moodle @@ -42,7 +42,7 @@ case "$1" in export COMPOSE_PROJECT_NAME=$2 export MOODLE_WWWROOT=$projecsdir/$2 export MOODLE_NAME=$2 - siteport="$(cat $MOODLE_WWWROOT/~siteport)" + siteport="$(cat $MOODLE_WWWROOT/siteport~)" export MOODLE_PORT=$siteport cd $projecsdir/docker_moodle @@ -75,8 +75,8 @@ case "$1" in echo $ok Created config.php "($MOODLE_WWWROOT/config.php)" # Saving the project port. - echo $siteport > $MOODLE_WWWROOT/~siteport - echo $ok Saved the project port "($MOODLE_WWWROOT/~siteport)" + echo $siteport > $MOODLE_WWWROOT/siteport~ + echo $ok Saved the project port "($MOODLE_WWWROOT/siteport~)" # Creating a local nginx rule. if ! echo " @@ -131,7 +131,7 @@ case "$1" in export MOODLE_NAME=$2 sitehost=$2.docker - siteport="$(cat $MOODLE_WWWROOT/~siteport)" + siteport="$(cat $MOODLE_WWWROOT/siteport~)" export MOODLE_PORT=$siteport @@ -141,7 +141,7 @@ case "$1" in rm -rf /etc/nginx/sites-enabled/$sitehost echo $ok New nginx site enabled "(/etc/nginx/sites-enabled/$sitehost)" - rm $MOODLE_WWWROOT/~siteport + rm $MOODLE_WWWROOT/siteport~ echo $ok New nginx site enabled "(/etc/nginx/sites-enabled/$sitehost)" service nginx restart @@ -149,7 +149,7 @@ case "$1" in sed -i "/$sitehost/d" /etc/hosts echo $ok Deleted host name from /etc/hosts file "($sitehost)" - cd $projecsdir/docker_moodle + cd "$projecsdir/docker_moodle" echo $ok Removing docker components... From 495f2d6632b586d2576ef9c6cd038c4e02ca261c Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Mon, 19 Jul 2021 21:42:05 +1000 Subject: [PATCH 04/11] Fix a bug in restore control command --- control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control b/control index 778143e87e7..c0ce9554f4d 100755 --- a/control +++ b/control @@ -23,7 +23,7 @@ case "$1" in dbrestore) dbcont="$(docker ps -q -f name=$2_db)" - gunzip < $3 | docker exec -i $dbcont psql -U moodle_user postgres + gunzip < $3 | docker exec -i $dbcont psql -U moodle_user moodle ;; start) From 910611fee7cf97d836cd8fc1756381f66007a14d Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Mon, 19 Jul 2021 21:45:43 +1000 Subject: [PATCH 05/11] Add note about local nginx set up --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 48909c477ec..070d5b9cccc 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,20 @@ sudo bash -c 'echo "PROJECTS_DIR=/home/dmitriim/projects" >> /etc/environment' sudo ln -s ~/project/docker_moodle/control /usr/local/bin/control ``` +3. Make ure that you local nginx server got client_max_body_size set to 8000M + +``` +sudo vi /etc/nginx/nginx.conf +``` + +``` +http { +... + client_max_body_size 8000M; +... + +} +``` ## Usage From 618e08422c1f545513abbfc83de1c7c0e9b13617 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Mon, 19 Jul 2021 22:21:56 +1000 Subject: [PATCH 06/11] Add chromium-browser --- docker/moodle/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/moodle/Dockerfile b/docker/moodle/Dockerfile index be46709de9a..a505ab64d7a 100644 --- a/docker/moodle/Dockerfile +++ b/docker/moodle/Dockerfile @@ -25,7 +25,8 @@ RUN apt-get update -y \ php-xml \ php-xmlrpc \ php-zip \ - vim + vim\ + chromium-browser RUN locale-gen en_AU.UTF-8 From e7e3f585bf305f8bd6e342d978892ac250511a0f Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Tue, 20 Jul 2021 18:57:38 +1000 Subject: [PATCH 07/11] Fix issue in docs with running tests --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 070d5b9cccc..b17a6c35633 100644 --- a/README.md +++ b/README.md @@ -124,5 +124,5 @@ To run tests: ``` control web -/vendor/bin/phpunit +./vendor/bin/phpunit ``` From 18d0d2a70a0c9210bbed4f73b1c1049b5fd423c3 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Thu, 22 Jul 2021 15:57:31 +1000 Subject: [PATCH 08/11] Add maihog support --- README.md | 22 +++++++++++++++++++--- docker-compose.yml | 1 + docker/moodle/entrypoint.sh | 1 + moodle-config | 7 ++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b17a6c35633..f091f12b898 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,24 @@ http { } ``` -## Usage +4. Start mailhog locally (it will be used for all your instances). Note: 192.168.56.1 is your local instance IP address. MailHog will be available on http://192.168.56.1:8025 + + +``` +docker run --detach --name=mailhog --publish=192.168.56.1:8025:8025 --publish=192.168.56.1:1025:1025 --restart=unless-stopped mailhog/mailhog +``` + +``` +sudo bash -c 'echo "MOODLE_MAIL_HOST=192.168.56.1" >> /etc/environment' +``` + +``` + echo "export MOODLE_MAIL_HOST=192.168.56.1" >> ~/.bashrc + source ~/.bashrc +``` + +## Usage 1. Clone Moodle code to your to where all your moodle projects are stored (e.g ~/projects) @@ -68,13 +84,13 @@ sudo control create moodle control start moodle ``` -4. Stop containers +5. Stop containers ``` control stop moodle ``` -4. Delete project +6. Delete project ``` sudo control delete moodle diff --git a/docker-compose.yml b/docker-compose.yml index 17d1cfa8b85..c1f7c6034a2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: MOODLE_NAME: "${MOODLE_NAME}" MOODLE_PORT: "${MOODLE_PORT}" MOODLE_WWWROOT: "${MOODLE_WWWROOT}" + MOODLE_MAIL_HOST: "${MOODLE_MAIL_HOST}" db: image: postgres:10.15 environment: diff --git a/docker/moodle/entrypoint.sh b/docker/moodle/entrypoint.sh index 5e7b7c4b42c..fa2e01a4e98 100644 --- a/docker/moodle/entrypoint.sh +++ b/docker/moodle/entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/bash echo "env[MOODLE_NAME] = ${MOODLE_NAME}" >> /etc/php/7.4/fpm/pool.d/custom-php-fpm.conf +echo "env[MOODLE_MAIL_HOST] = ${MOODLE_MAIL_HOST}" >> /etc/php/7.4/fpm/pool.d/custom-php-fpm.conf service php7.4-fpm start diff --git a/moodle-config b/moodle-config index 37b787e8a65..a920f2f6736 100644 --- a/moodle-config +++ b/moodle-config @@ -39,7 +39,12 @@ $CFG->admin = 'admin'; @error_reporting(E_ALL | E_STRICT); // NOT FOR PRODUCTION SERVERS! $CFG->debug = (E_ALL | E_STRICT); // === DEBUG_DEVELOPER - NOT FOR PRODUCTION SERVERS! -$CFG->noemailever = true; +$mailhost = getenv('MOODLE_MAIL_HOST'); +if (!empty($mailhost)) { + $CFG->smtphosts = $mailhost . ':1025'; +} else { + $CFG->noemailever = true; +} $CFG->directorypermissions = 0777; From 91816b4e1a9e12b738e2cf60378610e2a4b4aaa0 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Thu, 22 Jul 2021 15:58:37 +1000 Subject: [PATCH 09/11] Update README.md to make it clear about Nginx --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f091f12b898..6402071b830 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ - Docker - Docker-compose -- Nginx +- Nginx installed locally ## Set up From d359732ccdf3817c9a342dcc28308aac3822585b Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Thu, 22 Jul 2021 16:01:33 +1000 Subject: [PATCH 10/11] Clean up of README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6402071b830..1449dccb769 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,11 @@ git clone git@github.com:catalyst/docker_moodle.git ~/projects/docker_moodle ``` sudo bash -c 'echo "PROJECTS_DIR=/home/dmitriim/projects" >> /etc/environment' - ``` ``` - echo "export PROJECTS_DIR=/home/dmitriim/projects" >> ~/.bashrc - source ~/.bashrc +echo "export PROJECTS_DIR=/home/dmitriim/projects" >> ~/.bashrc +source ~/.bashrc ``` 2. Symlink control file to your /usr/local/bin/control @@ -41,14 +40,14 @@ sudo vi /etc/nginx/nginx.conf ``` http { ... - client_max_body_size 8000M; + client_max_body_size 8000M; ... } ``` -4. Start mailhog locally (it will be used for all your instances). Note: 192.168.56.1 is your local instance IP address. MailHog will be available on http://192.168.56.1:8025 - +4. Set up MailHog locally (it will be used for all your instances). Note: 192.168.56.1 is your local IP address, + and it should be available from your docker containers. ``` docker run --detach --name=mailhog --publish=192.168.56.1:8025:8025 --publish=192.168.56.1:1025:1025 --restart=unless-stopped mailhog/mailhog @@ -59,10 +58,12 @@ sudo bash -c 'echo "MOODLE_MAIL_HOST=192.168.56.1" >> /etc/environment' ``` ``` - echo "export MOODLE_MAIL_HOST=192.168.56.1" >> ~/.bashrc - source ~/.bashrc +echo "export MOODLE_MAIL_HOST=192.168.56.1" >> ~/.bashrc +source ~/.bashrc ``` +MailHog UI will be available on http://192.168.56.1:8025 + ## Usage 1. Clone Moodle code to your to where all your moodle projects are stored (e.g ~/projects) @@ -75,7 +76,6 @@ git clone git@github.com:moodle/moodle.git ~/projects/moodle ``` sudo control create moodle - ``` 4. Start containers From ccabd0c89e14de99ffc19291e0ae13611912da3d Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Fri, 22 Oct 2021 17:41:31 +1100 Subject: [PATCH 11/11] Add backup control command --- control | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/control b/control index c0ce9554f4d..f520b70080d 100755 --- a/control +++ b/control @@ -26,6 +26,13 @@ case "$1" in gunzip < $3 | docker exec -i $dbcont psql -U moodle_user moodle ;; + dbbackup) + backupfile=$projecsdir/$2-moodle.sql.gz + dbcont="$(docker ps -q -f name=$2_db)" + docker exec -i $dbcont pg_dump -U moodle_user moodle | gzip > $backupfile + echo Backup file is avaliable here $backupfile + ;; + start) export COMPOSE_PROJECT_NAME=$2 export MOODLE_WWWROOT=$projecsdir/$2