Skip to content

Commit

Permalink
Refactored project. Will now provide Docker images on releases for do…
Browse files Browse the repository at this point in the history
…wnload and use the new plugin using a declarative approach to configure moodle
  • Loading branch information
Glutamat42 committed Dec 14, 2024
1 parent 5789b1c commit 860d315
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 1,033 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/integration-test.yml

This file was deleted.

53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Moodle Plugin CI

on:
release:
types: [ created ]

jobs:
define-matrix:
runs-on: ubuntu-latest
outputs:
include_list: ${{ steps.moodle_versions.outputs.moodle_versions }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Collect list of compatible moodle versions
id: moodle_versions
run: |
supported_versions=$(bash get_supported_moodle_versions.sh)
echo "moodle_versions=$supported_versions" >> $GITHUB_OUTPUT
release:
runs-on: ubuntu-latest
needs: define-matrix
permissions:
contents: write
strategy:
matrix:
moodle_version: ${{ fromJSON(needs.define-matrix.outputs.include_list) }}
steps:
- name: Build Docker image
uses: docker/build-push-action@v2
with:
context: .
build-args: |
MOODLE_VERSION=${{ matrix.moodle_version }}
file: Dockerfile
push: false
tags: adler-moodle:${{ matrix.moodle_version }}-${{ github.event.release.tag_name }}

#
# - name: Prepare release body (description)
# id: prep_body
# run: |
# echo "${{ github.event.release.body }}" > changes.md
#
# - name: Discord notification
# uses: appleboy/discord-action@master
# with:
# webhook_id: ${{ secrets.DISCORD_RELEASE_CHANNEL_WEBHOOK_ID }}
# webhook_token: ${{ secrets.DISCORD_RELEASE_CHANNEL_WEBHOOK_TOKEN }}
# username: GitHub Releases
# message: "New release of **${{ github.repository }}**\nVersion: ${{ github.ref_name }} (${{github.event.release.name}})\n<${{ github.event.release.html_url }}>"
# file: changes.md
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
ARG MOODLE_VERSION=latest
ARG PLUGIN_VERSION=main

FROM bitnami/moodle:${MOODLE_VERSION}

# generate german language files
RUN sed -i 's/^# de_DE.UTF-8 UTF-8$/de_DE.UTF-8 UTF-8/' /etc/locale.gen && locale-gen

RUN apt update && apt install curl unzip nano -y
RUN apt update && apt install curl unzip jq -y
COPY opt/adler /opt/adler
COPY plugin-releases.json /opt/adler/moodle/adler_setup
COPY plugins.json /opt/adler

# ARG are wiped after FROM, see https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PLUGIN_VERSION
ENV PLUGIN_VERSION=${PLUGIN_VERSION}

ENTRYPOINT [ "/opt/adler/entrypoint_adler.sh" ]
CMD [ "/opt/bitnami/scripts/moodle/run.sh" ]
Expand Down
74 changes: 20 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# Moodle Bitnami Image Extension - User Creation, PHP Environment Variables, and AdLer Setup

This project extends the bitnami/moodle image with the following features:

- Setting up AdLer (after the first start the Moodle part of AdLer is fully set up).
- Create user(s) on first start
- Adding another environment variable to set a php.ini option.


## Dependencies
- Requires at least Plugin-Release-Set version 3.1.0
# AdLer LMS - Moodle for our project

This project extends the bitnami/moodle image for use with AdLer.

## Windows Users

Expand Down Expand Up @@ -44,47 +35,19 @@ All variables from the bitnami/moodle image are supported. Additionally, the fol

### Moodle user creation variables

| Variable | required | Description |
|-------------------------------------|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `USER_NAME` | no | Specifies the login name of a user to be created during the initial setup. Watch out that the default name of the admin user of bitnami/docker is "user" |
| `USER_PASSWORD` | if `USER_NAME` is specified | Specifies the password for the user created during the initial setup. Passwords have to follow moodle password validation rules. Otherwise the setup script will break. |
| `USER_FIRST_NAME` | no | Specifies the first name of the user created during the initial setup. |
| `USER_LAST_NAME` | no | Specifies the last name of the user created during the initial setup. |
| `USER_EMAIL` | no | Specifies the email address of the user created during the initial setup. |
| `USER_ROLE` | no | Specifies the short name of a page wide (system) role to assign to the user created during the initial setup. This is mostly useful for moodle administration accounts |
| `USER_CREATE_ADLER_COURSE_CATEGORY` | no | true \| false - If true a course category will be created for the user where has the role "adler_manager" |
| Variable | required | Description |
|--------------------------------------|------------------------------|-------------------------------|
| `DECLARATIVE_SETUP_MANAGER_PASSWORD` | if role `test_users` is used | Password for the manager user |
| `DECLARATIVE_SETUP_STUDENT_PASSWORD` | if role `test_users` is used | Password for the student user |

### Other environment variables

| Variable | required | Description |
|--------------------------------|----------|--------------------------------------------------------------------------------------------------------|
| `DEVELOP_DONT_INSTALL_PLUGINS` | no | true \| false - If true the setup script will not install any plugins. This is useful for development. |
| Variable | required | Description |
|------------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------|
| `ADLER_PLAYBOOK_ROLES` | no | roles to be passed to playbook, see [AdLer Playbook](https://github.com/ProjektAdLer/MoodlePlugin-playbook_adler) for a list of roles |

#### Examples

Example one user

```
USER_NAME=john_doe
USER_PASSWORD=Pass1234
USER_FIRST_NAME=John
```

Example three users

```
USER_NAME=user1,user2,user3
USER_PASSWORD=Secret123,Secret123,Pass1234
USER_FIRST_NAME=First1,First2,First3
USER_LAST_NAME=Last1,Last2,Last3
USER_EMAIL=user1@example.com,user2@example.com,user3@example.com
USER_ROLE=false,manager,false
```

## Sample docker-compose.yml

see [tests/docker-compose.yml](tests/docker-compose.yml)

## Updating moodle

> [!IMPORTANT]
Expand All @@ -98,26 +61,29 @@ Sadly it is not easy to automate that process as moodle itself does not provide
It might be within the realm of possibility to provide AdLer images with moodle and Plugins preinstalled,
but with this approach all additional plugins would be deleted after every update (potentially breaking moodle).

A possible approach to mitigate this issue might be placing an overlay volume on top of the whole moodle directory of this
A possible approach to mitigate this issue might be placing an overlay volume on top of the whole moodle directory of
this
moodle image. But it is unknown whether this would work and what potential issues might arise from this.

## Docker Build Arguments

When building the Docker image for this project, you can customize the following arguments:

- `MOODLE_VERSION`: Specifies the version of Moodle to be used in the image. The default value is `latest`.
- `PLUGIN_VERSION`: Specifies the version of the Moodle plugin to be included in the image. The default value is `main`.

These arguments allow you to control the versions of Moodle and the plugin that are used during the image build process. You can adjust these values according to your specific
These arguments allow you to control the versions of Moodle and the plugin that are used during the image build process.
You can adjust these values according to your specific
requirements and preferences.

## Install additional languages
1) Install the required system locale by modifying the Dockerfile. You can see which one you need by manually enabling the desired
language pack in moodle and checking the displayed error message.
2) Install the moodle language pack either via web interface or by modifying the setup.php script (add an additional
`install_language_pack` call for the desired language)

