From 5aa5d9d0ce7b4936afc1380e2710c37812163bd7 Mon Sep 17 00:00:00 2001 From: Catalan Lover Date: Sun, 3 May 2026 09:00:37 +0200 Subject: [PATCH] Update conditional restart logic with dynamic rolling tag detection. --- .../defaults/main.yml | 10 ++++------ .../tasks/validate_config.yml | 2 +- roles/custom/matrix-bot-draupnir/defaults/main.yml | 10 ++++------ .../matrix-bot-draupnir/tasks/validate_config.yml | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/roles/custom/matrix-appservice-draupnir-for-all/defaults/main.yml b/roles/custom/matrix-appservice-draupnir-for-all/defaults/main.yml index 89a075231..196992e51 100644 --- a/roles/custom/matrix-appservice-draupnir-for-all/defaults/main.yml +++ b/roles/custom/matrix-appservice-draupnir-for-all/defaults/main.yml @@ -46,18 +46,16 @@ matrix_appservice_draupnir_for_all_systemd_required_services_list_custom: [] # List of systemd services that matrix-bot-draupnir.service wants matrix_appservice_draupnir_for_all_systemd_wanted_services_list: [] -# Force restart tag is used to control if the tag that is used is rolling or not. -# When both Draupnir roles are enabled, we only force restart if they are on the same -# version string and that version string matches the moving tag. -matrix_appservice_draupnir_for_all_force_rolling_tag: "latest" +# Rolling tag: true if version doesn't match semver shape (vX.Y.Z with optional prerelease/build), false otherwise. +matrix_appservice_draupnir_for_all_rolling_tag: "{{ not (matrix_appservice_draupnir_for_all_version is match('^v[0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$')) }}" # Force restart the service on all runs only when both roles are enabled, both roles -# are using the same version string, and that version is the moving tag. +# are using the same version string, and that version is a classified as a moving tag. matrix_appservice_draupnir_for_all_force_restart: "{{ matrix_bot_draupnir_enabled | bool and matrix_appservice_draupnir_for_all_enabled | bool and matrix_bot_draupnir_version == matrix_appservice_draupnir_for_all_version and - matrix_appservice_draupnir_for_all_version == matrix_appservice_draupnir_for_all_force_rolling_tag + matrix_appservice_draupnir_for_all_rolling_tag | bool }}" # The room ID where people can use the bot. The bot has no access controls, so diff --git a/roles/custom/matrix-appservice-draupnir-for-all/tasks/validate_config.yml b/roles/custom/matrix-appservice-draupnir-for-all/tasks/validate_config.yml index 2c2fdf9f9..fcd406246 100644 --- a/roles/custom/matrix-appservice-draupnir-for-all/tasks/validate_config.yml +++ b/roles/custom/matrix-appservice-draupnir-for-all/tasks/validate_config.yml @@ -23,7 +23,7 @@ - {'old': 'matrix_appservice_draupnir_for_all_docker_image_registry_prefix_upstream', 'new': 'matrix_appservice_draupnir_for_all_container_image_registry_prefix_upstream'} - {'old': 'matrix_appservice_draupnir_for_all_docker_image_registry_prefix_upstream_default', 'new': 'matrix_appservice_draupnir_for_all_container_image_registry_prefix_upstream_default'} - {'old': 'matrix_appservice_draupnir_for_all_docker_src_files_path', 'new': 'matrix_appservice_draupnir_for_all_container_src_files_path'} - - {'old': 'matrix_appservice_draupnir_for_all_container_image_force_pull', 'new': ' (No longer needed due to new docker module doing this natively only if needed. If you run both bot mode and appservice mode matrix_appservice_draupnir_for_all_rolling_tag_force_pull is needed to make sure restart logic works correctly for both roles.)'} + - {'old': 'matrix_appservice_draupnir_for_all_container_image_force_pull', 'new': ' (No longer needed due to new docker module doing this natively only if needed.)'} - name: Fail if required matrix-bot-draupnir variables are undefined ansible.builtin.fail: diff --git a/roles/custom/matrix-bot-draupnir/defaults/main.yml b/roles/custom/matrix-bot-draupnir/defaults/main.yml index 78a511156..465a935d9 100644 --- a/roles/custom/matrix-bot-draupnir/defaults/main.yml +++ b/roles/custom/matrix-bot-draupnir/defaults/main.yml @@ -28,18 +28,16 @@ matrix_bot_draupnir_config_path: "{{ matrix_bot_draupnir_base_path }}/config" matrix_bot_draupnir_data_path: "{{ matrix_bot_draupnir_base_path }}/data" matrix_bot_draupnir_container_src_files_path: "{{ matrix_bot_draupnir_base_path }}/docker-src" -# Force restart tag is used to control if the tag that is used is rolling or not. -# When both Draupnir roles are enabled, we only force restart if they are on the same -# version string and that version string matches the moving tag. -matrix_bot_draupnir_force_rolling_tag: "latest" +# Rolling tag: true if version doesn't match semver shape (vX.Y.Z with optional prerelease/build), false otherwise. +matrix_bot_draupnir_rolling_tag: "{{ not (matrix_bot_draupnir_version is match('^v[0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$')) }}" # Force restart the service on all runs only when both roles are enabled, both roles -# are using the same version string, and that version is the moving tag. +# are using the same version string, and that version is a classified as a moving tag. matrix_bot_draupnir_force_restart: "{{ matrix_bot_draupnir_enabled | bool and matrix_appservice_draupnir_for_all_enabled | bool and matrix_bot_draupnir_version == matrix_appservice_draupnir_for_all_version and - matrix_bot_draupnir_version == matrix_bot_draupnir_rolling_tag + matrix_bot_draupnir_rolling_tag | bool }}" matrix_bot_draupnir_config_web_enabled: "{{ matrix_bot_draupnir_config_web_abuseReporting or matrix_bot_draupnir_config_web_synapseHTTPAntispam_enabled }}" # noqa var-naming diff --git a/roles/custom/matrix-bot-draupnir/tasks/validate_config.yml b/roles/custom/matrix-bot-draupnir/tasks/validate_config.yml index e7ae44f50..7bc402fc2 100644 --- a/roles/custom/matrix-bot-draupnir/tasks/validate_config.yml +++ b/roles/custom/matrix-bot-draupnir/tasks/validate_config.yml @@ -37,7 +37,7 @@ - {'old': 'matrix_bot_draupnir_docker_image_registry_prefix_upstream', 'new': 'matrix_bot_draupnir_container_image_registry_prefix_upstream'} - {'old': 'matrix_bot_draupnir_docker_image_registry_prefix_upstream_default', 'new': 'matrix_bot_draupnir_container_image_registry_prefix_upstream_default'} - {'old': 'matrix_bot_draupnir_docker_src_files_path', 'new': 'matrix_bot_draupnir_container_src_files_path'} - - {'old': 'matrix_bot_draupnir_container_image_force_pull', 'new': ' (No longer needed due to new docker module doing this natively only if needed. If you run both bot mode and appservice mode matrix_bot_draupnir_rolling_tag_force_pull is needed to make sure restart logic works correctly for both roles.)'} + - {'old': 'matrix_bot_draupnir_container_image_force_pull', 'new': ' (No longer needed due to new docker module doing this natively only if needed.)'} - name: Fail if required matrix-bot-draupnir variables are undefined ansible.builtin.fail: