Skip to content

A docker setup to create a development environment for Totara Learn

Notifications You must be signed in to change notification settings

samanthajayasinghe/totara-docker-dev

 
 

Repository files navigation

Container versions and build status:

Name Version Dockerfile Build
nginx 1.13.x Dockerfile Build status Nginx
php54 5.4 Dockerfile Build status PHP 5.4
php54-debug 5.4 + xdebug 2.4.1 Dockerfile Build status PHP 5.4 Debug
php55 5.5 Dockerfile Build status PHP 5.5
php55-debug 5.5 + xdebug 2.5.5 Dockerfile Build status PHP 5.5 Debug
php56 5.6 Dockerfile Build status PHP 5.6
php56-debug 5.6 + xdebug 2.5.5 Dockerfile Build status PHP 5.6 Debug
php70 7.0 Dockerfile Build status PHP 7.0
php70-debug 7.0 + xdebug 2.6.0 Dockerfile Build status PHP 7.0 Debug
php71 7.1 Dockerfile Build status PHP 7.1
php71-debug 7.1 + xdebug 2.6.0 Dockerfile Build status PHP 7.1 Debug
php72 7.2 Dockerfile Build status PHP 7.2
php72-debug 7.2 + xdebug 2.6.0 Dockerfile Build status PHP 7.2 Debug

A Docker setup for local Totara Learn development

This project aims to provide an easy way to start developing for Totara by providing a Docker setup.

This setup was created and tested intensively on a MAC and Linux. It works on Windows as well but wasn't tested that much yet.

Although this project started as a development environment for Totara Learn it can be used for any other PHP project.

What you get:

Requirements:

Warning Docker for Mac

Please note that there's a current issue with docker-sync on Mac and Docker stable versions newer than 17.09.1-ce-mac42. To be on the safe side I recommend to download and installing this version. In the edge version 18.05.0-ce-mac67 and newer the issue seem to be fixed as well.

Installation:

  1. Clone the Totara source code (see requirements)
  2. Clone this project
  3. Install docker-sync (optionally, recommended for MAC)
  4. Copy the file .env.dist to .env and change at least the path to your local Totara source folder (LOCAL_SRC)

/etc/hosts

Make sure you have all the hosts in your /etc/hosts file to be able to access them via the browser.

Example:

127.0.0.1   localhost totara54 totara54.behat totara55 totara55.behat totara56 totara56.behat totara70 totara70.behat totara71 totara71.behat totara72 totara72.behat

Shortcut commands

This project comes with a few bash scripts to simplify usage accross platforms. The scripts are located in the bin/ folder. Ideally you add the bin folder to your PATH environment variable so you can run the commands from anywhere.

tdocker                           # shortcut to general docker-compose ... command
tup [containers]                  # start (all) container(s)            
tbash [container]                 # log into a container, i.e. php-7.2
tstop [container]                 # stop (all) container(s)
trestart [container]              # restart (all) container(s)
tdown                             # shutdown all containers
tstats                            # show docker stats including container names
tbuild [container]                # build (all) container(s)
tgrunt [subfolder]                # run grunt scripts in container, if you use subfolders for version pass it as 2nd argument
tscale [container]=6              # scale up the number of containers, i.e. selenium-chrome
tunit [container] [folder] [init] # run or init unit tests in given container for given version

Run

# if you use docker-sync, fire up docker-sync as a daemon in the background
docker-sync start
# start all containers in background
tup
# to limit the amount of containers fired up
# you can just start the db and php container of your choice,
# it automatically starts nginx container as well
tup pgsql php-7.2
# if you later need to access any other php container 
# just start it with
tup php-5.6

Build

By default prebuilt images from docker hub (https://hub.docker.com/u/derschatta/) will be used. If you want to modify any of the containers to your needs then you can rebuild them locally with the following command:

tbuild
# or for individual images
tbuild php-7.2

Config & Database

Make sure you have configured Totara and created the databases you need. You can connect to the databases from your host using any tools you prefer (host = localhost, use defautls ports).

Credentials

DB Host User Password
PostresSQL 10.x pgsql postresql
PostresSQL 9.3.x pgsql93 postresql
Mysql mysql root root
MariaDB mariadb root root
Mssql mssql SA Totara.Mssql1

To use the command line clients provided by the containers you can use the following commands:

# PostgreSQL
tdocker exec pgsql psql -U postgres

# MySQL / MariaDB
tdocker exec mysql mysql -u root -p"root"
tdocker exec mariadb mysql -u root -p"root"

# Microsoft SQL Server
tdocker exec php-7.1 /opt/mssql-tools/bin/sqlcmd -S mssql -U SA -P "Totara.Mssql1"

Create a database schema for each Totara version you would like to develop on.

data directories

The nginx container automatically creates all required data folders.

/var/www/totara/data/ver[versionnumber].[database]
/var/www/totara/data/ver[versionnumber].[database].phpunit
/var/www/totara/data/ver[versionnumber].[database].behat
# example
/var/www/totara/data/ver11.pgsql
/var/www/totara/data/ver11.pgsql.phpunit
/var/www/totara/data/ver11.pgsql.behat

versionnumber = 22, 24, 25, 26, 27, 29, 9, 10, 11, 12 database = pgsql, mysql, mssql

Config example

This is an example for the t11 branch with the 3 different databases and the correct data directories. Please note: You will need additional configuration parameters for PHPUnit and Behat. Please refer to Totara docs and have a look at config-dist.php for examples.

//=========================================================================
// 1. DATABASE SETUP
//=========================================================================
// First, you need to configure the database where all Moodle data       //
// will be stored.  This database must already have been created         //
// and a username/password created to access it.                         //


//$CFG->dbtype    = 'mysqli';
//$CFG->dbhost    = 'mysql';  // eg 'localhost' or 'db.isp.com' or IP
//$CFG->dbuser    = 'root';   // your database username
//$CFG->dbpass    = 'root';   // your database password
//$CFG->dataroot  = '/var/www/totara/data/ver11.mysql';
//$CFG->behat_dataroot = '/var/www/totara/data/ver11.mysql.behat';
//$CFG->phpunit_dataroot = '/var/www/totara/data/ver11.mysql.phpunit';

//$CFG->dbtype    = 'sqlsrv';
//$CFG->dbhost    = 'mssql';  // eg 'localhost' or 'db.isp.com' or IP
//$CFG->dbuser    = 'SA';   // your database username
//$CFG->dbpass    = 'Totara.Mssql1';   // your database password
//$CFG->dataroot  = '/var/www/totara/data/ver11.mssql';
//$CFG->behat_dataroot = '/var/www/totara/data/ver11.mssql.behat';
//$CFG->phpunit_dataroot = '/var/www/totara/data/ver11.mssql.phpunit';

$CFG->dbtype    = 'pgsql';      // 'pgsql', 'mariadb', 'mysqli', 'mssql', 'sqlsrv'
$CFG->dbhost    = 'pgsql';  // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbuser    = 'postgres';   // your database username
$CFG->dbpass    = '';   // your database password
$CFG->dataroot  = '/var/www/totara/data/ver11.pgsql';
$CFG->behat_dataroot = '/var/www/totara/data/ver11.pgsql.behat';
$CFG->phpunit_dataroot = '/var/www/totara/data/ver11.pgsql.phpunit';


$CFG->dblibrary = 'native';     // 'native' only at the moment
$CFG->dbname    = 'totara_11';     // database name, eg moodle
$CFG->prefix    = 'mdl_';       // prefix to use for all table names
$CFG->dboptions = array(
    'dbpersist' => false,       // should persistent database connections be
                                //  used? set to 'false' for the most stable
                                //  setting, 'true' can improve performance
                                //  sometimes
    'dbsocket'  => false,       // should connection via UNIX socket be used?
                                //  if you set it to 'true' or custom path
                                //  here set dbhost to 'localhost',
                                //  (please note mysql is always using socket
                                //  if dbhost is 'localhost' - if you need
                                //  local port connection use '127.0.0.1')
    'dbport'    => '',          // the TCP port number to use when connecting
                                //  to the server. keep empty string for the
                                //  default port
);

Run unit tests

Make sure your config file contains the PHPUnit configuration needed and the database is ready.

Initiate:

# assuming you have a subfolder called 11 then you can call
# to initiate the unit tests
tunit php-7.1 11 init

Run:

# run all unit tests in given container for version
tunit php-7.1 11
# or add more phpunit params
tunit php-7.1 11 --test-suffix=_test.php relative/path/to/tests/

Run behat tests

Make sure your config file contains the Behat configuration needed and the database is ready.

Log into one of the test containers

tbash php-5.6
tbash php-7.1
# or if you need xdebug support
tbash php-5.6-debug
tbash php-7.1-debug

Go to the project folder

# replace version
cd /var/www/totara/src/[version]

If needed run the init script to initiate the behat tests

# in the project folder
php composer.phar install
# initiate the test environment (use --parallel=x if needed)
php admin/tool/behat/cli/init.php

To start running

# for t11
vendor/bin/behat
# for others use the command prompted after init, for example:
vendor/bin/behat --config /var/www/totara/data/ver9.pgsql.behat/behatrun/behat/behat.yml

Switch between different versions

I recommend to check out each Totara Learn version in a different subfolder below the folder LOCAL_SRC defined in .env. This is just a suggestion which worked fine for me. There are different ways to handle this and at the end you need to decide yourself how to do it.

Mailcatcher

The setup comes with mailcatcher support. Just add the following to your config and all mails will be sent to it:

$CFG->smtphosts = 'mailcatcher:25';

Open http://localhost:8080 to open the mailcatcher GUI.

If needed, modify the local port in the docker-compose.yml file.

NodeJS, NPM and grunt

If you want to use grunt or npm you can log into the nodejs container and issue the commands there:

tdocker run nodejs bash
# go to your source directory and
npm install
npm install grunt-cli
./node_modules/.bin/grunt

Or you use the shortcut bash script:

tgrunt
tgrunt 12

About

A docker setup to create a development environment for Totara Learn

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dockerfile 80.7%
  • Shell 19.3%