Skip to content

Commit

Permalink
Merge branch 'main' into ssat
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesia committed Feb 26, 2025
2 parents 815e8b2 + f0f774f commit 6cc55dd
Show file tree
Hide file tree
Showing 39 changed files with 281 additions and 196 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/auto-author-assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Auto Author Assign

on:
pull_request_target:
types: [ opened, reopened ]

permissions:
pull-requests: write

jobs:
assign-author:
name: Auto assign PR
runs-on: ubuntu-latest
steps:
- uses: toshimaru/auto-author-assign@v2.1.0
101 changes: 60 additions & 41 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,19 @@ tasks:
# Open Moodle site in browser.
gp ports await 8000 && gp preview $(gp url 8000)
# Change permissions to allow installation of plugins.
bin/moodle-docker-compose exec webserver bash -c 'chmod -R 777 .'
# Add some data if the file exists.
if [ -r "moodle/admin/tool/generator/tests/fixtures/gitpod-basic-scenario.feature" ];
then
bin/moodle-docker-compose exec webserver php admin/tool/generator/cli/runtestscenario.php --feature=./../tests/fixtures/gitpod-basic-scenario.feature
fi
command: |
# Update the patch to the latest version.
cd moodle
git fetch
git fetch $(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} | sed 's!/! !')
git reset --hard
cd ..
Expand Down
31 changes: 30 additions & 1 deletion .gitpod/setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,34 @@ then
export MOODLE_BRANCH=main
fi

if [ -z "$CLONEALL" ];
then
FASTCLONE='--depth 1'
else
FASTCLONE=""
fi

# Clone Moodle repository.
cd "${GITPOD_REPO_ROOT}" && git clone --branch "${MOODLE_BRANCH}" --single-branch "${MOODLE_REPOSITORY}" moodle
cd "${GITPOD_REPO_ROOT}" && git clone ${FASTCLONE} --branch "${MOODLE_BRANCH}" --single-branch "${MOODLE_REPOSITORY}" moodle

# Download the data file (if given). It will be used to generate some data.
if [ -n "$DATAFILE" ];
then
wget -O moodle/admin/tool/generator/tests/fixtures/gitpod-basic-scenario.feature "${DATAFILE}"
fi

