Skip to content

Commit

Permalink
Merge branch 'moodlehq:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aweed1 committed Mar 28, 2024
2 parents f2cbe83 + 575597a commit 52f3a6a
Show file tree
Hide file tree
Showing 44 changed files with 426 additions and 198 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
116 changes: 79 additions & 37 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
local.yml
/moodle/
50 changes: 50 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
tasks:
- name: Moodle Docker

before: |
# Set up Moodle docker environment vars.
export COMPOSE_PROJECT_NAME=moodle-gitpod
export MOODLE_DOCKER_WWWROOT="$GITPOD_REPO_ROOT"/moodle
export MOODLE_DOCKER_DB=pgsql
init: |
# Set up Moodle repository.
.gitpod/setup-env.sh
# Ensure customized config.php for the Docker containers is in place
cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php
# Start up containers.
bin/moodle-docker-compose up -d
# Wait for DB to come up.
bin/moodle-docker-wait-for-db
# Initialize Moodle database for manual testing.
bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="Docker moodle" --shortname="docker_moodle" --summary="Docker moodle site" --adminpass="test" --adminemail="admin@example.com"
# Hack to avoid when the workspace is restarted.
# It can be removed when https://github.com/gitpod-io/gitpod/issues/17551 is fixed.
bin/moodle-docker-compose exec webserver bash -c 'rm -rf /var/log/apache2/*'
# Open Moodle site in browser.
gp ports await 8000 && gp preview $(gp url 8000)
command: |
# Update the patch to the latest version.
cd moodle
git fetch
git reset --hard
cd ..
# Start up containers.
bin/moodle-docker-compose up -d
# Wait for DB to come up.
bin/moodle-docker-wait-for-db
ports:
- port: 8000
name: Moodle server
visibility: public
onOpen: ignore
12 changes: 12 additions & 0 deletions .gitpod/setup-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Initialize variables to get Moodle code.
if [ -z "$MOODLE_REPOSITORY" ];
then
export MOODLE_REPOSITORY=https://github.com/moodle/moodle.git
fi
if [ -z "$MOODLE_BRANCH" ];
then
export MOODLE_BRANCH=main
fi

# Clone Moodle repository.
cd "${GITPOD_REPO_ROOT}" && git clone --branch "${MOODLE_BRANCH}" --single-branch "${MOODLE_REPOSITORY}" moodle
47 changes: 38 additions & 9 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=master)](https://github.com/moodlehq/moodle-docker/actions/workflows/ci.yml?query=branch%3Amaster)
[![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)

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

Expand Down Expand Up @@ -132,7 +132,7 @@ Notes:
* The admin `username` you need to use for logging in is `admin` by default. You can customize it by passing `--adminuser='myusername'`
* During manual testing, if you are facing that your Moodle site is logging
you off continuously, putting the correct credentials, clean all cookies
for your Moodle site URL (usually `localhost`) from your browser.
for your Moodle site URL (usually `localhost`) from your browser.
[More info](https://github.com/moodlehq/moodle-docker/issues/256).

## Use containers for running behat tests for the Moodle App
Expand All @@ -141,9 +141,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 +175,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 +211,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.0 | 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.1 | 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 +223,6 @@ 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. |

## Local customisations

Expand Down Expand Up @@ -299,10 +297,41 @@ moodle-docker-compose restart webserver

## Advanced usage

As can be seen in [bin/moodle-docker-compose](https://github.com/moodlehq/moodle-docker/blob/master/bin/moodle-docker-compose),
As can be seen in [bin/moodle-docker-compose](https://github.com/moodlehq/moodle-docker/blob/main/bin/moodle-docker-compose),
this repo is just a series of Docker Compose configurations and light wrapper which make use of companion docker images. Each part
is designed to be reusable and you are encouraged to use the docker [compose] commands as needed.

## Quick start with Gitpod

Gitpod is a free, cloud-based, development environment providing VS Code and a suitable development environment right in your browser.

When launching a workspace in Gitpod, it will automatically:

* Clone the Moodle repo into the `<workspace>/moodle` folder.
* Initialise the Moodle database.
* Start the Moodle webserver.

<p>
<a href="https://gitpod.io/#https://github.com/moodlehq/moodle-docker" target="_blank" rel="noopener noreferrer">
<img loading="lazy" src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" class="img_ev3q">
</a>
</p>

> **IMPORTANT**: Gitpod is an alternative to local development and completely optional. We recommend setting up a local development environment if you plan to contribute regularly.
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.

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.com%2Fsarjona%2Fmoodle.git,MOODLE_BRANCH=MDL-79912-main/https://github.com/moodlehq/moodle-docker
```

To optimize your browsing experience, consider integrating the [Tampermonkey extension](https://www.tampermonkey.net/) into your preferred web browser for added benefits. Afterward, install the Gitpod script, which can be accessed via the following URL: [Gitpod script](https://gist.githubusercontent.com/sarjona/9fc728eb2d2b41a783ea03afd6a6161e/raw/gitpod.js). This script efficiently incorporates a button adjacent to each branch within the Moodle tracker, facilitating the effortless initiation of a Gitpod workspace tailored to the corresponding patch for the issue you're currently viewing.

## Companion docker images

The following Moodle customised docker images are close companions of this project:
Expand Down
8 changes: 4 additions & 4 deletions assets/web/apache2_mailpit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

Redirect "/_/mail" "/_/mail/"

ProxyPass "/_/mail/api/events" "ws://mailpit:8025/api/events"
ProxyPassReverse "/_/mail/api/events" "ws://mailpit:8025/api/events"
ProxyPass "/_/mail/api/events" "ws://mailpit:8025/_/mail/api/events"
ProxyPassReverse "/_/mail/api/events" "ws://mailpit:8025/_/mail/api/events"

ProxyPass "/_/mail/" "http://mailpit:8025/"
ProxyPassReverse "/_/mail/" "http://mailpit:8025/"
ProxyPass "/_/mail/" "http://mailpit:8025/_/mail/"
ProxyPassReverse "/_/mail/" "http://mailpit:8025/_/mail/"
1 change: 0 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 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
87 changes: 52 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.0}
export MOODLE_DOCKER_PHP_VERSION=${MOODLE_DOCKER_PHP_VERSION:-8.1}

# Database flavour.
dockercompose="${dockercompose} -f ${basedir}/db.${MOODLE_DOCKER_DB}.yml"
Expand Down Expand Up @@ -64,61 +64,69 @@ 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 ));
then
export MOODLE_DOCKER_APP_RUNTIME="ionic5"
elif (( $appminorversion != 9));
if (( $appmajorversion > 4 || $appminorversion > 3));
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"
# TODO always default to ionic7 after 4.4.0 release
if [[ $appversion = "latest"* ]];
then
export MOODLE_DOCKER_APP_RUNTIME="ionic5"
else
export MOODLE_DOCKER_APP_RUNTIME="ionic7"
fi
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 +147,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 +161,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 +178,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
Loading

0 comments on commit 52f3a6a

Please sign in to comment.