From 0f4d980c7608d79aa253bbaff6d48704d8bf51a4 Mon Sep 17 00:00:00 2001 From: Adam Nielsen <1765602+iwasherefirst2@users.noreply.github.com> Date: Wed, 24 Jun 2020 00:53:01 +0200 Subject: [PATCH 1/6] Use .env file for directory/db Using an environment file for directory/db has the advantage that the user does not need to specify the variables after each reboot. Added `.env` to gitignore list, to avoid that envirenment variables end up in repository. Created `moodle-start` for convenience. Imroved new readme. Closes #80 Closes #81 --- .env.example | 4 ++++ .gitignore | 1 + README.md | 24 ++++++------------------ bin/moodle-docker-compose | 2 ++ bin/moodle-docker-wait-for-db | 2 ++ bin/moodle-start | 4 ++++ 6 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 .env.example create mode 100644 .gitignore create mode 100755 bin/moodle-start diff --git a/.env.example b/.env.example new file mode 100644 index 00000000000..d1e5afb7073 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +# Set up path to Moodle code +export MOODLE_DOCKER_WWWROOT=/path/to/moodle/code +# Choose a db server (Currently supported: pgsql, mariadb, mysql, mssql, oracle) +export MOODLE_DOCKER_DB=pgsql diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..4c49bd78f1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/README.md b/README.md index 757c9837a0b..4734bd32c8a 100755 --- a/README.md +++ b/README.md @@ -18,27 +18,15 @@ This repository contains Docker configuration aimed at Moodle developers and tes ## Quick start -```bash -# Set up path to Moodle code -export MOODLE_DOCKER_WWWROOT=/path/to/moodle/code -# Choose a db server (Currently supported: pgsql, mariadb, mysql, mssql, oracle) -export MOODLE_DOCKER_DB=pgsql - -# Ensure customized config.php for the Docker containers is in place -cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php +1. Download or clone this repository +2. Rename `.env.example` to `.env` +3. Specify Moodle directory and db driver in `.env` +4. Run `bin/moodle-run` inside `moodle-docker` folder -# Start up containers -bin/moodle-docker-compose up -d +You can now access Moodle under `localhost:8000`. -# Wait for DB to come up (important for oracle/mssql) -bin/moodle-docker-wait-for-db +If you want to destroy the container, run `bin/moodle-docker-compose down`. -# Work with the containers (see below) -# [..] - -# Shut down and destroy containers -bin/moodle-docker-compose down -``` ## Use containers for running behat tests diff --git a/bin/moodle-docker-compose b/bin/moodle-docker-compose index fd7bdafc897..30b9fa9083f 100755 --- a/bin/moodle-docker-compose +++ b/bin/moodle-docker-compose @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -e +source .env + if [ ! -d "$MOODLE_DOCKER_WWWROOT" ]; then echo 'Error: $MOODLE_DOCKER_WWWROOT is not set or not an existing directory' diff --git a/bin/moodle-docker-wait-for-db b/bin/moodle-docker-wait-for-db index 9fb25a553ae..e5a1d2038f8 100755 --- a/bin/moodle-docker-wait-for-db +++ b/bin/moodle-docker-wait-for-db @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -e +source .env + basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )" if [ -z "$MOODLE_DOCKER_DB" ]; diff --git a/bin/moodle-start b/bin/moodle-start new file mode 100755 index 00000000000..18ff5eabd76 --- /dev/null +++ b/bin/moodle-start @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +bin/moodle-docker-compose up -d +bin/moodle-docker-wait-for-db From 20c16cd7dd2e13c66b7b92d2c480bbb60da62449 Mon Sep 17 00:00:00 2001 From: Adam Nielsen <1765602+iwasherefirst2@users.noreply.github.com> Date: Wed, 24 Jun 2020 07:29:10 +0200 Subject: [PATCH 2/6] Remove export key from env-example --- .env.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index d1e5afb7073..afcb91dbbc4 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ # Set up path to Moodle code -export MOODLE_DOCKER_WWWROOT=/path/to/moodle/code +MOODLE_DOCKER_WWWROOT=/path/to/moodle/code # Choose a db server (Currently supported: pgsql, mariadb, mysql, mssql, oracle) -export MOODLE_DOCKER_DB=pgsql +MOODLE_DOCKER_DB=pgsql From f7dad4fb576661a080585eb0aeeb7106af4613a9 Mon Sep 17 00:00:00 2001 From: Adam Nielsen <1765602+iwasherefirst2@users.noreply.github.com> Date: Wed, 24 Jun 2020 07:34:59 +0200 Subject: [PATCH 3/6] Add create-moodle-config script --- README.md | 4 +++- bin/create-moodle-config | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100755 bin/create-moodle-config diff --git a/README.md b/README.md index 4734bd32c8a..6edc9588b36 100755 --- a/README.md +++ b/README.md @@ -21,7 +21,9 @@ This repository contains Docker configuration aimed at Moodle developers and tes 1. Download or clone this repository 2. Rename `.env.example` to `.env` 3. Specify Moodle directory and db driver in `.env` -4. Run `bin/moodle-run` inside `moodle-docker` folder +4. Run `bin/create-moodle-config`. This copies the `config.php` into Moodle. +You only have to call this command onces. +4. Run `bin/moodle-run` inside `moodle-docker` folder to create the container. You can now access Moodle under `localhost:8000`. diff --git a/bin/create-moodle-config b/bin/create-moodle-config new file mode 100755 index 00000000000..bb6ac6ad818 --- /dev/null +++ b/bin/create-moodle-config @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +source .env + +cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php + + From 200981f3789d826bd2c84980cc2f0c62e67dd131 Mon Sep 17 00:00:00 2001 From: Adam Nielsen <1765602+iwasherefirst2@users.noreply.github.com> Date: Wed, 24 Jun 2020 07:42:00 +0200 Subject: [PATCH 4/6] Remove unprecise-named script --- README.md | 7 ++++++- bin/moodle-start | 4 ---- 2 files changed, 6 insertions(+), 5 deletions(-) delete mode 100755 bin/moodle-start diff --git a/README.md b/README.md index 6edc9588b36..9c43d88e02f 100755 --- a/README.md +++ b/README.md @@ -23,13 +23,18 @@ This repository contains Docker configuration aimed at Moodle developers and tes 3. Specify Moodle directory and db driver in `.env` 4. Run `bin/create-moodle-config`. This copies the `config.php` into Moodle. You only have to call this command onces. -4. Run `bin/moodle-run` inside `moodle-docker` folder to create the container. +4. Run `bin/moodle-docker-compose up -d` inside `moodle-docker` folder to create the container. +5. You may have to call also `bin/moodle-docker-wait-for-db` if you use `oracle/mssql`. You can now access Moodle under `localhost:8000`. If you want to destroy the container, run `bin/moodle-docker-compose down`. +Everytime you reboot your PC or destroyed the container, you just have to start the container with `bin/moodle-docker-compose up -d` +(and with `bin/moodle-docker-wait-for-db` if you use `oracle/mssql`). + + ## Use containers for running behat tests ```bash diff --git a/bin/moodle-start b/bin/moodle-start deleted file mode 100755 index 18ff5eabd76..00000000000 --- a/bin/moodle-start +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -bin/moodle-docker-compose up -d -bin/moodle-docker-wait-for-db From 5aa57aeec406c00a5ac4026c2a3b0c8898090e6e Mon Sep 17 00:00:00 2001 From: Adam Nielsen <1765602+iwasherefirst2@users.noreply.github.com> Date: Wed, 24 Jun 2020 07:59:28 +0200 Subject: [PATCH 5/6] Check if .env file exists before sourcing it --- bin/create-moodle-config | 8 +++++++- bin/moodle-docker-compose | 8 +++++++- bin/moodle-docker-wait-for-db | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/bin/create-moodle-config b/bin/create-moodle-config index bb6ac6ad818..f8f19a49d21 100755 --- a/bin/create-moodle-config +++ b/bin/create-moodle-config @@ -1,6 +1,12 @@ #!/usr/bin/env bash -source .env +if [ -f .env ]; +then + source .env +else + echo 'Error: No .env file in current directory.' + exit 1 +fi cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php diff --git a/bin/moodle-docker-compose b/bin/moodle-docker-compose index 30b9fa9083f..3fa948d751f 100755 --- a/bin/moodle-docker-compose +++ b/bin/moodle-docker-compose @@ -1,7 +1,13 @@ #!/usr/bin/env bash set -e -source .env +if [ -f .env ]; +then + source .env +else + echo 'Error: No .env file in current directory.' + exit 1 +fi if [ ! -d "$MOODLE_DOCKER_WWWROOT" ]; then diff --git a/bin/moodle-docker-wait-for-db b/bin/moodle-docker-wait-for-db index e5a1d2038f8..5849833d158 100755 --- a/bin/moodle-docker-wait-for-db +++ b/bin/moodle-docker-wait-for-db @@ -1,7 +1,13 @@ #!/usr/bin/env bash set -e -source .env +if [ -f .env ]; +then + source .env +else + echo 'Error: No .env file in current directory.' + exit 1 +fi basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )" From 25750bf298c7e3287e00a03a19d7422a846d6ea2 Mon Sep 17 00:00:00 2001 From: Adam Nielsen <1765602+iwasherefirst2@users.noreply.github.com> Date: Wed, 24 Jun 2020 08:03:18 +0200 Subject: [PATCH 6/6] Don't throw error if env is missing Let people decide if they want to set the directory path in the terminal instead of the envirenment file. This also should make travis pass the tests. --- bin/create-moodle-config | 3 --- bin/moodle-docker-compose | 3 --- bin/moodle-docker-wait-for-db | 3 --- 3 files changed, 9 deletions(-) diff --git a/bin/create-moodle-config b/bin/create-moodle-config index f8f19a49d21..3b0c7ae175c 100755 --- a/bin/create-moodle-config +++ b/bin/create-moodle-config @@ -3,9 +3,6 @@ if [ -f .env ]; then source .env -else - echo 'Error: No .env file in current directory.' - exit 1 fi cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php diff --git a/bin/moodle-docker-compose b/bin/moodle-docker-compose index 3fa948d751f..6b9523e540b 100755 --- a/bin/moodle-docker-compose +++ b/bin/moodle-docker-compose @@ -4,9 +4,6 @@ set -e if [ -f .env ]; then source .env -else - echo 'Error: No .env file in current directory.' - exit 1 fi if [ ! -d "$MOODLE_DOCKER_WWWROOT" ]; diff --git a/bin/moodle-docker-wait-for-db b/bin/moodle-docker-wait-for-db index 5849833d158..9a42f21eb6a 100755 --- a/bin/moodle-docker-wait-for-db +++ b/bin/moodle-docker-wait-for-db @@ -4,9 +4,6 @@ set -e if [ -f .env ]; then source .env -else - echo 'Error: No .env file in current directory.' - exit 1 fi basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"