# Install adminer.
if [ -n "$INSTALLADMINER" ];
then
cat << EOF > local.yml
services:
adminer:
image: adminer:latest
restart: always
ports:
- 8080:8080
depends_on:
- "db"
EOF
fi
40 changes: 30 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# moodle-docker: Docker Containers for Moodle Developers
[![Build Status](https://github.com/moodlehq/moodle-docker/workflows/moodle-docker%20CI/badge.svg?branch=main)](https://github.com/moodlehq/moodle-docker/actions/workflows/ci.yml?query=branch%3Amain)
[![moodle-docker CI](https://github.com/moodlehq/moodle-docker/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/moodlehq/moodle-docker/actions/workflows/ci.yml)

This repository contains Docker configuration aimed at Moodle developers and testers to easily deploy a testing environment for Moodle.

Expand All @@ -14,16 +14,21 @@ This repository contains Docker configuration aimed at Moodle developers and tes

## Prerequisites
* [Docker](https://docs.docker.com) and [Docker Compose](https://docs.docker.com/compose/cli-command/#installing-compose-v2) installed if your Docker CLI version does not support `docker compose` command.
* It's recommended to always run the latest versions of each, but at the minimum Docker v20.10.15 and Docker Compose v2.5.0 should be used.
* 3.25GB of RAM (if you choose [Microsoft SQL Server](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup#prerequisites) as db server)

## Quick start

```bash
# Set up path to Moodle code
export MOODLE_DOCKER_WWWROOT=/path/to/moodle/code
# Change ./moodle to your /path/to/moodle if you already have it checked out
export MOODLE_DOCKER_WWWROOT=./moodle

# Choose a db server (Currently supported: pgsql, mariadb, mysql, mssql, oracle)
export MOODLE_DOCKER_DB=pgsql

# Get Moodle code, you could select another version branch (skip this if you already got the code)
git clone -b MOODLE_403_STABLE git://git.moodle.org/moodle.git $MOODLE_DOCKER_WWWROOT

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

Expand Down Expand Up @@ -141,9 +146,9 @@ In order to run Behat tests for the Moodle App, you need to install the [local_m

The Behat tests will be run against a container serving the mobile application, you have two options here:

1. Use a Docker image that includes the application code. You need to specify the `MOODLE_DOCKER_APP_VERSION` env variable and the [moodlehq/moodleapp](https://hub.docker.com/r/moodlehq/moodleapp) image will be downloaded from Docker Hub. You can read about the available images in [Moodle App Docker Images](https://docs.moodle.org/dev/Moodle_App_Docker_Images) (for Behat, you'll want to run the ones with the `-test` suffix).
1. Use a Docker image that includes the application code. You need to specify the `MOODLE_DOCKER_APP_VERSION` env variable and the [moodlehq/moodleapp](https://hub.docker.com/r/moodlehq/moodleapp) image will be downloaded from Docker Hub. You can read about the available images in [Moodle App Docker Images](https://moodledev.io/general/app/development/setup/docker-images) (for Behat, you'll want to run the ones with the `-test` suffix).

2. Use a local copy of the application code and serve it through Docker, similar to how the Moodle site is being served. Set the `MOODLE_DOCKER_APP_PATH` env variable to the codebase in you file system. This will assume that you've already initialized the app calling `npm install` and `npm run setup` locally.
2. Use a local copy of the application code and serve it through Docker, similar to how the Moodle site is being served. Set the `MOODLE_DOCKER_APP_PATH` env variable to the codebase in you file system. This will assume that you've already initialized the app calling `npm install` locally.

For both options, you also need to set `MOODLE_DOCKER_BROWSER` to "chrome".

Expand Down Expand Up @@ -175,7 +180,7 @@ If you are going with the second option, this *can* be used for local developmen
By all means, if you don't want to have npm installed locally you can go full Docker executing the following commands before starting the containers:

```
docker run --volume $MOODLE_DOCKER_APP_PATH:/app --workdir /app bash -c "npm install npm@7 -g && npm ci"
docker run --volume $MOODLE_DOCKER_APP_PATH:/app --workdir /app bash -c "npm install"
```

You can learn more about writing tests for the app in [Acceptance testing for the Moodle App](https://moodledev.io/general/app/development/testing/acceptance-testing).
Expand Down Expand Up @@ -211,7 +216,7 @@ When you change them, use `bin/moodle-docker-compose down && bin/moodle-docker-c
| `MOODLE_DOCKER_DB` | yes | pgsql, mariadb, mysql, mssql, oracle | none | The database server to run against |
| `MOODLE_DOCKER_WWWROOT` | yes | path on your file system | none | The path to the Moodle codebase you intend to test |
| `MOODLE_DOCKER_DB_VERSION` | no | Docker tag - see relevant database page on docker-hub | mysql: 8.0 <br/>pgsql: 13 <br/>mariadb: 10.7 <br/>mssql: 2017-latest <br/>oracle: 21| The database server docker image tag |
| `MOODLE_DOCKER_PHP_VERSION` | no | 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6| 8.1 | The php version to use |
| `MOODLE_DOCKER_PHP_VERSION` | no | 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6| 8.2 | The php version to use |
| `MOODLE_DOCKER_BROWSER` | no | firefox, chrome, firefox:&lt;tag&gt;, chrome:&lt;tag&gt; | firefox:3 | The browser to run Behat against. Supports a colon notation to specify a specific Selenium docker image version to use. e.g. firefox:2.53.1 can be used to run with older versions of Moodle (<3.5) |
| `MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES` | no | any value | not set | If set, dependencies for memcached, redis, solr, and openldap are added |
| `MOODLE_DOCKER_BBB_MOCK` | no | any value | not set | If set the BigBlueButton mock image is started and configured |
Expand All @@ -223,8 +228,20 @@ When you change them, use `bin/moodle-docker-compose down && bin/moodle-docker-c
| `MOODLE_DOCKER_SELENIUM_VNC_PORT` | no | any integer value (or bind_ip:integer)| not set | If set, the selenium node will expose a vnc session on the port specified. Similar to MOODLE_DOCKER_WEB_PORT, you can optionally define the host IP to bind to. If you just set the port, VNC binds to 127.0.0.1 |
| `MOODLE_DOCKER_APP_PATH` | no | path on your file system | not set | If set and the chrome browser is selected, it will start an instance of the Moodle app from your local codebase |
| `MOODLE_DOCKER_APP_VERSION` | no | a valid [app docker image version](https://docs.moodle.org/dev/Moodle_App_Docker_images) | not set | If set will start an instance of the Moodle app if the chrome browser is selected |
| `MOODLE_DOCKER_APP_RUNTIME` | no | 'ionic3' or 'ionic5' | not set | Set this to indicate the runtime being used in the Moodle app. In most cases, this can be ignored because the runtime is guessed automatically (except on Windows using the `.cmd` binary). In case you need to set it manually and you're not sure which one it is, versions 3.9.5 and later should be using Ionic 5. |
| `MOODLE_DOCKER_APP_NODE_VERSION` | no | [node](https://hub.docker.com/_/node) image version tag | not set | Node version to run the app. In most cases, this can be ignored because the version is parsed from the project's `.nvmrc` file. This will only be used when the runtime is `ionic5` and the app is running from the local filesystem. |
| `MOODLE_DOCKER_TIMEOUT_FACTOR` | no | any integer value | 1 | If set the timeouts in behat will be multiplied by the factor |

In addition to that, `MOODLE_DOCKER_RUNNING=1` env variable is defined and available
in the webserver container to flag being run by `moodle-docker`. Developer
can use this to conditionally make changes in `config.php`. The common case is
to load test-specific configuration:
```
// Load moodle-docker config file if we are in moodle-docker environment
if (getenv('MOODLE_DOCKER_RUNNING')) {
require_once(__DIR__ . '/config.docker-template.php');
}
require_once(__DIR__ . '/lib/setup.php'); // Do not edit.
```

## Local customisations

Expand Down Expand Up @@ -325,8 +342,11 @@ The Moodle Gitpod template supports the following environment variables:

* `MOODLE_REPOSITORY`. The Moodle repository to be cloned. The value should be URL encoded. If left undefined, the default repository `https://github.com/moodle/moodle.git` is used.
* `MOODLE_BRANCH`. The Moodle branch to be cloned. If left undefined, the default branch `main` is employed.
* `DATAFILE`. When specified, this feature URL initializes the Moodle site with essential data. The value should be URL encoded. The content of this file adheres to the [Behat generators format](https://moodledev.io/general/development/tools/generator#create-a-testing-scenario-using-behat-generators) for creating testing scenarios.
* `INSTALLADMINER`. Add this variable, set to any value, to install [adminer](https://www.adminer.org/).
* `CLONEALL`. If not set, a shallow clone is created, truncating the history to reduce the clone size. Set to `1` for a full clone.

For a practical demonstration, launch a Gitpod workspace with the 'main' branch patch for [MDL-79912](https://tracker.moodle.org/browse/MDL-79912). Simply open the following URL in your web browser (note that MOODLE_REPOSITORY should be URL encoded). The password for the admin user is **test**:
For a practical demonstration, launch a Gitpod workspace with the 'main' branch patch for [MDL-79912](https://tracker.moodle.org/browse/MDL-79912). Simply open the following URL in your web browser (note that MOODLE_REPOSITORY should be URL encoded). The password for the **admin** user is **test**:

```
https://gitpod.io/#MOODLE_REPOSITORY=https%3A%2F%2Fgithub.heygears.com%2Fsarjona%2Fmoodle.git,MOODLE_BRANCH=MDL-79912-main/https://github.com/moodlehq/moodle-docker
Expand Down
3 changes: 2 additions & 1 deletion base.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2"
services:
webserver:
image: "moodlehq/moodle-php-apache:${MOODLE_DOCKER_PHP_VERSION}"
Expand All @@ -8,11 +7,13 @@ services:
- "${MOODLE_DOCKER_WWWROOT}:/var/www/html"
- "${ASSETDIR}/web/apache2_faildumps.conf:/etc/apache2/conf-enabled/apache2_faildumps.conf"
environment:
MOODLE_DOCKER_RUNNING: 1
MOODLE_DOCKER_DBNAME: moodle
MOODLE_DOCKER_DBUSER: moodle
MOODLE_DOCKER_DBPASS: "m@0dl3ing"
MOODLE_DOCKER_BROWSER: firefox
MOODLE_DOCKER_WEB_HOST: "${MOODLE_DOCKER_WEB_HOST}"
MOODLE_DOCKER_TIMEOUT_FACTOR: "${MOODLE_DOCKER_TIMEOUT_FACTOR}"
exttests:
image: moodlehq/moodle-exttests
volumes:
Expand Down
1 change: 0 additions & 1 deletion bbb-mock.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2"
services:
webserver:
environment:
Expand Down
1 change: 0 additions & 1 deletion behat-faildump.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2"
services:
webserver:
volumes:
Expand Down
83 changes: 48 additions & 35 deletions bin/moodle-docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dockercompose="${dockercompose} -f ${basedir}/base.yml"
dockercompose="${dockercompose} -f ${basedir}/service.mail.yml"

# PHP Version.
export MOODLE_DOCKER_PHP_VERSION=${MOODLE_DOCKER_PHP_VERSION:-8.1}
export MOODLE_DOCKER_PHP_VERSION=${MOODLE_DOCKER_PHP_VERSION:-8.2}

# Database flavour.
dockercompose="${dockercompose} -f ${basedir}/db.${MOODLE_DOCKER_DB}.yml"
Expand Down Expand Up @@ -64,61 +64,63 @@ then
fi
fi

# Fix mobile app deprecated variables
if [ ! -z "$MOODLE_APP_VERSION" ];
then
echo 'Warning: $MOODLE_APP_VERSION is deprecated, use $MOODLE_DOCKER_APP_VERSION instead'

if [ -z "$MOODLE_DOCKER_APP_VERSION" ];
then
export MOODLE_DOCKER_APP_VERSION="$MOODLE_APP_VERSION"
fi
fi

# Guess mobile app runtime
if [ -z "$MOODLE_DOCKER_APP_RUNTIME" ];
then
if [[ ! -z "$MOODLE_DOCKER_APP_PATH" ]];
then
appversion="$(cat $MOODLE_DOCKER_APP_PATH/package.json | grep -oP '"version": "\K\d\.\d\.\d{1,2}(-\w+)?(?=")')"
appversion="$(cat $MOODLE_DOCKER_APP_PATH/package.json | sed -n -E 's/\s*"version": "([0-9]+\.[0-9]+\.[0-9]+)(.*)?",/\1/p')"
elif [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]];
then
appversion=$MOODLE_DOCKER_APP_VERSION
fi

if [[ ! -z $appversion ]];
then
if [[ ! -z "$(echo $appversion | grep -oP '\d\.\d\.\d{1,2}')" ]];
if [[ ! -z "$(echo $appversion | sed -n -E 's/([0-9]+\.[0-9]+\.[0-9]+)/\1/p')" ]];
then
appmajorversion="$(echo $appversion | grep -oP '\d(?=\.\d\.\d{1,2})')"
appminorversion="$(echo $appversion | grep -oP '\d\.\K\d(?=\.\d{1,2})')"
apppatchversion="$(echo $appversion | grep -oP '\d\.\d\.\K\d{1,2}')"
appmajorversion="$(echo $appversion | sed -n -E 's/([0-9]+)\.[0-9]+\.[0-9]+/\1/p')"
appminorversion="$(echo $appversion | sed -n -E 's/[0-9]+\.([0-9]+)\.[0-9]+/\1/p')"

if (( $appmajorversion > 3 ));
if (( $appmajorversion > 4 || $appminorversion > 3));
then
export MOODLE_DOCKER_APP_RUNTIME="ionic5"
elif (( $appminorversion != 9));
then
export MOODLE_DOCKER_APP_RUNTIME="ionic3"
elif (( $apppatchversion < 5 ));
then
export MOODLE_DOCKER_APP_RUNTIME="ionic3"
export MOODLE_DOCKER_APP_RUNTIME="ionic7"
else
export MOODLE_DOCKER_APP_RUNTIME="ionic5"
fi
else
export MOODLE_DOCKER_APP_RUNTIME="ionic5"
export MOODLE_DOCKER_APP_RUNTIME="ionic7"
fi
fi
fi

# Guess mobile app node version
if [[ -z "$MOODLE_DOCKER_APP_NODE_VERSION" ]] && [[ ! -z "$MOODLE_DOCKER_APP_PATH" ]] && [[ "$MOODLE_DOCKER_APP_RUNTIME" == "ionic5" ]];
# Guess mobile app node version (only for local app development)
if [[ -z "$MOODLE_DOCKER_APP_NODE_VERSION" ]] && [[ ! -z "$MOODLE_DOCKER_APP_PATH" ]];
then
if [ -f "$MOODLE_DOCKER_APP_PATH/.nvmrc" ]; then
appnodeversion="$(cat $MOODLE_DOCKER_APP_PATH/.nvmrc | grep -oP '(\d+\.?)+' || true)"
appnodeversion="$(cat $MOODLE_DOCKER_APP_PATH/.nvmrc | sed -E "s/v(([0-9]+\.?)+)/\1/" || true)"

export MOODLE_DOCKER_APP_NODE_VERSION="$appnodeversion"
fi

export MOODLE_DOCKER_APP_NODE_VERSION="$appnodeversion"
# Guess mobile app port (only when using Docker app images)
if [[ -z "$MOODLE_DOCKER_APP_PORT" ]] && [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]];
then
if [[ "$MOODLE_DOCKER_APP_RUNTIME" = "ionic5" ]];
then
export MOODLE_DOCKER_APP_PORT="80"
else
export MOODLE_DOCKER_APP_PORT="443"
fi
fi

# Guess mobile app protocol
if [[ -z "$MOODLE_DOCKER_APP_PROTOCOL" ]];
then
if [[ "$MOODLE_DOCKER_APP_RUNTIME" = "ionic5" ]];
then
export MOODLE_DOCKER_APP_PROTOCOL="http"
else
export MOODLE_DOCKER_APP_PROTOCOL="https"
fi
fi

Expand All @@ -139,7 +141,12 @@ then
MOODLE_DOCKER_BROWSER_TAG=3
elif [[ "$MOODLE_DOCKER_BROWSER_NAME" = "chrome" ]];
then
MOODLE_DOCKER_BROWSER_TAG=3
if [[ "$MOODLE_DOCKER_APP_RUNTIME" = "ionic5" ]];
then
MOODLE_DOCKER_BROWSER_TAG=3
else
MOODLE_DOCKER_BROWSER_TAG="120.0"
fi
fi
fi

Expand All @@ -148,11 +155,11 @@ if [[ "$MOODLE_DOCKER_BROWSER_NAME" == "chrome" ]];
then
if [[ ! -z "$MOODLE_DOCKER_APP_PATH" ]];
then
dockercompose="${dockercompose} -f ${basedir}/moodle-app-dev-$MOODLE_DOCKER_APP_RUNTIME.yml"
dockercompose="${dockercompose} -f ${basedir}/moodle-app-dev.yml"
elif [[ ! -z "$MOODLE_DOCKER_APP_VERSION" ]];
then
# Mobile app using a docker image
dockercompose="${dockercompose} -f ${basedir}/moodle-app-$MOODLE_DOCKER_APP_RUNTIME.yml"
dockercompose="${dockercompose} -f ${basedir}/moodle-app.yml"
fi
fi

Expand All @@ -165,7 +172,11 @@ fi
export MOODLE_DOCKER_SELENIUM_SUFFIX=""
if [[ $MOODLE_DOCKER_SELENIUM_VNC_PORT == *":"* ]] || [[ $MOODLE_DOCKER_SELENIUM_VNC_PORT -gt 0 ]]
then
export MOODLE_DOCKER_SELENIUM_SUFFIX="-debug"
if [[ $(echo $MOODLE_DOCKER_BROWSER_TAG | sed 's/[^0-9].*//g') -lt 4 ]]
then
export MOODLE_DOCKER_SELENIUM_SUFFIX="-debug"
fi

# If no bind ip has been configured (bind_ip:port), default to 127.0.0.1
if [[ ! $MOODLE_DOCKER_SELENIUM_VNC_PORT == *":"* ]]
then
Expand Down Expand Up @@ -218,6 +229,8 @@ then
dockercompose="${dockercompose} -f ${basedir}/webserver.port.yml"
fi

# Behat test timeout factor
export MOODLE_DOCKER_TIMEOUT_FACTOR=${MOODLE_DOCKER_TIMEOUT_FACTOR:-1}

# Mac OS Compatbility
if [[ "$(uname)" == "Darwin" ]]; then
Expand Down
Loading

0 comments on commit 6cc55dd

Please # to comment.