redpanda.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ServiceConfig,
  12. )
  13. REDPANDA_VERSION = "v25.1.4"
  14. class Redpanda(Service):
  15. def __init__(
  16. self,
  17. name: str = "redpanda",
  18. version: str = REDPANDA_VERSION,
  19. auto_create_topics: bool = False,
  20. image: str | None = None,
  21. aliases: list[str] | None = None,
  22. ports: list[int] | None = None,
  23. ) -> None:
  24. if image is None:
  25. image = f"redpandadata/redpanda:{version}"
  26. if ports is None:
  27. ports = [9092, 8081]
  28. # The Redpanda container provides both a Kafka and a Schema Registry replacement
  29. if aliases is None:
  30. aliases = ["kafka", "schema-registry"]
  31. # Most of these options are simply required when using Redpanda in Docker.
  32. # See: https://docs.redpanda.com/current/get-started/quick-start/#Single-command-for-a-1-node-cluster
  33. # The `enable_transactions` and `enable_idempotence` feature flags enable
  34. # features Materialize requires that are present by default in Apache Kafka
  35. # but not in Redpanda.
  36. command_list = [
  37. "redpanda",
  38. "start",
  39. "--overprovisioned",
  40. "--smp=1",
  41. "--memory=1G",
  42. "--reserve-memory=0M",
  43. "--node-id=0",
  44. "--check=false",
  45. "--set",
  46. "redpanda.enable_transactions=true",
  47. "--set",
  48. "redpanda.enable_idempotence=true",
  49. "--set",
  50. f"redpanda.auto_create_topics_enabled={auto_create_topics}",
  51. # Only require 4KB per topic partition rather than 4MiB.
  52. "--set",
  53. "redpanda.topic_memory_per_partition=4096",
  54. "--set",
  55. f"--advertise-kafka-addr=kafka:{ports[0]}",
  56. ]
  57. config: ServiceConfig = {
  58. "image": image,
  59. "ports": ports,
  60. "command": command_list,
  61. "networks": {"default": {"aliases": aliases}},
  62. "healthcheck": {
  63. "test": ["CMD", "curl", "-f", "localhost:9644/v1/status/ready"],
  64. "interval": "1s",
  65. "start_period": "120s",
  66. },
  67. }
  68. super().__init__(name=name, config=config)