Skip to content

Commit 3d96ec0

Browse files
authored
Write mz config to deterministic location (#32240)
The file name is based off a hash of the contents. This avoids accumulating many temporary config files in a local worktree. ### Checklist - [ ] This PR has adequate test coverage / QA involvement has been duly considered. ([trigger-ci for additional test/nightly runs](https://trigger-ci.dev.materialize.com/)) - [ ] This PR has an associated up-to-date [design doc](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/README.md), is a design doc ([template](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/00000000_template.md)), or is sufficiently small to not require a design. <!-- Reference the design in the description. --> - [ ] If this PR evolves [an existing `$T ⇔ Proto$T` mapping](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/command-and-response-binary-encoding.md) (possibly in a backwards-incompatible way), then it is tagged with a `T-proto` label. - [ ] If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label ([example](MaterializeInc/cloud#5021)). <!-- Ask in #team-cloud on Slack if you need help preparing the cloud PR. --> - [ ] If this PR includes major [user-facing behavior changes](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/guide-changes.md#what-changes-require-a-release-note), I have pinged the relevant PM to schedule a changelog post. --------- Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent 018050b commit 3d96ec0

File tree

1 file changed

+16
-22
lines changed
  • misc/python/materialize/mzcompose/services

1 file changed

+16
-22
lines changed

misc/python/materialize/mzcompose/services/mz.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
# the Business Source License, use of this software will be governed
88
# by the Apache License, Version 2.0.
99

10-
import tempfile
10+
import hashlib
1111

1212
import toml
1313

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
2017

2118

2219
class Mz(Service):
@@ -28,17 +25,6 @@ def __init__(
2825
environment: str = "staging",
2926
app_password: str,
3027
) -> 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-
)
4228

4329
# Production env does not require to specify an endpoint.
4430
if environment == "production":
@@ -48,7 +34,7 @@ def __init__(
4834
cloud_endpoint = f"https://api.{environment}.cloud.materialize.com"
4935
admin_endpoint = f"https://admin.{environment}.cloud.materialize.com"
5036

51-
toml.dump(
37+
config_str = toml.dumps(
5238
{
5339
"profile": "default",
5440
"profiles": {
@@ -60,13 +46,21 @@ def __init__(
6046
},
6147
},
6248
},
63-
config,
6449
)
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)
6660
super().__init__(
6761
name=name,
6862
config={
6963
"mzbuild": "mz",
70-
"volumes": [f"{config.name}:/root/.config/materialize/mz.toml"],
64+
"volumes": [f"{config_name}:/root/.config/materialize/mz.toml"],
7165
},
7266
)

0 commit comments

Comments
 (0)