mz.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. import hashlib
  10. import toml
  11. from materialize import MZ_ROOT
  12. from materialize.mzcompose import loader
  13. from materialize.mzcompose.service import Service
  14. class Mz(Service):
  15. def __init__(
  16. self,
  17. *,
  18. name: str = "mz",
  19. region: str = "aws/us-east-1",
  20. environment: str = "staging",
  21. app_password: str,
  22. ) -> None:
  23. # Production env does not require to specify an endpoint.
  24. if environment == "production":
  25. cloud_endpoint = None
  26. admin_endpoint = None
  27. else:
  28. cloud_endpoint = f"https://api.{environment}.cloud.materialize.com"
  29. admin_endpoint = f"https://admin.{environment}.cloud.materialize.com"
  30. config_str = toml.dumps(
  31. {
  32. "profile": "default",
  33. "profiles": {
  34. "default": {
  35. "app-password": app_password,
  36. "region": region,
  37. "cloud-endpoint": cloud_endpoint,
  38. "admin-endpoint": admin_endpoint,
  39. },
  40. },
  41. },
  42. )
  43. # We must create the temporary config file in a location
  44. # that is accessible on the same path in both the ci-builder
  45. # container and the host that runs the docker daemon
  46. # $TMP does not guarantee that, but loader.composition_path does.
  47. config_hash = hashlib.sha256(config_str.encode()).hexdigest()
  48. config_name = (loader.composition_path or MZ_ROOT) / f"tmp_{config_hash}.toml"
  49. with open(config_name, "w") as f:
  50. f.write(config_str)
  51. super().__init__(
  52. name=name,
  53. config={
  54. "mzbuild": "mz",
  55. "volumes": [f"{config_name}:/root/.config/materialize/mz.toml"],
  56. },
  57. )