-
Notifications
You must be signed in to change notification settings - Fork 454
/
redpanda.py
74 lines (64 loc) · 2.4 KB
/
redpanda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
from materialize.mzcompose.service import (
Service,
ServiceConfig,
)
class Redpanda(Service):
def __init__(
self,
name: str = "redpanda",
version: str = "v23.1.9",
auto_create_topics: bool = False,
image: str | None = None,
aliases: list[str] | None = None,
ports: list[int] | None = None,
) -> None:
if image is None:
image = f"vectorized/redpanda:{version}"
if ports is None:
ports = [9092, 8081]
# The Redpanda container provides both a Kafka and a Schema Registry replacement
if aliases is None:
aliases = ["kafka", "schema-registry"]
# Most of these options are simply required when using Redpanda in Docker.
# See: https://vectorized.io/docs/quick-start-docker/#Single-command-for-a-1-node-cluster
# The `enable_transactions` and `enable_idempotence` feature flags enable
# features Materialize requires that are present by default in Apache Kafka
# but not in Redpanda.
command_list = [
"redpanda",
"start",
"--overprovisioned",
"--smp=1",
"--memory=1G",
"--reserve-memory=0M",
"--node-id=0",
"--check=false",
"--set",
"redpanda.enable_transactions=true",
"--set",
"redpanda.enable_idempotence=true",
"--set",
f"redpanda.auto_create_topics_enabled={auto_create_topics}",
"--set",
f"--advertise-kafka-addr=kafka:{ports[0]}",
]
config: ServiceConfig = {
"image": image,
"ports": ports,
"command": command_list,
"networks": {"default": {"aliases": aliases}},
"healthcheck": {
"test": ["CMD", "curl", "-f", "localhost:9644/v1/status/ready"],
"interval": "1s",
"start_period": "120s",
},
}
super().__init__(name=name, config=config)