From b38bb6dba5f2c7401c9fff37c345c7ecb68a2fac Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 16 Oct 2026 11:33:22 +0200 Subject: [PATCH] fix(web-app-weblate): let beat alone populate the volumes the tier shares weblate, beat and worker mount the same weblate_data and weblate_cache. Docker fills a fresh named volume from the image once per POST /containers/create, and that copy does an Lstat plus os.Mkdir per directory without tolerating EEXIST. Compose created all three at once, two populations of the image's /app/data raced, and the deploy died with "failed to mkdir /var/lib/docker/volumes/weblate_data/_data/python: file exists" in CI run 38818071194. The daemon log names the route as containers/create, so this is the population path, not a mount of a pre-existing file. Make weblate and worker depend on beat. The lever is not startup order but the Create phase, which compose runs in dependency order: beat populates both volumes alone, and by the time the other two are created no copy runs. The failing run proves that phase is ordered - COMPOSE_PARALLEL_LIMIT was 4, yet only the two existing depends_on targets reached Created before the other three began. This is compose-only. In swarm, container_depends_on drops to a bare list (plugins/lookup/container_depends_on.py:103) and docker stack deploy ignores it, so swarm behaviour is unchanged and the same race stays reachable there. A mode-independent fix needs nocopy on the non-owning mounts, which plugins/lookup/container_volumes.py cannot express today. The test reads meta/volumes.yml, collects every service sharing a volume and requires each non-beat sharer to name beat. Against the previous template it yields weblate False, beat True, worker False, so it fails without this change. Co-Authored-By: Claude Opus 5 (1M context) --- .../web-app-weblate/templates/compose.yml.j2 | 8 ++- .../python/roles/web-app-weblate/__init__.py | 0 .../test_shared_volume_population_order.py | 53 +++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 tests/unit/python/roles/web-app-weblate/__init__.py create mode 100644 tests/unit/python/roles/web-app-weblate/test_shared_volume_population_order.py diff --git a/roles/web-app-weblate/templates/compose.yml.j2 b/roles/web-app-weblate/templates/compose.yml.j2 index a0c197a092..868f8a129f 100644 --- a/roles/web-app-weblate/templates/compose.yml.j2 +++ b/roles/web-app-weblate/templates/compose.yml.j2 @@ -10,7 +10,9 @@ {{ lookup('container_volumes', service_name) | indent(4) }} {{ lookup('container_extra_hosts') | indent(4) }} {{ lookup('container_networks') | indent(4) }} - {{ lookup('container_depends_on', application_id) | indent(4) }} + {{ lookup('container_depends_on', application_id, extra={ + 'beat': {'condition': 'service_started'}, +}) | indent(4) }} {{ lookup('container_healthcheck', service_name) | indent(4) }} {% set service_name = 'beat' %} @@ -35,7 +37,9 @@ {{ lookup('container_volumes', service_name) | indent(4) }} {{ lookup('container_extra_hosts') | indent(4) }} {{ lookup('container_networks') | indent(4) }} - {{ lookup('container_depends_on', application_id) | indent(4) }} + {{ lookup('container_depends_on', application_id, extra={ + 'beat': {'condition': 'service_started'}, +}) | indent(4) }} {{ lookup('compose_volumes') }} diff --git a/tests/unit/python/roles/web-app-weblate/__init__.py b/tests/unit/python/roles/web-app-weblate/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit/python/roles/web-app-weblate/test_shared_volume_population_order.py b/tests/unit/python/roles/web-app-weblate/test_shared_volume_population_order.py new file mode 100644 index 0000000000..530300804c --- /dev/null +++ b/tests/unit/python/roles/web-app-weblate/test_shared_volume_population_order.py @@ -0,0 +1,53 @@ +from __future__ import annotations + +import re +import unittest + +from utils.cache.files import PROJECT_ROOT, read_text +from utils.cache.yaml import load_yaml_str +from utils.roles.mapping import ROLE_FILE_META_VOLUMES, ROLE_FILE_TEMPL_COMPOSE + +ROLE = PROJECT_ROOT / "roles" / "web-app-weblate" +COMPOSE = ROLE / ROLE_FILE_TEMPL_COMPOSE +VOLUMES = ROLE / ROLE_FILE_META_VOLUMES +POPULATING_SERVICE = "beat" + + +def service_blocks(template: str) -> dict[str, str]: + """Split a compose template into one text block per ``service_name``. + + Args: + template: the raw ``compose.yml.j2`` source. + + Returns: + Mapping of service name to the template text that renders it. + """ + parts = re.split(r"{%\s*set service_name = '([^']+)'\s*%}", template) + return dict(zip(parts[1::2], parts[2::2], strict=True)) + + +class TestSharedVolumePopulationOrder(unittest.TestCase): + def test_every_other_sharer_waits_for_the_service_that_fills_the_volume( + self, + ) -> None: + volumes = load_yaml_str(read_text(str(VOLUMES))) + sharers = { + mount["service"] + for entry in volumes.values() + for mount in entry.get("mounts") or [] + } + blocks = service_blocks(read_text(str(COMPOSE))) + for service in sorted(sharers - {POPULATING_SERVICE}): + self.assertIn( + POPULATING_SERVICE, + blocks[service], + f"docker fills a fresh named volume from the image once per container " + f"create and the copy's mkdir is not EEXIST-safe, so '{service}' must " + f"depend on '{POPULATING_SERVICE}' instead of being created beside it, " + f"or the deploy dies on 'mkdir /var/lib/docker/volumes/weblate_data/" + f"_data/python: file exists'", + ) + + +if __name__ == "__main__": + unittest.main()