@@ -163,6 +163,10 @@ def __init__(
163
163
if munge_services :
164
164
self .dependencies = self ._munge_services (self .compose ["services" ].items ())
165
165
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
+
166
170
def _munge_services (
167
171
self , services : list [tuple [str , dict ]]
168
172
) -> mzbuild .DependencySet :
@@ -229,6 +233,12 @@ def _munge_services(
229
233
230
234
return deps
231
235
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
+
232
242
def invoke (
233
243
self ,
234
244
* args : str ,
@@ -263,12 +273,8 @@ def invoke(
263
273
("--project-name" , self .project_name ) if self .project_name else ()
264
274
)
265
275
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
272
278
273
279
ret = None
274
280
for retry in range (1 , max_tries + 1 ):
@@ -393,6 +399,8 @@ def override(self, *services: "Service") -> Iterator[None]:
393
399
# config for an `mzbuild` config.
394
400
deps .acquire ()
395
401
402
+ self ._write_compose ()
403
+
396
404
# Ensure image freshness
397
405
self .pull_if_variable ([service .name for service in services ])
398
406
@@ -421,6 +429,7 @@ def override(self, *services: "Service") -> Iterator[None]:
421
429
422
430
# Restore the old composition.
423
431
self .compose = old_compose
432
+ self ._write_compose ()
424
433
425
434
@contextmanager
426
435
def test_case (self , name : str ) -> Iterator [None ]:
@@ -687,6 +696,7 @@ def up(
687
696
for service in self .compose ["services" ].values ():
688
697
service ["entrypoint" ] = ["sleep" , "infinity" ]
689
698
service ["command" ] = []
699
+ self ._write_compose ()
690
700
691
701
self .invoke (
692
702
"up" ,
@@ -698,6 +708,7 @@ def up(
698
708
699
709
if persistent :
700
710
self .compose = old_compose # type: ignore
711
+ self ._write_compose ()
701
712
702
713
def validate_sources_sinks_clusters (self ) -> str | None :
703
714
"""Validate that all sources, sinks & clusters are in a good state"""
0 commit comments