diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml deleted file mode 100644 index a73444d..0000000 --- a/.github/workflows/integration-test.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Moodle Plugin CI - -on: [push, pull_request] - -jobs: - integration-test: - runs-on: ubuntu-22.04 - - steps: - - name: Check out repository code - uses: actions/checkout@v3 - - - name: run test script - run: | - cd tests - sudo ./test.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4569905 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 823239a..77e33a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] diff --git a/README.md b/README.md index e43a2a8..cf19be5 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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] @@ -98,7 +61,8 @@ 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 @@ -106,18 +70,20 @@ moodle image. But it is unknown whether this would work and what potential issue 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. \ No newline at end of file +This typically indicates the setup script already failed during a previous run. Have a look on the logs of the first +execution. \ No newline at end of file diff --git a/get_supported_moodle_versions.sh b/get_supported_moodle_versions.sh new file mode 100644 index 0000000..e3f5dc2 --- /dev/null +++ b/get_supported_moodle_versions.sh @@ -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" \ No newline at end of file diff --git a/opt/adler/moodle/adler_setup/dependencies.php b/opt/adler/moodle/adler_setup/dependencies.php deleted file mode 100644 index e9f4c72..0000000 --- a/opt/adler/moodle/adler_setup/dependencies.php +++ /dev/null @@ -1,3 +0,0 @@ -libdir . "/clilib.php"); -require_once("lib.php"); - - -## cli opts -$help = "Command line tool to uninstall plugins. - -Options: - -h --help Print this help. - --plugin_version Version of AdLer plugins to install. main or exact release name. Defaults to main. - --develop_dont_install_plugins DEVELOP OPTION: Skip plugin installation -"; - -list($options, $unrecognised) = cli_get_params([ - 'help' => false, - 'plugin_version' => 'main', - 'develop_dont_install_plugins' => false, -], []); - -if ($unrecognised) { - $unrecognised = implode(PHP_EOL . ' ', $unrecognised); - cli_error('unknown option(s):' . $unrecognised); -} - - -if ($options['help']) { - cli_writeln($help); - exit(0); -} - -# cast boolean cli opts -$options['develop_dont_install_plugins'] = $options['develop_dont_install_plugins'] == "true"; -## end cli opts -cli_writeln('CLI options: ' . json_encode($options)); - - -// validate plugin version -if (version_compare($options['plugin_version'], $MINIMUM_PLUGIN_RELEASE_SET, '<') && $options['plugin_version'] !== 'main') { - cli_error("Plugin version is too low. Minimum required version is $MINIMUM_PLUGIN_RELEASE_SET"); -} - - -function get_plugin_config() { - $url = __DIR__ . '/plugin-releases.json'; -// $url = 'https://raw.githubusercontent.com/Glutamat42/moodle-docker/main/plugin-releases.json'; - $file_content = file_get_contents($url); - return json_decode($file_content, true); -} - - -if ($options['develop_dont_install_plugins']) { - cli_writeln("skipping plugin installation"); -} else { - cli_writeln("installing plugins"); - - $plugin_release_info = get_plugin_config(); - - $plugins = []; - if (isset($plugin_release_info['common_versions'][$options['plugin_version']])) { - foreach ($plugin_release_info['common_versions'][$options['plugin_version']] as $plugin) { - $path = $CFG->dirroot . $plugin['path']; - - if (preg_match('/^[0-9]+(\.[0-9]+){0,2}(-rc(\.[0-9]+)?)?$/', $plugin['version'])) { - // plugin is a release - $info = get_updated_release_info( - $plugin['git_project'], - $plugin['version'], - core_plugin_manager::instance()->get_plugin_info($plugin['name'])->release - ); - - if ($info === false) { - cli_writeln("No update available for {$plugin['name']} {$plugin['version']}"); - continue; - } else if ($info !== null && property_exists($info, 'tag_name')) { - // checking for one of the keys is sufficient - $url = $info->zip_url; - } else { - cli_error("Failed to get release info for {$plugin['name']} {$plugin['version']}"); - } - } else { - // plugin is a branch - $url = "https://github.com/" . $plugin['git_project'] . "/archive/refs/heads/" . $plugin['version'] . ".zip"; - } - - /** @noinspection PhpUndefinedVariableInspection */ - $plugins[] = [ - "path" => $path, - "url" => $url - ]; - } - } else { - cli_error("plugin version not found"); - } - - cli_writeln("plugins to install: " . json_encode($plugins)); - foreach ($plugins as $plugin) { - update_plugin($plugin); - } -} - -// upgrade moodle installation -cli_writeln("Upgrading moodle installation..."); -$cmd = "php {$CFG->dirroot}/admin/cli/upgrade.php --non-interactive --allow-unstable 2>&1"; -cli_writeln("Executing: $cmd"); -passthru($cmd, $result_code); -if ($result_code != 0) { - cli_error('command execution failed'); -} diff --git a/opt/adler/moodle/adler_setup/lib.php b/opt/adler/moodle/adler_setup/lib.php deleted file mode 100644 index eadf5ba..0000000 --- a/opt/adler/moodle/adler_setup/lib.php +++ /dev/null @@ -1,216 +0,0 @@ -dirroot . '/user/profile/lib.php'); -require_once($CFG->dirroot . '/user/lib.php'); - -use local_adler\plugin_interface; -use core\event\user_created; -use tool_langimport\controller as lang_controller; - - - -/** Get Infos (incl download urls) of release to update to. Will return false if nothing to update - * @param string $github_repo GitHub repo of the plugin, / - * @param string $version Version pattern to match against. Eg 1 will match all Releases 1.x.y, 2.7 will match 2.7.x - * @param string|null $old_version Current version - * @return object|false - */ -function get_updated_release_info(string $github_repo, string $version, string $old_version = null) { - cli_writeln("Params for get_updated_release_info: github_repo=$github_repo, version=$version, old_version=$old_version"); - - $url = "https://api.github.com/repos/" . $github_repo . "/releases"; - cli_writeln("Fetching release info from $url"); - - $context = stream_context_create(['http' => ['user_agent' => 'PHP']]); - $response = file_get_contents($url, false, $context); -// $response = "[{\"url\":\"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375\",\"assets_url\":\"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets\",\"upload_url\":\"https://uploads.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets{?name,label}\",\"html_url\":\"https://github.com/ProjektAdLer/MoodlePluginLocal/releases/tag/1.0.0\",\"id\":108886375,\"author\":{\"login\":\"Glutamat42\",\"id\":51326311,\"node_id\":\"MDQ6VXNlcjUxMzI2MzEx\",\"avatar_url\":\"https://avatars.githubusercontent.com/u/51326311?v=4\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/Glutamat42\",\"html_url\":\"https://github.com/Glutamat42\",\"followers_url\":\"https://api.github.com/users/Glutamat42/followers\",\"following_url\":\"https://api.github.com/users/Glutamat42/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/Glutamat42/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/Glutamat42/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/Glutamat42/subscriptions\",\"organizations_url\":\"https://api.github.com/users/Glutamat42/orgs\",\"repos_url\":\"https://api.github.com/users/Glutamat42/repos\",\"events_url\":\"https://api.github.com/users/Glutamat42/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/Glutamat42/received_events\",\"type\":\"User\",\"site_admin\":false},\"node_id\":\"RE_kwDOIidAYc4GfXln\",\"tag_name\":\"1.0.0\",\"target_commitish\":\"main\",\"name\":\"v1.0.0\",\"draft\":false,\"prerelease\":false,\"created_at\":\"2023-06-16T14:30:58Z\",\"published_at\":\"2023-06-16T14:50:20Z\",\"assets\":[],\"tarball_url\":\"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/tarball/1.0.0\",\"zipball_url\":\"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/zipball/1.0.0\",\"body\":\"This initial release of the project supports both Moodle 4.2 and Moodle 4.1 (LTS) versions. It introduces essential functionality to enhance the project's capabilities. Key highlights of this release include:\\r\\n\\r\\n- Compatibility with Moodle 4.2 and Moodle 4.1 (LTS)\\r\\n- API endpoints for integration with external systems (backend)\\r\\n- Backup and restore functionality\\r\\n- Plugin interface for clear communication functions between plugins (availability_adler)\\r\\n- Documentation\"}]"; -// $response = "[\n {\n \"url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375\",\n \"assets_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets\",\n \"upload_url\": \"https://uploads.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets{?name,label}\",\n \"html_url\": \"https://github.com/ProjektAdLer/MoodlePluginLocal/releases/tag/1.0.0\",\n \"id\": 108886375,\n \"node_id\": \"RE_kwDOIidAYc4GfXln\",\n \"tag_name\": \"1.0.0\",\n \"target_commitish\": \"main\",\n \"name\": \"v1.0.0\",\n \"draft\": false,\n \"prerelease\": false,\n \"created_at\": \"2023-06-16T14:30:58Z\",\n \"published_at\": \"2023-06-16T14:50:20Z\",\n \"assets\": [],\n \"tarball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/tarball/1.0.0\",\n \"zipball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/zipball/1.0.0\"\n },\n {\n \"url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375\",\n \"assets_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets\",\n \"upload_url\": \"https://uploads.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets{?name,label}\",\n \"html_url\": \"https://github.com/ProjektAdLer/MoodlePluginLocal/releases/tag/1.0.0\",\n \"id\": 108886375,\n \"node_id\": \"RE_kwDOIidAYc4GfXln\",\n \"tag_name\": \"1.0.3\",\n \"target_commitish\": \"main\",\n \"name\": \"v1.0.3\",\n \"draft\": false,\n \"prerelease\": false,\n \"created_at\": \"2023-06-16T14:30:58Z\",\n \"published_at\": \"2023-06-16T14:50:20Z\",\n \"assets\": [],\n \"tarball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/tarball/1.0.0\",\n \"zipball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/zipball/1.0.0\"\n },\n {\n \"url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375\",\n \"assets_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets\",\n \"upload_url\": \"https://uploads.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets{?name,label}\",\n \"html_url\": \"https://github.com/ProjektAdLer/MoodlePluginLocal/releases/tag/1.0.0\",\n \"id\": 108886375,\n \"node_id\": \"RE_kwDOIidAYc4GfXln\",\n \"tag_name\": \"2.0.0\",\n \"target_commitish\": \"main\",\n \"name\": \"v2.0.0\",\n \"draft\": false,\n \"prerelease\": false,\n \"created_at\": \"2023-06-16T14:30:58Z\",\n \"published_at\": \"2023-06-16T14:50:20Z\",\n \"assets\": [],\n \"tarball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/tarball/1.0.0\",\n \"zipball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/zipball/1.0.0\"\n },\n {\n \"url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375\",\n \"assets_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets\",\n \"upload_url\": \"https://uploads.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets{?name,label}\",\n \"html_url\": \"https://github.com/ProjektAdLer/MoodlePluginLocal/releases/tag/1.0.0\",\n \"id\": 108886375,\n \"node_id\": \"RE_kwDOIidAYc4GfXln\",\n \"tag_name\": \"2.0.1\",\n \"target_commitish\": \"main\",\n \"name\": \"v2.0.1\",\n \"draft\": false,\n \"prerelease\": false,\n \"created_at\": \"2023-06-16T14:30:58Z\",\n \"published_at\": \"2023-06-16T14:50:20Z\",\n \"assets\": [],\n \"tarball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/tarball/1.0.0\",\n \"zipball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/zipball/1.0.0\"\n },\n {\n \"url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375\",\n \"assets_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets\",\n \"upload_url\": \"https://uploads.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets{?name,label}\",\n \"html_url\": \"https://github.com/ProjektAdLer/MoodlePluginLocal/releases/tag/1.0.0\",\n \"id\": 108886375,\n \"node_id\": \"RE_kwDOIidAYc4GfXln\",\n \"tag_name\": \"2.1.0\",\n \"target_commitish\": \"main\",\n \"name\": \"v2.1.0\",\n \"draft\": false,\n \"prerelease\": false,\n \"created_at\": \"2023-06-16T14:30:58Z\",\n \"published_at\": \"2023-06-16T14:50:20Z\",\n \"assets\": [],\n \"tarball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/tarball/1.0.0\",\n \"zipball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/zipball/1.0.0\"\n },\n {\n \"url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375\",\n \"assets_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets\",\n \"upload_url\": \"https://uploads.github.com/repos/ProjektAdLer/MoodlePluginLocal/releases/108886375/assets{?name,label}\",\n \"html_url\": \"https://github.com/ProjektAdLer/MoodlePluginLocal/releases/tag/1.0.0\",\n \"id\": 108886375,\n \"node_id\": \"RE_kwDOIidAYc4GfXln\",\n \"tag_name\": \"3.0.0\",\n \"target_commitish\": \"main\",\n \"name\": \"v3.0.0\",\n \"draft\": false,\n \"prerelease\": false,\n \"created_at\": \"2023-06-16T14:30:58Z\",\n \"published_at\": \"2023-06-16T14:50:20Z\",\n \"assets\": [],\n \"tarball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/tarball/1.0.0\",\n \"zipball_url\": \"https://api.github.com/repos/ProjektAdLer/MoodlePluginLocal/zipball/1.0.0\"\n }\n]"; - cli_writeln("Response: $response"); - - $releases = json_decode($response, true); - $matchingReleases = array_filter($releases, function ($release) use ($version) { - return strpos($release['tag_name'], $version) === 0; - }); - cli_writeln("Matching releases: " . json_encode($matchingReleases)); - - usort($matchingReleases, function ($a, $b) { - return version_compare($a['tag_name'], $b['tag_name'], '<=') ? 1 : -1; - }); - cli_writeln("Sorted matching releases: " . json_encode($matchingReleases)); - - $latestRelease = reset($matchingReleases); - cli_writeln("Latest release: " . json_encode($latestRelease)); - - if ($old_version !== null && $latestRelease['tag_name'] === $old_version) { - return false; - } - - return (object)[ - 'tag_name' => $latestRelease['name'], - 'version' => $latestRelease['tag_name'], - 'zip_url' => $latestRelease['zipball_url'], - 'tar_url' => $latestRelease['tarball_url'] - ]; -} - -/** - * @param $plugin object plugin object with "path" and "url" - * @return void - */ -function update_plugin($plugin) { - $plugin_path = $CFG->dirroot . DIRECTORY_SEPARATOR . $plugin["path"]; - - if (is_dir($plugin_path)) { - // make writeable - chmod($plugin_path,0775); - // delete plugin folder - cli_writeln("Plugin already installed, updating..."); - $cmd = "rm -rf $plugin_path"; - cli_writeln("Executing: $cmd"); - exec($cmd, $blub, $result_code); - if ($result_code != 0) { - cli_error('command execution failed'); - } - } - cli_writeln("Installing plugin..."); - // first cleanup in case the folder is left over from a previous failed attempt - $cmd = "rm -rf /tmp/plugin && mkdir /tmp/plugin && curl -L {$plugin['url']} -o /tmp/plugin/plugin.zip && unzip /tmp/plugin/plugin.zip -d /tmp/plugin/ && rm /tmp/plugin/plugin.zip && mv /tmp/plugin/* $plugin_path && rm -r /tmp/plugin"; - cli_writeln("Executing: $cmd"); - exec($cmd, $blub, $result_code); - if ($result_code != 0) { - cli_error('command execution failed'); - } - // revoke write permissions to prevent update in moodle ui - chmod($plugin_path, 0555); -} - -function create_one_user($username, $password, $first_name, $last_name, $email, $role) { - // originally taken from moodlelib ~4.2, but not much left of it - cli_writeln('creating user "' . $username . '"'); - - $newuser = new stdClass(); - // Just in case check text case. - $newuser->username = trim(strtolower($username)); - $newuser->password = $password; - $newuser->email = $email; - $newuser->firstname = $first_name; - $newuser->lastname = $last_name; - $newuser->auth = 'manual'; - $newuser->lang = 'en'; - $newuser->timecreated = time(); - $newuser->timemodified = $newuser->timecreated; - $newuser->confirmed = 1; - $newuser->mnethostid = get_config('core', 'mnet_localhost_id'); - $newuser->description = "Created during setup"; - - try { - $newuser->id = user_create_user($newuser, true, false); - } catch (Throwable $e) { - cli_error(json_encode($e)); - } -// Setting the password this way ignore password validation rules -// update_internal_user_password($user, $password); - - // Save user profile data. - profile_save_data($newuser); - - $user = get_complete_user_data('id', $newuser->id); - - // Trigger event. - user_created::create_from_userid($newuser->id)->trigger(); - - // assign user to role - if ($role) { - global $DB; - $role_id = $DB->get_record('role', array('shortname' => $role))->id; - role_assign($role_id, $user->id, 1); - } - - cli_writeln('user created'); - return $user; -} - -function create_users($options) { - // parse data, set default values - $users_data = [ - 'name' => explode(',', $options['user_name']), - 'password' => explode(',', $options['user_password']), - ]; - $users_data['first_name'] = $options['user_first_name'] ? explode(',', $options['user_first_name']) : array_fill(0, count($users_data['name']), "false"); - $users_data['last_name'] = $options['user_last_name'] ? explode(',', $options['user_last_name']) : array_fill(0, count($users_data['name']), "false"); - $users_data['email'] = $options['user_email'] ? explode(',', $options['user_email']) : array_fill(0, count($users_data['name']), "false"); - $users_data['role'] = $options['user_role'] ? explode(',', $options['user_role']) : array_fill(0, count($users_data['name']), "false"); - $users_data['create_adler_course_category'] = $options['user_create_adler_course_category'] ? explode(',', $options['user_create_adler_course_category']) : array_fill(0, count($users_data['name']), "false"); - - // trim all values - foreach (array_keys($users_data) as $key) { - $users_data[$key] = array_map('trim', $users_data[$key]); - } - - // in case any value is empty, set to false - foreach (array_keys($users_data) as $key) { - $users_data[$key] = array_map(function ($value) { - return empty($value) ? "false" : $value; - }, $users_data[$key]); - } - - // validation - foreach (array_keys($users_data) as $key) { - assert(count($users_data['name']) == count($users_data[$key]), 'all user property arrays has to have the same length'); - } - - - for ($i = 0; $i < count($users_data['name']); $i++) { - // for optional fields, fill with default values if not set - $first_name = $users_data['first_name'][$i] != "false" ? $users_data['first_name'][$i] : $users_data['name'][$i]; - $last_name = $users_data['last_name'][$i] != "false" ? $users_data['last_name'][$i] : $users_data['name'][$i]; - $role = $users_data['role'][$i] == "false" ? false : $users_data['role'][$i]; - $email = $users_data['email'][$i] != "false" ?: $users_data['name'][$i] . '@example.example'; - - $user = create_one_user($users_data['name'][$i], $users_data['password'][$i], $first_name, $last_name, $email, $role); - - if ($users_data['create_adler_course_category'][$i] == "true") { - cli_writeln("creating course category with upload permission for user " . $user->username); - create_default_course_category_for_user($user->username); - } - } -} - -function create_default_course_category_for_user($username) { - // use local_adler cli script - plugin_interface::create_category_user_can_create_courses_in($username, 'adler_manager'); -} - - -/** - * @param $language_code string language code. List of valid codes can be found at Site administration -> Language -> Language packs - * @return bool - */ -function is_language_pack_installed(string $language_code): bool { - $installed_langs = get_string_manager()->get_list_of_translations(); - return str_contains(implode('', $installed_langs), "($language_code)"); -} - -/** - * @param $language_code string language code. List of valid codes can be found at Site administration -> Language -> Language packs - * @return void - */ -function install_language_pack(string $language_code): void { - if (is_language_pack_installed($language_code)) { - cli_writeln("Language pack already installed"); - return; - } - - $lang_controller = new lang_controller(); - try { - $result = $lang_controller->install_languagepacks($language_code); - if ($result == 1) { - cli_writeln("Language \"" . $language_code . "\" was installed"); - } else { - cli_error("Language \"" . $language_code . "\" was not installed. The reason is unknown due to moodle limitations."); - } - } catch (Exception $e) { - cli_error("Failed to install language pack \"$language_code\". Reason: " . $e->getMessage()); - } -} diff --git a/opt/adler/moodle/adler_setup/setup.php b/opt/adler/moodle/adler_setup/setup.php deleted file mode 100644 index f8f1584..0000000 --- a/opt/adler/moodle/adler_setup/setup.php +++ /dev/null @@ -1,145 +0,0 @@ -libdir . "/clilib.php"); -require_once($CFG->libdir . "/moodlelib.php"); -require_once($CFG->libdir . "/accesslib.php"); -require_once("lib.php"); - - -## cli opts -$help = "Command line tool to uninstall plugins. - -Options: - -h --help Print this help. - --first_run Set this flag if this script is run the first time - --user_name Comma seperated list of users that will be created during first_run. Per default the users do not have any special permissions, it will be a default \"student\". This field will be the login name and used as default value for optional fields. Name and password parameters are required if this user should be created. To add multiple users use for example --user_name=user1,user,user3. All used switches have to have the same array length. Use false if you want the default behavior (eg --user_first_name=John,false,Peter) - --user_password Passwords are not allowed to contain \",\". Passwords have to follow moodle password validation rules. - --user_first_name See user_name for further information. - --user_last_name See user_name for further information. - --user_email See user_name for further information. - --user_role shortname of role. See user_name for further information. - --user_create_adler_course_category true: create a course category for the user and assign the account to the adler_manager role in the context of this course category. See user_name for further information. -"; - -list($options, $unrecognised) = cli_get_params([ - 'help' => false, - 'first_run' => false, - 'user_name' => false, - 'user_password' => false, - 'user_first_name' => false, - 'user_last_name' => false, - 'user_email' => false, - 'user_role' => false, - 'user_create_adler_course_category' => false, -], []); - -if ($unrecognised) { - $unrecognised = implode(PHP_EOL . ' ', $unrecognised); - cli_error('unknown option(s):' . $unrecognised); -} - -if ($options['help']) { - cli_writeln($help); - exit(0); -} - -# cast boolean cli opts -$options['first_run'] = $options['first_run'] == "true"; -## end cli opts -cli_writeln('CLI options: ' . json_encode((object) array_merge((array) $options, ['user_password' => '***']))); - - -function do_adler_roles_exist() { - $roles = get_all_roles(); - $filtered_roles = array_filter($roles, function($role) { - return $role->name == 'adler_manager'; - }); - - return !empty($filtered_roles); -} - -// check if adler roles already exist -if (do_adler_roles_exist()) { - cli_writeln("adler roles already exist"); -} else { - // create adler role - $role_adler_manager_id = create_role('adler_manager', 'adler_manager', 'Manager for adler courses. Has all permissions required to work with the authoring tool.', 'user'); - $capabilities_adler_manager = [ - 'moodle/course:delete', - 'moodle/course:enrolconfig', - 'moodle/question:add', - 'moodle/question:managecategory', - 'moodle/restore:configure', - 'moodle/restore:restoreactivity', - 'moodle/restore:restorecourse', - 'moodle/restore:restoresection', - 'moodle/restore:restoretargetimport', - 'moodle/restore:rolldates', - 'moodle/restore:uploadfile', - 'moodle/restore:userinfo', - 'moodle/restore:viewautomatedfilearea' - ]; - foreach ($capabilities_adler_manager as $capability) { - assign_capability($capability, CAP_ALLOW, $role_adler_manager_id, context_system::instance()); - } - // set context levels where the role can be assigned - $contextlevels = [ - CONTEXT_COURSECAT, - ]; - set_role_contextlevels($role_adler_manager_id, $contextlevels); -} - - -if ($options['first_run']) { - // enable webservices - set_config('enablewebservices', true); - - // Enable REST server. - $activeprotocols = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols); - - if (!in_array('rest', $activeprotocols)) { - $activeprotocols[] = 'rest'; - $updateprotocol = true; - } - - if ($updateprotocol) { - set_config('webserviceprotocols', implode(',', $activeprotocols)); - } - - // enable login for webservices other than moodle mobile service - $cap = new stdClass(); - $cap->contextid = 1; // no idea what this is for, but it seems this is always 1 - $cap->roleid = $role_id = $DB->get_record('role', array('shortname' => 'user'))->id; # role id of "authenticated user" - $cap->capability = 'moodle/webservice:createtoken'; - $cap->permission = 1; // no idea what this is for, but it seems this is always 1 - $cap->timemodified = time(); - $cap->modifierid = 0; - $DB->insert_record('role_capabilities', $cap); - - // enable rest:use for webservices other than moodle mobile service - $cap = new stdClass(); - $cap->contextid = 1; // no idea what this is for, but it seems this is always 1 - $cap->roleid = $role_id = $DB->get_record('role', array('shortname' => 'user'))->id; # role id of "authenticated user" - $cap->capability = 'webservice/rest:use'; - $cap->permission = 1; // no idea what this is for, but it seems this is always 1 - $cap->timemodified = time(); - $cap->modifierid = 0; - $DB->insert_record('role_capabilities', $cap); - - // create users - if ($options['user_name']) { - cli_writeln("creating user(s)"); - create_users($options); - } - - // activate german language pack - install_language_pack('de'); -} \ No newline at end of file diff --git a/opt/adler/setup.sh b/opt/adler/setup.sh index b42a584..09839b2 100755 --- a/opt/adler/setup.sh +++ b/opt/adler/setup.sh @@ -1,26 +1,59 @@ #!/bin/bash +set -e -if test -f /bitnami/moodle/adler_setup/setup.php; then - echo "adler setup.php exists -> this is not the first run" - first_run=false -else - echo "adler setup.php does not exists -> this is the first run" - first_run=true -fi +cd /bitnami/moodle + +#### install declarativesetup if not exists +# Define the directory and URL +DECLARATIVESETUP_VERSION=$(jq -r '.[] | select(.name == "local_declarativesetup") | .version' /opt/adler/plugins.json) +DECLARATIVESETUP_REPO=$(jq -r '.[] | select(.name == "local_declarativesetup") | .package_repo' /opt/adler/plugins.json) +TARGET_DIR="local/declarativesetup" +ZIP_URL="$DECLARATIVESETUP_REPO/local_declarativesetup/$DECLARATIVESETUP_VERSION.zip" +ZIP_FILE="/tmp/local_declarativesetup_$DECLARATIVESETUP_VERSION.zip" -rm -r -f /bitnami/moodle/adler_setup # cleanup first -cp -r /opt/adler/moodle/adler_setup /bitnami/moodle/ -chown -R daemon /bitnami/moodle/adler_setup +# Check if the directory exists +echo "Checking if $TARGET_DIR exists" +if [ ! -d "$TARGET_DIR" ]; then + echo "Directory $TARGET_DIR does not exist. Downloading and extracting the zip file: $ZIP_URL" -su daemon -s /bin/sh -c "php /bitnami/moodle/adler_setup/install_plugins.php ${PLUGIN_VERSION:+--plugin_version=\"$PLUGIN_VERSION\"} ${DEVELOP_DONT_INSTALL_PLUGINS:+--develop_dont_install_plugins=\"$DEVELOP_DONT_INSTALL_PLUGINS\"}" -if [ $? -ne 0 ]; then - echo "install_plugins.php failed" + # Download the zip file + curl -f -o "$ZIP_FILE" "$ZIP_URL" + if [ $? -ne 0 ]; then + echo "Failed to download the zip file from $ZIP_URL" exit 1 -fi -su daemon -s /bin/sh -c "php /bitnami/moodle/adler_setup/setup.php --first_run=\"$first_run\" ${USER_NAME:+--user_name=\"$USER_NAME\"} ${USER_PASSWORD:+--user_password=\"$USER_PASSWORD\"} ${USER_FIRST_NAME:+--user_first_name=\"$USER_FIRST_NAME\"} ${USER_LAST_NAME:+--user_last_name=\"$USER_LAST_NAME\"} ${USER_EMAIL:+--user_email=\"$USER_EMAIL\"} ${USER_ROLE:+--user_role=\"$USER_ROLE\"} ${USER_CREATE_ADLER_COURSE_CATEGORY:+--user_create_adler_course_category=\"$USER_CREATE_ADLER_COURSE_CATEGORY\"}" -if [ $? -ne 0 ]; then - echo "setup.php failed" + fi + + # Extract the zip file to the target directory + unzip -q "$ZIP_FILE" -d "$(dirname "$TARGET_DIR")" + if [ $? -ne 0 ]; then + echo "Failed to extract the zip file to $TARGET_DIR" + exit 1 + fi + + # Clean up the zip file + rm "$ZIP_FILE" + + # Run the upgrade script + php admin/cli/upgrade.php --non-interactive + + if [ $? -ne 0 ]; then + echo "Upgrade script failed" exit 1 + fi +else + echo "Directory $TARGET_DIR already exists. Skipping download and extraction." fi +#### install main playbook (installing all plugins and potential further playbooks) +echo "installing adler playbook" +ADLER_PLAYBOOK_VERSION=$(jq -r '.[] | select(.name == "playbook_adler") | .version' /opt/adler/plugins.json) +# TODO: package repo or github repo from version.json +php local/declarativesetup/cli/install_plugin.php --package-repo=https://packages.projekt-adler.eu/packages/playbook_adler --version="$ADLER_PLAYBOOK_VERSION" --moodle-name=playbook_adler +# copy plugins.json to playbook +cp /opt/adler/plugins.json local/declarativesetup/playbook/adler/files/plugins.json + +#### run playbooks +echo "running adler playbook" +php local/declarativesetup/cli/run_playbook.php --playbook=adler --roles="$ADLER_PLAYBOOK_ROLES" + echo "finished adler setup/update script" diff --git a/plugin-releases.json b/plugin-releases.json deleted file mode 100644 index 6e9e0c8..0000000 --- a/plugin-releases.json +++ /dev/null @@ -1,286 +0,0 @@ -{ - "common_versions": { - "main": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "main", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "main", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "main", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - }, - { - "git_project": "ProjektAdLer/MoodlePluginLocalLogging", - "version": "main", - "path": "/local/logging", - "name": "local_logging" - } - ], - "1.0.0": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "1.0.0", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "1.0.0", - "path": "/availability/condition/adler", - "name": "availability_adler" - } - ], - "2.0.0-rc": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "2.0.0-rc.2", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "2.0.0-rc.1", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "2.0.0-rc.3", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - } - ], - "2.0.0": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "2.0.0", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "2.0.0", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "2.0.0", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - } - ], - "3.0.0": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "3.0.0", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "3.0.0", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "2.1.0", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - } - ], - "3.1.0": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "3.1.0", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "3.0.0", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "2.1.0", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - }, - { - "git_project": "ProjektAdLer/MoodlePluginLocalLogging", - "version": "0.1.0", - "path": "/local/logging", - "name": "local_logging" - } - ], - "3.2.0": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "3.2.0", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "3.0.1", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "2.2.0", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - }, - { - "git_project": "ProjektAdLer/MoodlePluginLocalLogging", - "version": "0.2.0", - "path": "/local/logging", - "name": "local_logging" - } - ], - "4.0.0-rc.1": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "4.0.0-rc.1", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "3.0.1", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "2.2.0", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - }, - { - "git_project": "ProjektAdLer/MoodlePluginLocalLogging", - "version": "0.2.0", - "path": "/local/logging", - "name": "local_logging" - } - ], - "4.0.0": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "4.0.0", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "3.0.1", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "2.2.0", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - }, - { - "git_project": "ProjektAdLer/MoodlePluginLocalLogging", - "version": "0.2.0", - "path": "/local/logging", - "name": "local_logging" - } - ], - "4.0.1": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "4.0.1", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "3.0.1", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "2.2.0", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - }, - { - "git_project": "ProjektAdLer/MoodlePluginLocalLogging", - "version": "0.2.0", - "path": "/local/logging", - "name": "local_logging" - } - ], - "5.0.0-rc.1": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "5.0.0-rc.1", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "3.0.1", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "3.0.0-rc.1", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - }, - { - "git_project": "ProjektAdLer/MoodlePluginLocalLogging", - "version": "0.2.0", - "path": "/local/logging", - "name": "local_logging" - } - ], - "5.0.0-rc.2": [ - { - "git_project": "ProjektAdLer/MoodlePluginLocal", - "version": "5.0.0-rc.2", - "path": "/local/adler", - "name": "local_adler" - }, - { - "git_project": "ProjektAdler/MoodlePluginAvailability", - "version": "3.0.1", - "path": "/availability/condition/adler", - "name": "availability_adler" - }, - { - "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", - "version": "3.0.0-rc.1", - "path": "/mod/adleradaptivity", - "name": "mod_adleradaptivity" - }, - { - "git_project": "ProjektAdLer/MoodlePluginLocalLogging", - "version": "0.2.0", - "path": "/local/logging", - "name": "local_logging" - } - ] - } -} diff --git a/plugins.json b/plugins.json new file mode 100644 index 0000000..6ee555d --- /dev/null +++ b/plugins.json @@ -0,0 +1,32 @@ +[ + { + "package_repo": "https://packages.projekt-adler.eu/packages/moodle/", + "version": "0.1.0", + "name": "local_declarativesetup" + }, + { + "package_repo": "https://packages.projekt-adler.eu/packages/moodle/", + "version": "0.1.0", + "name": "playbook_adler" + }, + { + "git_project": "ProjektAdLer/MoodlePluginLocal", + "version": "5.0.0", + "name": "local_adler" + }, + { + "git_project": "ProjektAdler/MoodlePluginAvailability", + "version": "4.0.1", + "name": "availability_adler" + }, + { + "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", + "version": "3.0.0", + "name": "mod_adleradaptivity" + }, + { + "git_project": "ProjektAdLer/MoodlePluginLocalLogging", + "version": "1.0.0", + "name": "local_logging" + } +] diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml deleted file mode 100644 index 8e63ea4..0000000 --- a/tests/docker-compose.yml +++ /dev/null @@ -1,56 +0,0 @@ -version: '3' -services: - moodle: - build: - context: .. - args: -# PLUGIN_VERSION: main - PLUGIN_VERSION: 3.1.0 - MOODLE_VERSION: 4.3 - ports: - - '8000:8080' - environment: - DEVELOP_DONT_INSTALL_PLUGINS: false - PHP_OUTPUT_BUFFERING: 8192 - PHP_POST_MAX_SIZE: 2048M - PHP_UPLOAD_MAX_FILESIZE: 2048M - MOODLE_DATABASE_HOST: db_moodle - MOODLE_DATABASE_PORT_NUMBER: 3306 - MOODLE_DATABASE_USER: moodle - MOODLE_DATABASE_PASSWORD: moodle - MOODLE_DATABASE_NAME: moodle - USER_NAME: student,manager - USER_PASSWORD: Student1234!1234,Manager1234!1234 - USER_ROLE: false,false - USER_CREATE_ADLER_COURSE_CATEGORY: "false, true" - BITNAMI_DEBUG: true - volumes: - - moodle_moodle:/bitnami/moodle - - moodle_moodledata:/bitnami/moodledata - depends_on: - - db_moodle - restart: unless-stopped - - db_moodle: - image: bitnami/mariadb:10.11 - ports: - - '3306:3306' - environment: - MARIADB_USER: moodle - MARIADB_PASSWORD: moodle - MARIADB_ROOT_PASSWORD: root_pw - MARIADB_DATABASE: moodle - MARIADB_CHARACTER_SET: utf8mb4 - MARIADB_COLLATE: utf8mb4_unicode_ci - volumes: - - db_moodle_data:/bitnami/mariadb - restart: unless-stopped - - -volumes: - moodle_moodle: - driver: local - moodle_moodledata: - driver: local - db_moodle_data: - driver: local diff --git a/tests/test.sh b/tests/test.sh deleted file mode 100755 index 166bcac..0000000 --- a/tests/test.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - -# fail if one command fails -set -e - -# Set variables -username="manager" -password='Manager1234!1234' -hostname="localhost" -port="8000" - -if [ $(id -u) -ne 0 ] - then echo "Please run as root" - exit 1 -fi - -apt update && apt install -y curl jq - -docker compose down -v -docker compose up -d --build - -echo "docker containers starting" - -# Check if the container is ready -set +e -COUNT=0 -COUNT_MAX=100 -while [ $COUNT -lt $COUNT_MAX ]; do - curl -f -s -LI http://${hostname}:${port} > /dev/null - if [ $? -eq 0 ] - then - break - fi - echo "Moodle still starting... This will typically take between 1 and 3 minutes. $((COUNT * 5)) seconds passed" - sleep 5 - COUNT=$((COUNT + 1)) -done -set -e -# output docker logs -docker compose logs - -# If the container is not ready, exit with an error -if [ $COUNT -eq $COUNT_MAX ]; then - echo "Container did not become ready in time" - exit 1 -fi - -echo "moodle is ready, starting with curl" - -# Get token -token_response=$(curl --location "http://${hostname}:${port}/login/token.php?username=${username}&password=${password}&service=adler_services" -s) - -# Extract token from response -echo "response is $token_response" -token=$(echo "$token_response" | jq -r '.token') -echo "token is $token" - -# Upload course -course_fullname=$(curl --location "http://${hostname}:${port}/webservice/rest/server.php" \ - --form "wstoken=${token}" \ - --form "wsfunction=local_adler_upload_course" \ - --form "moodlewsrestformat=json" \ - --form "mbz=@testworld.mbz" \ - | jq -r '.data.course_fullname') -if [ "$course_fullname" != "test" ]; then - exit 1 -fi -printf "course upload successful, name is $course_fullname \n" - -# Search uploaded course and get course ID -new_course_id=$(curl --location "http://${hostname}:${port}/webservice/rest/server.php" \ - --form "wstoken=${token}" \ - --form "wsfunction=core_course_search_courses" \ - --form "moodlewsrestformat=json" \ - --form "criterianame=search" \ - --form "criteriavalue=${course_fullname}" \ - | jq -r '.courses[0].id') -if [ "$new_course_id" != "2" ]; then - exit 1 -fi -printf "found course, has id $new_course_id \n" - -# Get total number of courses and verify it equals 1 -total_matching_courses=$(curl --location "http://${hostname}:${port}/webservice/rest/server.php" \ - --form "wstoken=${token}" \ - --form "wsfunction=core_course_search_courses" \ - --form "moodlewsrestformat=json" \ - --form "criterianame=search" \ - --form "criteriavalue=${course_fullname}" \ - | jq -r '.total') -if [ "$total_matching_courses" -ne 1 ]; then - exit 1 -fi -printf "found exactly one course \n" - -docker compose down -v diff --git a/tests/testworld.mbz b/tests/testworld.mbz deleted file mode 100644 index 64be169..0000000 Binary files a/tests/testworld.mbz and /dev/null differ