minio.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. from materialize.mzcompose.service import (
  10. Service,
  11. )
  12. def minio_blob_uri(address: str = "minio") -> str:
  13. return f"s3://minioadmin:minioadmin@persist/persist?endpoint=http://{address}:9000/&region=minio"
  14. class Minio(Service):
  15. def __init__(
  16. self,
  17. name: str = "minio",
  18. image: str = "minio/minio:RELEASE.2023-07-07T07-13-57Z",
  19. setup_materialize: bool = False,
  20. additional_directories: list[str] = [],
  21. ports: list[int | str] = [9000, 9001],
  22. allow_host_ports: bool = False,
  23. ) -> None:
  24. # We can pre-create buckets in minio by creating subdirectories in
  25. # /data. A bit gross to do this via a shell command, but it's net
  26. # less complicated than using a separate setup container that runs `mc`.
  27. command = "minio server /data --console-address :9001"
  28. if setup_materialize:
  29. command = f"mkdir -p /data/persist && {command}"
  30. for dir in additional_directories:
  31. command = f"mkdir -p /data/{dir} && {command}"
  32. super().__init__(
  33. name=name,
  34. config={
  35. "entrypoint": ["sh", "-c"],
  36. "command": [command],
  37. "image": image,
  38. "ports": ports,
  39. "allow_host_ports": allow_host_ports,
  40. "environment": [
  41. "MINIO_STORAGE_CLASS_STANDARD=EC:0",
  42. "MINIO_HEAL_DISABLE=on",
  43. "MINIO_DISK_WATERMARK_LOW=1",
  44. "MINIO_DISK_WATERMARK_HIGH=1",
  45. ],
  46. "healthcheck": {
  47. "test": [
  48. "CMD",
  49. "curl",
  50. "--fail",
  51. "http://localhost:9000/minio/health/live",
  52. ],
  53. "timeout": "5s",
  54. "interval": "1s",
  55. "start_period": "30s",
  56. },
  57. },
  58. )
  59. class Mc(Service):
  60. def __init__(
  61. self,
  62. name: str = "mc",
  63. image: str = "minio/mc:RELEASE.2023-07-07T05-25-51Z",
  64. ) -> None:
  65. super().__init__(
  66. name=name,
  67. config={
  68. "image": image,
  69. },
  70. )