Skip to content
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

Add support for reading a .env file #249

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This is an example environment file for Moodle Docker.
# This file is in the POSIX format and intended to be read by shdotenv.
# Documentation for this file format can be found at the following location:
# https://github.com/ko1nksm/shdotenv/blob/main/docs/specification.md

# This shouold be an absolute path to your Moodle source directory.
MOODLE_DOCKER_WWWROOT=/absolute/path/to/Moodle/on/host

# The port number for web.
MOODLE_DOCKER_WEB_PORT=1234

# The database server type to use.
# Valid options are pgsql, mysql, mariadb, oci, sqlsrv.
MOODLE_DOCKER_DB=pgsql

# The database credentials to use.
MOODLE_DOCKER_DBNAME=moodle
MOODLE_DOCKER_DBUSER=moodle
MOODLE_DOCKER_DBPASS="m@0dl3ing"

# The browser environment to bring up for any Behat tests
MOODLE_DOCKER_BROWSER=firefox
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
local.yml
.env
shdotenv
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ bin/moodle-docker-wait-for-db
# Shut down and destroy containers
bin/moodle-docker-compose down
```

## Configuration

If you are running a *nix-like OS such as Linux, or MacOS, then you can provide a local `.env` file to setup your default environment. This file only provides _default_ configuration for any environment variable not already set in your environment. If you wish to override a setting from the default you can do so in the normal way using an export command.

An example environment file is provided in [`.env.example`](https://github.com/moodlehq/moodle-docker/master/blob/.env.example).

Environment file configuration is loaded using [shdotenv](https://github.com/ko1nksm/shdotenv) and the `.env` file should be in the [POSIX dialect](https://github.com/ko1nksm/shdotenv/blob/main/docs/specification.md).

Please note that this file _should not_ be added to your git repository. It is intended to contain your _local_ default configuration.

## Run several Moodle instances

By default, the script will load a single instance. If you want to run two
Expand Down
13 changes: 13 additions & 0 deletions bin/moodle-docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ set -e
thisfile=$( readlink "${BASH_SOURCE[0]}" ) || thisfile="${BASH_SOURCE[0]}"
basedir="$( cd "$( dirname "$thisfile" )/../" && pwd -P )"

# Check for an environent file, and import it if found.
ENVFILE="${basedir}/.env"
if [ -f "$ENVFILE" ]
then
SHDOTENV="${basedir}/shdotenv"
if [ ! -f "${SHDOTENV}" ]
then
curl https://github.com/ko1nksm/shdotenv/releases/latest/download/shdotenv -L -o "${SHDOTENV}"
chmod +x "${SHDOTENV}"
fi
eval "$(./shdotenv || echo "exit $?")"
fi

if [ ! -d "$MOODLE_DOCKER_WWWROOT" ];
then
echo 'Error: $MOODLE_DOCKER_WWWROOT is not set or not an existing directory'
Expand Down