diff --git a/roles/web-app-bluesky/files/shell/heal_sso_proxy_cfg.sh b/roles/web-app-bluesky/files/shell/heal_sso_proxy_cfg.sh new file mode 100644 index 0000000000..ac4b8c0c7c --- /dev/null +++ b/roles/web-app-bluesky/files/shell/heal_sso_proxy_cfg.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Remove the oauth2-proxy cfg bind-mount source when a prior deploy left it as a directory. +# +# Environment: +# SSO_PROXY_CFG_PATH host path the oauth2-proxy cfg file is bind-mounted from +# SSO_PROXY_CONTAINER container that mounts it, stopped before the removal +set -euo pipefail + +cfg_path="${SSO_PROXY_CFG_PATH:?SSO_PROXY_CFG_PATH must be set}" +container_name="${SSO_PROXY_CONTAINER:?SSO_PROXY_CONTAINER must be set}" + +if [[ -d "${cfg_path}" ]]; then + if container inspect "${container_name}" >/dev/null 2>&1; then + container stop "${container_name}" >/dev/null + fi + rm -rf "${cfg_path}" +fi diff --git a/roles/web-app-bluesky/tasks/00_core.yml b/roles/web-app-bluesky/tasks/00_core.yml index 44b8fbc9bb..caa472a5cc 100644 --- a/roles/web-app-bluesky/tasks/00_core.yml +++ b/roles/web-app-bluesky/tasks/00_core.yml @@ -1,6 +1,12 @@ --- - include_tasks: utils/once/flag.yml +- name: "๐Ÿ“‚ Register the compose handlers the pre-compose staging notifies" + ansible.builtin.include_role: + name: sys-svc-compose + tasks_from: none.yml + handlers_from: main + - name: "๐Ÿณ Pre-compose web-enabled staging (services dir + social-app + login-broker)" block: - name: "โœ… Ensure social-app services directory exists" @@ -20,13 +26,10 @@ ansible.builtin.include_tasks: "03_pds.yml" - name: "๐Ÿงน Heal oauth2-proxy cfg bind-mount (if it became a directory in a prior deploy)" - ansible.builtin.shell: >- - if [ -d "{{ BLUESKY_SSO_PROXY_CFG_PATH }}" ]; then - container stop "{{ BLUESKY_SSO_PROXY_CONTAINER }}" 2>/dev/null || true; - rm -rf "{{ BLUESKY_SSO_PROXY_CFG_PATH }}"; - fi - args: - executable: /bin/bash + ansible.builtin.script: "{{ role_path }}/files/shell/heal_sso_proxy_cfg.sh" + environment: + SSO_PROXY_CFG_PATH: "{{ BLUESKY_SSO_PROXY_CFG_PATH }}" + SSO_PROXY_CONTAINER: "{{ BLUESKY_SSO_PROXY_CONTAINER }}" changed_when: false - name: "๐Ÿ“‚ include sys-stk-backend role" diff --git a/tests/unit/python/roles/sys-stk-backend/test_handler_registration_order.py b/tests/unit/python/roles/sys-stk-backend/test_handler_registration_order.py index 7da51f33df..1a748dd28a 100644 --- a/tests/unit/python/roles/sys-stk-backend/test_handler_registration_order.py +++ b/tests/unit/python/roles/sys-stk-backend/test_handler_registration_order.py @@ -11,6 +11,7 @@ from utils.roles.mapping import ROLE_FILE_TASKS_MAIN BACKEND = PROJECT_ROOT / "roles/sys-stk-backend" / ROLE_FILE_TASKS_MAIN RDBMS_DEDICATED = PROJECT_ROOT / "roles/sys-svc-rdbms/tasks/dedicated.yml" +BLUESKY_CORE = PROJECT_ROOT / "roles/web-app-bluesky/tasks/00_core.yml" COMPOSE_OWNER = "sys-svc-compose" _NOTIFY = re.compile(r"^\s*notify:\s*(?:\[\s*)?['\"]?(compose-[\w-]+)", re.MULTILINE) @@ -64,6 +65,21 @@ class TestHandlerRegistrationOrder(unittest.TestCase): self.assertEqual(loader.get("name"), COMPOSE_OWNER) self.assertEqual(loader.get("handlers_from"), "main") + def test_bluesky_registers_the_owner_before_its_pre_compose_staging(self) -> None: + tasks = load_yaml_str(read_text(str(BLUESKY_CORE))) + loader = next( + index + for index, task in enumerate(tasks) + if _role_include(task).get("name") == COMPOSE_OWNER + and _role_include(task).get("handlers_from") == "main" + ) + staging = next( + index + for index, task in enumerate(tasks) + if "Pre-compose" in str(task.get("name")) + ) + self.assertLess(loader, staging) + def test_the_notifier_bootstraps_the_compose_host_before_its_first_notify( self, ) -> None: