mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2026-12-02 02:09:35 +00:00
Add a hook checking install tags against service groups
The hook reports custom roles' `install-*` tags which have no service group of the same name, as `just install-service` would not start these services. Tags of galaxy roles are not checked, because the roles are not available where the hook runs in CI. Whether a group contains all of a role's services is not checked either, so the style guide now documents that requirement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a7303e22ae
commit
cd4f820462
@@ -40,6 +40,13 @@ repos:
|
||||
files: '^(group_vars/(matrix_servers|jitsi_jvb_servers)|bin/check-group-vars-jinja\.py|\.pre-commit-config\.yaml)$'
|
||||
args: ['group_vars/matrix_servers', 'group_vars/jitsi_jvb_servers']
|
||||
pass_filenames: false
|
||||
- id: check-install-service-names
|
||||
name: Check that custom roles' install tags have a matching service group
|
||||
entry: bin/check-install-service-names.py
|
||||
language: python
|
||||
additional_dependencies: ['pyyaml==6.0.3']
|
||||
files: '^(group_vars/matrix_servers|roles/custom/[^/]+/tasks/.+\.yml|bin/check-install-service-names\.py|\.pre-commit-config\.yaml)$'
|
||||
pass_filenames: false
|
||||
- id: check-examples-vars-migration-version
|
||||
name: Check examples/vars.yml migration version matches expected
|
||||
entry: bin/check-examples-vars-migration-version.sh
|
||||
|
||||
Executable
+101
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
# Checks that each `install-SERVICE` tag of the custom roles has a matching service group.
|
||||
#
|
||||
# `just install-service SERVICE` runs the `install-SERVICE` tag and then starts the group named SERVICE.
|
||||
# Ansible does not complain if that group does not exist, so the service gets installed, but not started.
|
||||
#
|
||||
# This script does not cover:
|
||||
# - tags of the galaxy roles, because they are not available where this hook runs in CI
|
||||
# - whether a group contains all of a role's services, as the group only needs to exist here
|
||||
# - group names which have no matching tag, as these are valid for `just start-group` and `just stop-group`
|
||||
#
|
||||
# Usage: bin/check-install-service-names.py
|
||||
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
import yaml
|
||||
|
||||
REPO = pathlib.Path(__file__).resolve().parent.parent
|
||||
GROUP_VARS = REPO / "group_vars" / "matrix_servers"
|
||||
ROLES = REPO / "roles" / "custom"
|
||||
SERVICES_VARIABLE = "devture_systemd_service_manager_services_list_auto"
|
||||
|
||||
# The homeserver's service uses `matrix_homeserver_implementation` as a group name.
|
||||
# The values below are the ones allowed by the matrix-base role's validate_config.yml.
|
||||
HOMESERVER_IMPLEMENTATIONS = {"synapse", "dendrite", "conduit", "continuwuity", "tuwunel"}
|
||||
|
||||
# Tags of custom roles which do not install a service of their own, so no group can match them.
|
||||
TAGS_WITHOUT_SERVICE = {
|
||||
"appservice-double-puppet", # only prepares configuration for other services
|
||||
"docker", # only used for migration tasks here, as the Docker role itself is a galaxy one
|
||||
"prometheus-services-connect", # only prepares configuration for other services
|
||||
}
|
||||
|
||||
|
||||
def tag_names(node):
|
||||
"""Yields the tag names below a YAML node, whichever way a task has them written."""
|
||||
if isinstance(node, yaml.MappingNode):
|
||||
for key, value in node.value:
|
||||
if key.value == "tags":
|
||||
if isinstance(value, yaml.SequenceNode):
|
||||
yield from (item.value for item in value.value)
|
||||
else:
|
||||
yield from (tag.strip() for tag in value.value.split(","))
|
||||
else:
|
||||
yield from tag_names(value)
|
||||
elif isinstance(node, yaml.SequenceNode):
|
||||
for value in node.value:
|
||||
yield from tag_names(value)
|
||||
|
||||
|
||||
def install_tags():
|
||||
"""Returns a map of service names (tags without the `install-` prefix) to the roles having them."""
|
||||
services = {}
|
||||
for path in sorted(ROLES.glob("*/tasks/**/*.yml")):
|
||||
role = path.relative_to(ROLES).parts[0]
|
||||
with path.open(encoding="utf-8") as file:
|
||||
for tag in tag_names(yaml.compose(file, Loader=yaml.SafeLoader)):
|
||||
if tag.startswith("install-") and tag != "install-all":
|
||||
services.setdefault(tag.removeprefix("install-"), set()).add(role)
|
||||
return services
|
||||
|
||||
|
||||
def service_groups():
|
||||
"""Returns the group names used in the list of services."""
|
||||
with GROUP_VARS.open(encoding="utf-8") as file:
|
||||
document = yaml.compose(file, Loader=yaml.SafeLoader)
|
||||
value = next(value.value for key, value in document.value if key.value == SERVICES_VARIABLE)
|
||||
groups = set()
|
||||
for names in re.findall(r"'groups': \[(.*?)\]", value):
|
||||
groups.update(re.findall(r"'([^']+)'", names))
|
||||
if "'groups': ['matrix', 'homeservers', matrix_homeserver_implementation]" in value:
|
||||
groups.update(HOMESERVER_IMPLEMENTATIONS)
|
||||
return groups
|
||||
|
||||
|
||||
def main():
|
||||
services = install_tags()
|
||||
groups = service_groups()
|
||||
failed = False
|
||||
for service, roles in sorted(services.items()):
|
||||
if service not in groups and service not in TAGS_WITHOUT_SERVICE:
|
||||
print(f"install-{service} ({', '.join(sorted(roles))}): no `{service}` group in {SERVICES_VARIABLE}")
|
||||
failed = True
|
||||
for service in sorted(TAGS_WITHOUT_SERVICE):
|
||||
if service not in services:
|
||||
print(f"{service}: listed in TAGS_WITHOUT_SERVICE, but no custom role has an install-{service} tag")
|
||||
failed = True
|
||||
elif service in groups:
|
||||
print(f"{service}: listed in TAGS_WITHOUT_SERVICE, but it has a group")
|
||||
failed = True
|
||||
return 1 if failed else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
+1
-1
@@ -90,7 +90,7 @@ Besides the role itself and its documentation page, a new component touches a fe
|
||||
|
||||
1. The role, in `roles/custom/matrix-<component>/` (or an external role wired via `requirements.yml`, as described above).
|
||||
2. Role registration in `setup.yml`.
|
||||
3. Wiring in `group_vars/matrix_servers`. Wire the component to the rest of the playbook there (referencing variables of other roles), but keep values that the role can construct by itself in the role's own `defaults/main.yml`.
|
||||
3. Wiring in `group_vars/matrix_servers`. Wire the component to the rest of the playbook there (referencing variables of other roles), but keep values that the role can construct by itself in the role's own `defaults/main.yml`. Each of the role's services in `devture_systemd_service_manager_services_list_auto` needs a group named after the role's `install-*` tag (e.g. `mautrix-slack` for `install-mautrix-slack`), so that `just install-service` starts all of them.
|
||||
4. The documentation page, `docs/configuring-playbook-<component>.md`, linked from the table of contents in `docs/README.md`.
|
||||
5. An entry in the supported services list in `README.md`.
|
||||
6. A row in `docs/container-images.md`, if the component runs a container.
|
||||
|
||||
Reference in New Issue
Block a user