diff --git a/Dockerfile b/Dockerfile index c97c1b5..466d578 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ FROM bitnami/moodle:${MOODLE_VERSION} RUN apt update && apt install curl unzip nano -y COPY opt/adler /opt/adler +COPY plugin-releases.json /opt/adler/moodle/adler_setup # 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} diff --git a/opt/adler/moodle/adler_setup/setup.php b/opt/adler/moodle/adler_setup/setup.php index 9e58a2a..93cf2f2 100644 --- a/opt/adler/moodle/adler_setup/setup.php +++ b/opt/adler/moodle/adler_setup/setup.php @@ -114,47 +114,53 @@ } } +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"); -// install plugins - if ($options['plugin_version'] == 'main') { - $plugins = [ - [ - "path" => $CFG->dirroot . "/local/adler", - "url" => "https://github.com/ProjektAdLer/MoodlePluginLocal/archive/refs/heads/main.zip" - ], - [ - "path" => $CFG->dirroot . "/availability/condition/adler", - "url" => "https://github.com/ProjektAdLer/MoodlePluginAvailability/archive/refs/heads/main.zip" - ], - ]; - } else { - $plugins = []; - $info = get_updated_release_info( - "ProjektAdLer/MoodlePluginLocal", - $options['plugin_version'], - core_plugin_manager::instance()->get_plugin_info('local_adler')->release - ); - if ($info) { - $plugins[] = [ - "path" => $CFG->dirroot . "/local/adler", - "url" => $info->zip_url - ]; - } - $info = get_updated_release_info( - "ProjektAdler/MoodlePluginAvailability", - $options['plugin_version'], - core_plugin_manager::instance()->get_plugin_info('local_adler')->release - ); - if ($info) { + + $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) { + $url = $info->zip_url; + } else { + cli_error("Failed to get release info"); + } + } else { + // plugin is a branch + $url = "https://github.com/" . $plugin['url'] . "/archive/refs/heads/" . $plugin['version'] . ".zip"; + } + + /** @noinspection PhpUndefinedVariableInspection */ $plugins[] = [ - "path" => $CFG->dirroot . "/availability/condition/adler", - "url" => $info->zip_url + "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); diff --git a/plugin-releases.json b/plugin-releases.json new file mode 100644 index 0000000..a8448ef --- /dev/null +++ b/plugin-releases.json @@ -0,0 +1,58 @@ +{ + "common_versions": { + "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" + } + ], + "main": [ + { + "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" + }, + { + "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", + "version": "1.0.0", + "path": "/mod/adleradaptivity", + "name": "mod_adleradaptivity" + } + ], + "2.0.0-rc": [ + { + "git_project": "ProjektAdLer/MoodlePluginLocal", + "version": "2.0.0-rc.1", + "path": "/local/adler", + "name": "local_adler" + }, + { + "git_project": "ProjektAdler/MoodlePluginAvailability", + "version": "1.0.0", + "path": "/availability/condition/adler", + "name": "availability_adler" + }, + { + "git_project": "ProjektAdLer/MoodlePluginModAdleradaptivity", + "version": "2.0.0-rc.2", + "path": "/mod/adleradaptivity", + "name": "mod_adleradaptivity" + } + ] + } +} diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index d086729..31c0398 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -4,7 +4,7 @@ services: build: context: .. args: - PLUGIN_VERSION: 1.0.0 + PLUGIN_VERSION: 2.0.0-rc MOODLE_VERSION: 4.2 ports: - '8000:8080' diff --git a/tests/test.sh b/tests/test.sh index 1be42c2..ce17f4c 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -31,7 +31,7 @@ while [ $COUNT -lt $COUNT_MAX ]; do then break fi - echo "moodle still starting... This will typically take between 1 and 3 minutes" + echo "Moodle still starting... This will typically take between 1 and 3 minutes. $((COUNT * 5)) seconds passed" sleep 5 COUNT=$((COUNT + 1)) done