Skip to content

Commit 37ceda6

Browse files
authored
Merge pull request #23517 from def-/pr-docker-weirdness
mzcompose: Safer docker compose file
2 parents 5c85eec + 5eb9c7f commit 37ceda6

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

misc/python/materialize/mzcompose/composition.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ def __init__(
163163
if munge_services:
164164
self.dependencies = self._munge_services(self.compose["services"].items())
165165

166+
# Emit the munged configuration to a temporary file so that we can later
167+
# pass it to Docker Compose.
168+
self._write_compose()
169+
166170
def _munge_services(
167171
self, services: list[tuple[str, dict]]
168172
) -> mzbuild.DependencySet:
@@ -229,6 +233,12 @@ def _munge_services(
229233

230234
return deps
231235

236+
def _write_compose(self) -> None:
237+
new_file = TemporaryFile(mode="w")
238+
os.set_inheritable(new_file.fileno(), True)
239+
yaml.dump(self.compose, new_file)
240+
self.file = new_file
241+
232242
def invoke(
233243
self,
234244
*args: str,
@@ -263,12 +273,8 @@ def invoke(
263273
("--project-name", self.project_name) if self.project_name else ()
264274
)
265275

266-
# Emit the munged configuration to a temporary file so that we can later
267-
# pass it to Docker Compose.
268-
file = TemporaryFile(mode="w")
269-
os.set_inheritable(file.fileno(), True)
270-
yaml.dump(self.compose, file)
271-
file.flush()
276+
# Make sure file doesn't get changed/deleted while we use it
277+
file = self.file
272278

273279
ret = None
274280
for retry in range(1, max_tries + 1):
@@ -393,6 +399,8 @@ def override(self, *services: "Service") -> Iterator[None]:
393399
# config for an `mzbuild` config.
394400
deps.acquire()
395401

402+
self._write_compose()
403+
396404
# Ensure image freshness
397405
self.pull_if_variable([service.name for service in services])
398406

@@ -421,6 +429,7 @@ def override(self, *services: "Service") -> Iterator[None]:
421429

422430
# Restore the old composition.
423431
self.compose = old_compose
432+
self._write_compose()
424433

425434
@contextmanager
426435
def test_case(self, name: str) -> Iterator[None]:
@@ -687,6 +696,7 @@ def up(
687696
for service in self.compose["services"].values():
688697
service["entrypoint"] = ["sleep", "infinity"]
689698
service["command"] = []
699+
self._write_compose()
690700

691701
self.invoke(
692702
"up",
@@ -698,6 +708,7 @@ def up(
698708

699709
if persistent:
700710
self.compose = old_compose # type: ignore
711+
self._write_compose()
701712

702713
def validate_sources_sinks_clusters(self) -> str | None:
703714
"""Validate that all sources, sinks & clusters are in a good state"""

test/cluster/mzcompose.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
7474

7575
for i, name in enumerate(c.workflows):
7676
# incident-70 requires more memory, runs in separate CI step
77-
if name in ("default", "test-incident-70"):
77+
# concurrent-connections is too flaky
78+
if name in ("default", "test-incident-70", "test-concurrent-connections"):
7879
continue
7980
if shard is None or shard_count is None or i % int(shard_count) == shard:
8081
with c.test_case(name):
@@ -2570,7 +2571,7 @@ def workflow_test_concurrent_connections(c: Composition) -> None:
25702571

25712572
def worker(c: Composition, i: int) -> None:
25722573
start_time = time.time()
2573-
c.sql("SELECT 1")
2574+
c.sql("SELECT 1", print_statement=False)
25742575
end_time = time.time()
25752576
runtimes[i] = end_time - start_time
25762577

0 commit comments

Comments
 (0)