Skip to content

Use .env file for directory/db #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Set up path to Moodle code
MOODLE_DOCKER_WWWROOT=/path/to/moodle/code
# Choose a db server (Currently supported: pgsql, mariadb, mysql, mssql, oracle)
MOODLE_DOCKER_DB=pgsql

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need an export before them if you want to source them from the scripts. dotenv files like you know them from php, python etc will not work with shells.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
27 changes: 11 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,22 @@ 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
1. Download or clone this repository
2. Rename `.env.example` to `.env`
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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to me like a more complicated setup than what was here previously.

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`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have to -> You should (at least to my knowledge you always want to do this if you execute these commands directly after each other)


# Ensure customized config.php for the Docker containers is in place
cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still seems necessary for someone to quick start?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoups your right. I added a create-moodle-config script and updated the readme in the latest commit.

You can now access Moodle under `localhost:8000`.

# Start up containers
bin/moodle-docker-compose up -d
If you want to destroy the container, run `bin/moodle-docker-compose down`.

# Wait for DB to come up (important for oracle/mssql)
bin/moodle-docker-wait-for-db

# Work with the containers (see below)
# [..]
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`).

# Shut down and destroy containers
bin/moodle-docker-compose down
```

## Use containers for running behat tests

Expand Down
10 changes: 10 additions & 0 deletions bin/create-moodle-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

if [ -f .env ];
then
source .env

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work as the variables are not exported (at least inside you sample env file)
Also applies to all following uses of source .env

fi

cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php


5 changes: 5 additions & 0 deletions bin/moodle-docker-compose
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env bash
set -e

if [ -f .env ];
then
source .env
fi

if [ ! -d "$MOODLE_DOCKER_WWWROOT" ];
then
echo 'Error: $MOODLE_DOCKER_WWWROOT is not set or not an existing directory'
Expand Down
5 changes: 5 additions & 0 deletions bin/moodle-docker-wait-for-db
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env bash
set -e

if [ -f .env ];
then
source .env
fi

basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"

if [ -z "$MOODLE_DOCKER_DB" ];
Expand Down