7
7
# the Business Source License, use of this software will be governed
8
8
# by the Apache License, Version 2.0.
9
9
10
- import tempfile
10
+ import hashlib
11
11
12
12
import toml
13
13
14
- from materialize .mzcompose import (
15
- loader ,
16
- )
17
- from materialize .mzcompose .service import (
18
- Service ,
19
- )
14
+ from materialize import MZ_ROOT
15
+ from materialize .mzcompose import loader
16
+ from materialize .mzcompose .service import Service
20
17
21
18
22
19
class Mz (Service ):
@@ -28,17 +25,6 @@ def __init__(
28
25
environment : str = "staging" ,
29
26
app_password : str ,
30
27
) -> None :
31
- # We must create the temporary config file in a location
32
- # that is accessible on the same path in both the ci-builder
33
- # container and the host that runs the docker daemon
34
- # $TMP does not guarantee that, but loader.composition_path does.
35
- config = tempfile .NamedTemporaryFile (
36
- dir = loader .composition_path ,
37
- prefix = "tmp_" ,
38
- suffix = ".toml" ,
39
- mode = "w" ,
40
- delete = False ,
41
- )
42
28
43
29
# Production env does not require to specify an endpoint.
44
30
if environment == "production" :
@@ -48,7 +34,7 @@ def __init__(
48
34
cloud_endpoint = f"https://api.{ environment } .cloud.materialize.com"
49
35
admin_endpoint = f"https://admin.{ environment } .cloud.materialize.com"
50
36
51
- toml .dump (
37
+ config_str = toml .dumps (
52
38
{
53
39
"profile" : "default" ,
54
40
"profiles" : {
@@ -60,13 +46,21 @@ def __init__(
60
46
},
61
47
},
62
48
},
63
- config ,
64
49
)
65
- config .close ()
50
+
51
+ # We must create the temporary config file in a location
52
+ # that is accessible on the same path in both the ci-builder
53
+ # container and the host that runs the docker daemon
54
+ # $TMP does not guarantee that, but loader.composition_path does.
55
+ config_hash = hashlib .sha256 (config_str .encode ()).hexdigest ()
56
+ config_name = (loader .composition_path or MZ_ROOT ) / f"tmp_{ config_hash } .toml"
57
+
58
+ with open (config_name , "w" ) as f :
59
+ f .write (config_str )
66
60
super ().__init__ (
67
61
name = name ,
68
62
config = {
69
63
"mzbuild" : "mz" ,
70
- "volumes" : [f"{ config . name } :/root/.config/materialize/mz.toml" ],
64
+ "volumes" : [f"{ config_name } :/root/.config/materialize/mz.toml" ],
71
65
},
72
66
)
0 commit comments