Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Commit

Permalink
Merge branch 'moodle_dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Glutamat42 committed Oct 31, 2023
2 parents 234c416 + 922ce4f commit 11c5dd1
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 35 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
72 changes: 39 additions & 33 deletions opt/adler/moodle/adler_setup/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
58 changes: 58 additions & 0 deletions plugin-releases.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
2 changes: 1 addition & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11c5dd1

Please sign in to comment.