1) Install the required system locale by modifying the Dockerfile. You can see which one you need by manually enabling
the desired
language pack in moodle and checking the displayed error message.
2) Install the moodle language pack either via web interface or by modifying the playbook.

## Troubleshooting

**Moodle setup fails with "The configuration file config.php alreaady exists. ...":** \
This typically indicates the setup script already failed during a previous run. Have a look on the logs of the first execution.
This typically indicates the setup script already failed during a previous run. Have a look on the logs of the first
execution.
63 changes: 63 additions & 0 deletions get_supported_moodle_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# Read plugins.json
plugins=$(jq -c '.[]' plugins.json)

# Initialize the supported_moodle_versions variable
supported_moodle_versions=""

# Iterate over each plugin
for plugin in $plugins; do
git_project=$(echo $plugin | jq -r '.git_project')
version=$(echo $plugin | jq -r '.version')
name=$(echo $plugin | jq -r '.name')

# Construct the URL to the plugin_compatibility.json file
if [ "$version" == "main" ]; then
url="https://raw.githubusercontent.com/$git_project/refs/heads/$version/plugin_compatibility.json"
else
url="https://raw.githubusercontent.com/$git_project/refs/tags/$version/plugin_compatibility.json"
fi

# Fetch the plugin_compatibility.json file
response=$(curl -s $url)

if [[ "$response" == "404: Not Found" ]]; then
echo "Failed to fetch plugin_compatibility.json for $name ($version)"
exit 1
fi

# Extract the list of Moodle versions from the response
current_moodle_versions=$(echo $response | jq -r '.[].moodle')
if [ $? -eq 0 ]; then
if [ -z "$supported_moodle_versions" ]; then
# If supported_moodle_versions is empty, set it to the current list
supported_moodle_versions=$current_moodle_versions
else
# Otherwise, keep only the versions that are in both lists
supported_moodle_versions=$(echo "$supported_moodle_versions" | grep -Fxf - <(echo "$current_moodle_versions"))
fi
else
echo "Failed to fetch plugin_compatibility.json for $name ($version)"
exit 1
fi
done

convert_branch_to_version() {
branch_name=$1
major_version=${branch_name:7:1}
minor_version=${branch_name:8:2}
minor_version=${minor_version#0} # Remove leading zero if present
echo "$major_version.$minor_version"
}

json_array="["
for moodle_branch in $supported_moodle_versions; do
moodle_version=$(convert_branch_to_version $moodle_branch)
json_array="$json_array {\"moodle\": \"$moodle_version\"},"
done
json_array="${json_array%,} ]"


# Output the final list of supported Moodle versions
echo "$json_array"
3 changes: 0 additions & 3 deletions opt/adler/moodle/adler_setup/dependencies.php

This file was deleted.

16 changes: 0 additions & 16 deletions opt/adler/moodle/adler_setup/dummy_functions.php

This file was deleted.

Loading

0 comments on commit 860d315

Please sign in to comment.