diff --git a/roles/web-app-joomla/README.md b/roles/web-app-joomla/README.md
index 02fbed3f86..14c8d91fb2 100644
--- a/roles/web-app-joomla/README.md
+++ b/roles/web-app-joomla/README.md
@@ -80,6 +80,19 @@ Its enablement derives directly from the `sso` service flag, and its OIDC runtim
- **External database:** Persist Joomla content in the project's central RDBMS through the standard role-meta wiring.
- **NGINX reverse proxy:** Front the Joomla container with the project's `sys-stk-front-proxy` for TLS termination and per-domain routing.
+## Core Updates
+
+The Joomla image copies its core into the `joomla_data` volume only while that volume is empty. Every deploy compares three versions: the core files in the volume (`libraries/src/Version.php`), the version the database was last finalised for (the `files_joomla` manifest cache) and the core of the pinned image (`/usr/src/joomla`).
+
+When the site is behind the image, [`tasks/upgrade/`](./tasks/upgrade/) steps it forward one update at a time, planned by [`filter_plugins/joomla_core.py`](./filter_plugins/joomla_core.py):
+
+- A site on an older major first moves to that major's bridge release, listed under `services.joomla.upgrade.bridges` in [`meta/services.yml`](./meta/services.yml). The deploy downloads the bridge's official update package from the Joomla GitHub releases and checks its SHA-256 before use.
+- Before a major is left, the deploy sets the plugin states the bridge entry lists, which are the pre-conditions of Joomla's own `core:update`.
+- Each step lays the update files over the volume, then runs Joomla's own `finaliseUpgrade` through [`files/php/core_update.php`](./files/php/core_update.php), which applies the schema updates and the core update script, and checks the database structure before and after.
+- A core at or above the image's core is left untouched; the image pin only sets the floor. A code volume and a database that disagree above the pin stop the deploy, as does an older major without a declared bridge.
+
+The SSO plugin task requires a core of `6.1.0` or later, the first release with `cli/joomla.php extension:enable`.
+
## Quick Setup
### Development
diff --git a/roles/web-app-joomla/files/php/core_update.php b/roles/web-app-joomla/files/php/core_update.php
new file mode 100644
index 0000000000..702f71cacb
--- /dev/null
+++ b/roles/web-app-joomla/files/php/core_update.php
@@ -0,0 +1,188 @@
+alias('session', 'session.cli')
+ ->alias('JSession', 'session.cli')
+ ->alias(\Joomla\CMS\Session\Session::class, 'session.cli')
+ ->alias(\Joomla\Session\Session::class, 'session.cli')
+ ->alias(\Joomla\Session\SessionInterface::class, 'session.cli');
+
+$app = $container->get(\Joomla\Console\Application::class);
+Factory::$application = $app;
+
+$app->addCommand(new class () extends AbstractCommand {
+ protected static $defaultName = 'infinito:core';
+
+ protected function configure(): void
+ {
+ $this->setDescription('Report, check, prepare and finalise a Joomla core update');
+ $this->addArgument('action', InputArgument::REQUIRED, 'version | schema | plugins | finalise');
+ }
+
+ protected function doExecute(InputInterface $input, OutputInterface $output): int
+ {
+ $language = $this->getApplication()->getLanguage();
+ foreach (['lib_joomla', '', 'com_installer', 'com_joomlaupdate'] as $extension) {
+ $language->load($extension, JPATH_ADMINISTRATOR);
+ }
+
+ return match ($input->getArgument('action')) {
+ 'version' => $this->version($output),
+ 'schema' => $this->schema($output),
+ 'plugins' => $this->plugins(preg_split('/\s+/', trim((string) getenv('J_PLUGINS')), -1, PREG_SPLIT_NO_EMPTY), $output),
+ 'finalise' => $this->finalise($output),
+ };
+ }
+
+ private function version(OutputInterface $output): int
+ {
+ $manifest = json_decode((string) ExtensionHelper::getExtensionRecord('joomla', 'file')->manifest_cache, true);
+ if (!is_array($manifest) || !isset($manifest['version'])) {
+ $output->writeln('files_joomla carries no version in its manifest cache');
+
+ return 1;
+ }
+ $output->writeln('database-version=' . $manifest['version']);
+
+ return 0;
+ }
+
+ private function databaseModel(int $extensionId)
+ {
+ $app = $this->getApplication();
+ $model = $app->bootComponent('com_installer')->getMVCFactory($app)->createModel('Database', 'Administrator');
+ $model->setState('filter.extension_id', $extensionId);
+
+ return $model;
+ }
+
+ /** @return list */
+ private function schemaErrors(int $extensionId): array
+ {
+ $item = $this->databaseModel($extensionId)->getItems()[0];
+
+ return $item['errorsCount'] > 0 ? array_map('strip_tags', $item['errorsMessage']) : [];
+ }
+
+ private function schema(OutputInterface $output): int
+ {
+ $coreId = (int) ExtensionHelper::getExtensionRecord('joomla', 'file')->extension_id;
+ $errors = $this->schemaErrors($coreId);
+ if ($errors === []) {
+ $output->writeln('schema ' . JVERSION . ': up to date');
+
+ return 0;
+ }
+
+ foreach ($errors as $error) {
+ $output->writeln('schema ' . JVERSION . ': ' . $error);
+ }
+ $this->databaseModel($coreId)->fix([$coreId]);
+
+ $errors = $this->schemaErrors($coreId);
+ foreach ($errors as $error) {
+ $output->writeln('schema ' . JVERSION . ' after fix: ' . $error . '');
+ }
+ $output->writeln('schema ' . JVERSION . ': ' . ($errors === [] ? 'fixed' : 'still out of date'));
+
+ return $errors === [] ? 0 : 1;
+ }
+
+ /** @param list $pairs */
+ private function plugins(array $pairs, OutputInterface $output): int
+ {
+ $db = Factory::getContainer()->get(DatabaseInterface::class);
+ foreach ($pairs as $pair) {
+ if (!preg_match('#^([a-z0-9_-]+)/([a-z0-9_-]+)=([01])$#', $pair, $match)) {
+ $output->writeln("plugin state '$pair' is not folder/element=0|1");
+
+ return 1;
+ }
+ [, $folder, $element, $enabled] = $match;
+ $where = static fn ($query) => $query
+ ->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
+ ->where($db->quoteName('folder') . ' = ' . $db->quote($folder))
+ ->where($db->quoteName('element') . ' = ' . $db->quote($element));
+
+ $db->setQuery($where($db->createQuery()
+ ->update($db->quoteName('#__extensions'))
+ ->set($db->quoteName('enabled') . ' = ' . (int) $enabled)))->execute();
+ $state = $db->setQuery($where($db->createQuery()
+ ->select($db->quoteName('enabled'))
+ ->from($db->quoteName('#__extensions'))))->loadResult();
+
+ if ($state === null && $enabled === '0') {
+ $output->writeln("plugin $folder/$element: not installed");
+ continue;
+ }
+ if ((string) $state !== $enabled) {
+ $output->writeln("plugin $folder/$element could not be set to enabled=$enabled");
+
+ return 1;
+ }
+ $output->writeln("plugin $folder/$element: enabled=$state");
+ }
+
+ return 0;
+ }
+
+ private function finalise(OutputInterface $output): int
+ {
+ Log::addLogger(['logger' => 'echo'], Log::ALL & ~Log::DEBUG, ['Update']);
+
+ $app = $this->getApplication();
+ $model = $app->bootComponent('com_joomlaupdate')->getMVCFactory($app)->createModel('Update', 'Administrator');
+
+ $finalised = $model->finaliseUpgrade();
+ foreach ($model->getErrors() as $error) {
+ $output->writeln('finalise: ' . ($error instanceof \Throwable ? $error->getMessage() : (string) $error) . '');
+ }
+ if (!$finalised || $model->getErrors()) {
+ return 1;
+ }
+
+ $model->resetUpdateSource();
+ foreach ([JPATH_CACHE . '/autoload_psr4.php', JPATH_BASE . '/joomla.xml'] as $leftover) {
+ if (is_file($leftover) && !unlink($leftover)) {
+ $output->writeln("finalise: cannot remove $leftover");
+
+ return 1;
+ }
+ }
+ $model->purge();
+ $output->writeln('finalise: Joomla ' . JVERSION);
+
+ return 0;
+ }
+});
+
+$app->execute();
diff --git a/roles/web-app-joomla/filter_plugins/joomla_core.py b/roles/web-app-joomla/filter_plugins/joomla_core.py
new file mode 100644
index 0000000000..44ab440621
--- /dev/null
+++ b/roles/web-app-joomla/filter_plugins/joomla_core.py
@@ -0,0 +1,191 @@
+from __future__ import annotations
+
+import re
+
+from ansible.errors import AnsibleFilterError
+
+_PARTS = ("MAJOR", "MINOR", "PATCH")
+_BRIDGE_KEYS = ("version", "sha256", "plugins")
+_VERSION = re.compile(r"^(\d+)\.(\d+)\.(\d+)$")
+_DATABASE_VERSION = re.compile(r"^database-version=(\S+)$", re.MULTILINE)
+_SHA256 = re.compile(r"^[0-9a-f]{64}$")
+_PLUGIN = re.compile(r"^[a-z0-9_-]+/[a-z0-9_-]+$")
+
+
+def _parse(version) -> tuple[int, int, int]:
+ match = _VERSION.match(str(version))
+ if match is None:
+ raise AnsibleFilterError(
+ f"'{version}' is not a Joomla core version of the form MAJOR.MINOR.PATCH"
+ )
+ return tuple(int(part) for part in match.groups())
+
+
+def _render(version: tuple[int, int, int]) -> str:
+ return ".".join(str(part) for part in version)
+
+
+def joomla_core_version(version_php) -> str:
+ """Return the ``MAJOR.MINOR.PATCH`` a ``Version.php`` declares.
+
+ Args:
+ version_php: the text of ``libraries/src/Version.php``.
+
+ Returns:
+ The version of the core files, for example ``5.3.4``.
+ """
+ if not isinstance(version_php, str) or not version_php.strip():
+ raise AnsibleFilterError("joomla_core_version expects the text of Version.php")
+ numbers = []
+ for part in _PARTS:
+ match = re.search(rf"\bconst\s+{part}_VERSION\s*=\s*(\d+)\s*;", version_php)
+ if match is None:
+ raise AnsibleFilterError(f"Version.php declares no {part}_VERSION")
+ numbers.append(int(match.group(1)))
+ return _render(tuple(numbers))
+
+
+def joomla_core_database_version(output) -> str:
+ """Return the core version the database was last finalised for.
+
+ Args:
+ output: stdout of ``core_update.php version``, whose
+ ``database-version=`` line carries the version that
+ ``files_joomla`` records in its manifest cache.
+
+ Returns:
+ That version, for example ``5.3.4``.
+ """
+ matches = _DATABASE_VERSION.findall(output if isinstance(output, str) else "")
+ if len(matches) != 1:
+ raise AnsibleFilterError(
+ "expected exactly one database-version= line from core_update.php"
+ )
+ return _render(_parse(matches[0]))
+
+
+def _bridges_by_major(bridges) -> dict[int, dict]:
+ if not isinstance(bridges, list):
+ raise AnsibleFilterError("the Joomla bridge releases must be a list")
+ by_major: dict[int, dict] = {}
+ for bridge in bridges:
+ if not isinstance(bridge, dict) or set(bridge) != set(_BRIDGE_KEYS):
+ raise AnsibleFilterError(
+ f"a Joomla bridge release needs exactly {', '.join(_BRIDGE_KEYS)}: {bridge}"
+ )
+ version = _parse(bridge["version"])
+ if not _SHA256.match(str(bridge["sha256"])):
+ raise AnsibleFilterError(
+ f"Joomla bridge {_render(version)} carries no SHA-256 of its update package"
+ )
+ plugins = bridge["plugins"]
+ if not isinstance(plugins, dict) or not all(
+ _PLUGIN.match(str(name)) and isinstance(state, bool)
+ for name, state in plugins.items()
+ ):
+ raise AnsibleFilterError(
+ f"Joomla bridge {_render(version)} needs plugins as folder/element: true|false"
+ )
+ if version[0] in by_major:
+ raise AnsibleFilterError(
+ f"two Joomla bridge releases are declared for major {version[0]}"
+ )
+ by_major[version[0]] = {
+ "version": version,
+ "sha256": str(bridge["sha256"]),
+ "plugins": dict(plugins),
+ }
+ return by_major
+
+
+def _step(origin, version, bridge, plugins) -> dict:
+ return {
+ "from": _render(origin),
+ "version": _render(version),
+ "package": bridge is not None,
+ "sha256": bridge["sha256"] if bridge else "",
+ "plugins": [f"{name}={int(state)}" for name, state in plugins.items()],
+ "check": True,
+ }
+
+
+def joomla_core_upgrade_steps(database, files, target, bridges) -> list[dict]:
+ """Plan the core updates that bring the site up to ``target``.
+
+ Every step lays the files of its version over the code volume and then
+ finalises the database for it, so the plan starts at the version the
+ database was last finalised for. A volume whose files moved past that
+ point in an interrupted update gets those files laid again. A core at
+ or above ``target`` is left alone.
+
+ Args:
+ database: core version the database was last finalised for.
+ files: core version of the files in the code volume.
+ target: core version the pinned image ships.
+ bridges: list of ``{version, sha256, plugins}``, one per major the
+ core may leave. Joomla carries a major's schema changes only in
+ that major's packages, so a major is left from its bridge release
+ alone. ``sha256`` names the bridge's update package, ``plugins``
+ the ``folder/element: enabled`` states Joomla demands before the
+ major is left.
+
+ Returns:
+ Ordered steps ``{from, version, package, sha256, plugins, check}``.
+ A step with ``package`` true installs that bridge's update package,
+ the others the image's own tree; ``plugins`` lists
+ ``folder/element=0|1`` only on the step that leaves a major; ``check``
+ is false where the files in the volume no longer match ``from``, so
+ the pre-update schema check of the old code cannot run.
+ """
+ start = current = _parse(database)
+ laid = _parse(files)
+ goal = _parse(target)
+ by_major = _bridges_by_major(bridges)
+ if max(current, laid) > goal:
+ if current != laid:
+ raise AnsibleFilterError(
+ f"the Joomla code volume holds {_render(laid)} but the database was "
+ f"finalised for {_render(current)}, and the pinned image ships "
+ f"{_render(goal)}; finish that update inside Joomla, the deploy never "
+ "lays older files"
+ )
+ return []
+ steps: list[dict] = []
+ while current[0] < goal[0]:
+ bridge = by_major.get(current[0])
+ if bridge is None:
+ raise AnsibleFilterError(
+ f"no bridge release is declared for Joomla {current[0]}.x, so "
+ f"{_render(current)} has no update path to {_render(goal)}"
+ )
+ if current < bridge["version"]:
+ steps.append(_step(current, bridge["version"], bridge, {}))
+ current = bridge["version"]
+ landing = by_major.get(current[0] + 1)
+ if current[0] + 1 == goal[0]:
+ steps.append(_step(current, goal, None, bridge["plugins"]))
+ current = goal
+ elif landing is None:
+ raise AnsibleFilterError(
+ f"no bridge release is declared for Joomla {current[0] + 1}.x, so "
+ f"{_render(current)} has no update path to {_render(goal)}"
+ )
+ else:
+ steps.append(
+ _step(current, landing["version"], landing, bridge["plugins"])
+ )
+ current = landing["version"]
+ if current < goal or (not steps and laid != goal):
+ steps.append(_step(current, goal, None, {}))
+ if steps:
+ steps[0]["check"] = laid == start
+ return steps
+
+
+class FilterModule:
+ def filters(self):
+ return {
+ "joomla_core_version": joomla_core_version,
+ "joomla_core_database_version": joomla_core_database_version,
+ "joomla_core_upgrade_steps": joomla_core_upgrade_steps,
+ }
diff --git a/roles/web-app-joomla/meta/services.yml b/roles/web-app-joomla/meta/services.yml
index 282f2caffb..f913d47cf5 100644
--- a/roles/web-app-joomla/meta/services.yml
+++ b/roles/web-app-joomla/meta/services.yml
@@ -44,6 +44,13 @@ joomla:
enabled: true
image: joomla
version: 6.1.4-php8.3-apache
+ upgrade:
+ bridges:
+ - version: 5.4.9
+ sha256: 7840541ae606bd460d4bf3647c977699af279c229f708756c78a2dcc06cfc8cf
+ plugins:
+ behaviour/compat: false
+ behaviour/compat6: true
custom: true
name: joomla
min_storage: 478MB
diff --git a/roles/web-app-joomla/tasks/02_manager_ops.yml b/roles/web-app-joomla/tasks/02_manager_ops.yml
index 71bbcede6c..3946969ec0 100644
--- a/roles/web-app-joomla/tasks/02_manager_ops.yml
+++ b/roles/web-app-joomla/tasks/02_manager_ops.yml
@@ -15,6 +15,9 @@
loop_control:
loop_var: joomla_step
+- name: "โฌ๏ธ Update the Joomla core up to the core of the pinned image"
+ include_tasks: upgrade/main.yml
+
- name: ๐ Include assert routines
include_tasks: "06_assert.yml"
when: MODE_ASSERT_LOCAL | bool
diff --git a/roles/web-app-joomla/tasks/08_oidc_plugin.yml b/roles/web-app-joomla/tasks/08_oidc_plugin.yml
index 037239a96c..03572661f2 100644
--- a/roles/web-app-joomla/tasks/08_oidc_plugin.yml
+++ b/roles/web-app-joomla/tasks/08_oidc_plugin.yml
@@ -1,4 +1,14 @@
---
+- name: "๐ง Require a Joomla core that provides extension:enable"
+ ansible.builtin.assert:
+ that:
+ - JOOMLA_CORE_FILES is version(JOOMLA_CLI_EXTENSION_ENABLE_SINCE, '>=')
+ fail_msg: >-
+ plg_system_keycloak is enabled through `cli/joomla.php extension:enable`, which Joomla
+ ships from {{ JOOMLA_CLI_EXTENSION_ENABLE_SINCE }}; the core is at {{ JOOMLA_CORE_FILES }}.
+ Pin a Joomla image of {{ JOOMLA_CLI_EXTENSION_ENABLE_SINCE }} or later, or switch SSO off.
+ quiet: true
+
- name: "๐ Define OIDC plugin paths"
ansible.builtin.set_fact:
JOOMLA_OIDC_PLUGIN_HOST_DIR: "{{ role_path }}/files/joomla-oidc-plugin"
diff --git a/roles/web-app-joomla/tasks/upgrade/core_update.yml b/roles/web-app-joomla/tasks/upgrade/core_update.yml
new file mode 100644
index 0000000000..0698151905
--- /dev/null
+++ b/roles/web-app-joomla/tasks/upgrade/core_update.yml
@@ -0,0 +1,28 @@
+---
+# Param: joomla_core_action - core_update.php action: version | schema | plugins | finalise
+# Param: joomla_core_plugins - space-separated folder/element=0|1 states for the plugins action, "" otherwise
+- name: "๐งฉ Run the Joomla core_update.php '{{ joomla_core_action }}' action"
+ ansible.builtin.command:
+ argv:
+ - container
+ - exec
+ - -i
+ - --user
+ - "{{ JOOMLA_WEB_USER }}"
+ - -e
+ - "J_ROOT={{ JOOMLA_DOCROOT }}"
+ - -e
+ - "J_PLUGINS={{ joomla_core_plugins }}"
+ - "{{ JOOMLA_LOCAL_CID }}" # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
+ - php
+ - -d
+ - "memory_limit={{ JOOMLA_PHP_MEMORY_LIMIT }}"
+ - --
+ - "infinito:core"
+ - "{{ joomla_core_action }}"
+ stdin: "{{ lookup('file', role_path ~ '/files/php/core_update.php') }}"
+ register: joomla_core_update
+ changed_when: >-
+ joomla_core_action in ['plugins', 'finalise']
+ or (joomla_core_action == 'schema' and 'fixed' in joomla_core_update.stdout)
+ delegate_to: "{{ JOOMLA_HOST_NODE }}"
diff --git a/roles/web-app-joomla/tasks/upgrade/detect.yml b/roles/web-app-joomla/tasks/upgrade/detect.yml
new file mode 100644
index 0000000000..b6532b22bb
--- /dev/null
+++ b/roles/web-app-joomla/tasks/upgrade/detect.yml
@@ -0,0 +1,29 @@
+---
+- name: "๐ Read Version.php of the code volume and of the image tree"
+ ansible.builtin.command:
+ argv:
+ - container
+ - exec
+ - "{{ JOOMLA_LOCAL_CID }}" # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
+ - cat
+ - "{{ [joomla_core_tree, JOOMLA_VERSION_PHP] | path_join }}"
+ loop:
+ - "{{ JOOMLA_DOCROOT }}"
+ - "{{ JOOMLA_IMAGE_SOURCE_DIR }}"
+ loop_control:
+ loop_var: joomla_core_tree
+ register: joomla_version_php
+ changed_when: false
+ delegate_to: "{{ JOOMLA_HOST_NODE }}"
+
+- name: "๐ Read the core version the Joomla database was finalised for"
+ ansible.builtin.include_tasks: core_update.yml
+ vars:
+ joomla_core_action: version
+ joomla_core_plugins: ""
+
+- name: "๐ Record the Joomla core versions of database, code volume and image"
+ ansible.builtin.set_fact:
+ JOOMLA_CORE_DATABASE: "{{ joomla_core_update.stdout | joomla_core_database_version }}"
+ JOOMLA_CORE_FILES: "{{ joomla_version_php.results[0].stdout | joomla_core_version }}"
+ JOOMLA_CORE_TARGET: "{{ joomla_version_php.results[1].stdout | joomla_core_version }}"
diff --git a/roles/web-app-joomla/tasks/upgrade/main.yml b/roles/web-app-joomla/tasks/upgrade/main.yml
new file mode 100644
index 0000000000..3c814b0aaa
--- /dev/null
+++ b/roles/web-app-joomla/tasks/upgrade/main.yml
@@ -0,0 +1,31 @@
+---
+- name: "๐ Detect the Joomla core versions"
+ ansible.builtin.include_tasks: detect.yml
+
+- name: "๐งญ Plan the Joomla core update up to the image's core"
+ ansible.builtin.set_fact:
+ JOOMLA_CORE_UPGRADE_STEPS: "{{ JOOMLA_CORE_DATABASE | joomla_core_upgrade_steps(JOOMLA_CORE_FILES, JOOMLA_CORE_TARGET, JOOMLA_UPGRADE_BRIDGES) }}"
+
+- name: "๐งญ Show the Joomla core update plan"
+ ansible.builtin.debug:
+ msg: >-
+ Joomla core: database {{ JOOMLA_CORE_DATABASE }}, code volume {{ JOOMLA_CORE_FILES }},
+ image {{ JOOMLA_CORE_TARGET }};
+ steps: {{ JOOMLA_CORE_UPGRADE_STEPS | map(attribute='version') | join(' -> ') or 'none' }}
+
+- name: "โฌ๏ธ Update the Joomla core step by step"
+ ansible.builtin.include_tasks: step.yml
+ loop: "{{ JOOMLA_CORE_UPGRADE_STEPS }}"
+ loop_control:
+ loop_var: joomla_core_step
+ label: "{{ joomla_core_step.from }} -> {{ joomla_core_step.version }}"
+
+- name: "โ
Assert one Joomla core at or above the image's core"
+ ansible.builtin.assert:
+ that:
+ - JOOMLA_CORE_DATABASE == JOOMLA_CORE_FILES
+ - JOOMLA_CORE_FILES is version(JOOMLA_CORE_TARGET, '>=')
+ fail_msg: >-
+ Joomla core is split after the update: database {{ JOOMLA_CORE_DATABASE }},
+ code volume {{ JOOMLA_CORE_FILES }}, image {{ JOOMLA_CORE_TARGET }}
+ quiet: true
diff --git a/roles/web-app-joomla/tasks/upgrade/step.yml b/roles/web-app-joomla/tasks/upgrade/step.yml
new file mode 100644
index 0000000000..eca2c55e26
--- /dev/null
+++ b/roles/web-app-joomla/tasks/upgrade/step.yml
@@ -0,0 +1,96 @@
+---
+- name: "๐ฉบ Check the database structure of Joomla {{ joomla_core_step.from }}"
+ ansible.builtin.include_tasks: core_update.yml
+ vars:
+ joomla_core_action: schema
+ joomla_core_plugins: ""
+ when: joomla_core_step.check | bool
+
+- name: "๐ Set the plugin states Joomla demands to leave {{ joomla_core_step.from }}"
+ ansible.builtin.include_tasks: core_update.yml
+ vars:
+ joomla_core_action: plugins
+ joomla_core_plugins: "{{ joomla_core_step.plugins | join(' ') }}"
+ when: joomla_core_step.plugins | length > 0
+
+- name: "๐ฆ Fetch and verify the Joomla {{ joomla_core_step.version }} update package"
+ ansible.builtin.command:
+ argv:
+ - container
+ - exec
+ - "{{ JOOMLA_LOCAL_CID }}" # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
+ - bash
+ - -c
+ - |
+ set -euo pipefail
+ rm -rf "$1"
+ mkdir -p "$1/tree"
+ curl -fsSL --retry 3 --connect-timeout 10 --max-time 600 -o "$1/package.tar.gz" "$2"
+ echo "$3 $1/package.tar.gz" | sha256sum -c -
+ tar -xzf "$1/package.tar.gz" -C "$1/tree" --no-same-owner
+ - bash
+ - "{{ JOOMLA_UPGRADE_STAGING_DIR }}"
+ - "https://github.com/joomla/joomla-cms/releases/download/{{ joomla_core_step.version }}/Joomla_{{ joomla_core_step.version }}-Stable-Update_Package.tar.gz"
+ - "{{ joomla_core_step.sha256 }}"
+ changed_when: true
+ when: joomla_core_step.package | bool
+ delegate_to: "{{ JOOMLA_HOST_NODE }}"
+
+- name: "๐๏ธ Lay the Joomla {{ joomla_core_step.version }} files over the code volume"
+ ansible.builtin.command:
+ argv:
+ - container
+ - exec
+ - "{{ JOOMLA_LOCAL_CID }}" # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
+ - bash
+ - -c
+ - |
+ set -euo pipefail
+ tar --create --file - --directory "$1" --owner "$3" --group "$3" --anchored \
+ --exclude ./installation --exclude ./administrator/logs --exclude './images/*' . \
+ | tar --extract --file - --directory "$2"
+ rm -f "$2/administrator/cache/autoload_psr4.php"
+ - bash
+ - "{{ (JOOMLA_UPGRADE_STAGING_DIR ~ '/tree') if joomla_core_step.package | bool else JOOMLA_IMAGE_SOURCE_DIR }}"
+ - "{{ JOOMLA_DOCROOT }}"
+ - "{{ JOOMLA_WEB_USER }}"
+ changed_when: true
+ delegate_to: "{{ JOOMLA_HOST_NODE }}"
+
+- name: "๐ Finalise the Joomla {{ joomla_core_step.version }} update on the database"
+ ansible.builtin.include_tasks: core_update.yml
+ vars:
+ joomla_core_action: finalise
+ joomla_core_plugins: ""
+
+- name: "๐ฉบ Check the database structure of Joomla {{ joomla_core_step.version }}"
+ ansible.builtin.include_tasks: core_update.yml
+ vars:
+ joomla_core_action: schema
+ joomla_core_plugins: ""
+
+- name: "๐งน Remove the Joomla {{ joomla_core_step.version }} update package"
+ ansible.builtin.command:
+ argv:
+ - container
+ - exec
+ - "{{ JOOMLA_LOCAL_CID }}" # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node
+ - rm
+ - -rf
+ - "{{ JOOMLA_UPGRADE_STAGING_DIR }}"
+ changed_when: true
+ when: joomla_core_step.package | bool
+ delegate_to: "{{ JOOMLA_HOST_NODE }}"
+
+- name: "๐ Re-detect the Joomla core after the {{ joomla_core_step.version }} update"
+ ansible.builtin.include_tasks: detect.yml
+
+- name: "โ
Assert the Joomla core reached {{ joomla_core_step.version }}"
+ ansible.builtin.assert:
+ that:
+ - JOOMLA_CORE_DATABASE == joomla_core_step.version
+ - JOOMLA_CORE_FILES == joomla_core_step.version
+ fail_msg: >-
+ Joomla update to {{ joomla_core_step.version }} left the database at
+ {{ JOOMLA_CORE_DATABASE }} and the code volume at {{ JOOMLA_CORE_FILES }}
+ quiet: true
diff --git a/roles/web-app-joomla/vars/main.yml b/roles/web-app-joomla/vars/main.yml
index a8b0f5d4ae..0ed65554dd 100644
--- a/roles/web-app-joomla/vars/main.yml
+++ b/roles/web-app-joomla/vars/main.yml
@@ -13,6 +13,13 @@ JOOMLA_CONFIG_FILE: "/var/www/html/configuration.php"
JOOMLA_INSTALLER_CLI_FILE: "/var/www/html/installation/joomla.php"
JOOMLA_CLI_FILE: "/var/www/html/cli/joomla.php"
JOOMLA_INIT_READY_FILE: "/var/www/html/.infinito-init.ready"
+JOOMLA_CLI_EXTENSION_ENABLE_SINCE: "6.1.0"
+
+JOOMLA_DOCROOT: "{{ lookup('volume', application_id, 'data').target }}"
+JOOMLA_IMAGE_SOURCE_DIR: "/usr/src/joomla"
+JOOMLA_VERSION_PHP: "libraries/src/Version.php"
+JOOMLA_UPGRADE_BRIDGES: "{{ lookup('config', application_id, 'services.joomla.upgrade.bridges') }}"
+JOOMLA_UPGRADE_STAGING_DIR: "/tmp/infinito-joomla-upgrade"
JOOMLA_ENTRYPOINT_SCRIPT_FILE: "docker-entrypoint-joomla.sh"
JOOMLA_ENTRYPOINT_SCRIPT_HOST_ABS: "{{ [ lookup('container', application_id, 'directories.volumes'), JOOMLA_ENTRYPOINT_SCRIPT_FILE ] | path_join }}"
diff --git a/tests/unit/python/roles/web-app-joomla/__init__.py b/tests/unit/python/roles/web-app-joomla/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/unit/python/roles/web-app-joomla/filter_plugins/__init__.py b/tests/unit/python/roles/web-app-joomla/filter_plugins/__init__.py
new file mode 100644
index 0000000000..087c384b57
--- /dev/null
+++ b/tests/unit/python/roles/web-app-joomla/filter_plugins/__init__.py
@@ -0,0 +1,5 @@
+from pathlib import Path
+
+PROJECT_ROOT: Path = Path(__file__).resolve().parents[6]
+
+__all__ = ["PROJECT_ROOT"]
diff --git a/tests/unit/python/roles/web-app-joomla/filter_plugins/test_joomla_core.py b/tests/unit/python/roles/web-app-joomla/filter_plugins/test_joomla_core.py
new file mode 100644
index 0000000000..e04affb844
--- /dev/null
+++ b/tests/unit/python/roles/web-app-joomla/filter_plugins/test_joomla_core.py
@@ -0,0 +1,219 @@
+from __future__ import annotations
+
+import importlib.util
+import sys
+import unittest
+
+from ansible.errors import AnsibleFilterError
+
+from . import PROJECT_ROOT
+
+
+def _load_module(rel_path: str, name: str):
+ path = PROJECT_ROOT / rel_path
+ spec = importlib.util.spec_from_file_location(name, str(path))
+ mod = importlib.util.module_from_spec(spec)
+ assert spec and spec.loader
+ sys.modules[name] = mod
+ spec.loader.exec_module(mod)
+ return mod
+
+
+MODULE = _load_module(
+ "roles/web-app-joomla/filter_plugins/joomla_core.py", "joomla_core"
+)
+
+SHA_5 = "7840541ae606bd460d4bf3647c977699af279c229f708756c78a2dcc06cfc8cf"
+SHA_4 = "a" * 64
+BRIDGE_5 = {
+ "version": "5.4.9",
+ "sha256": SHA_5,
+ "plugins": {"behaviour/compat": False, "behaviour/compat6": True},
+}
+BRIDGE_4 = {"version": "4.4.14", "sha256": SHA_4, "plugins": {}}
+
+VERSION_PHP = """