-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathTiltfile
154 lines (139 loc) · 5.15 KB
/
Tiltfile
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
load("ext://restart_process", "docker_build_with_restart")
load("ext://helm_resource", "helm_resource", "helm_repo")
# A list of directories where changes trigger a hot-reload of the sequencer
hot_reload_dirs = ["app", "cmd", "tools", "x"]
# Create a localnet config file from defaults, and if a default configuration doesn't exist, populate it with default values
localnet_config_path = "localnet_config.yaml"
localnet_config_defaults = {
"relayers": {"count": 1},
"gateways": {"count": 1},
# By default, we use the `helm_repo` function below to point to the remote repository
# but can update it to the locally cloned repo for testing & development
"helm_chart_local_repo": {"enabled": False, "path": "../helm-charts"},
}
localnet_config_file = read_yaml(localnet_config_path, default=localnet_config_defaults)
localnet_config = {}
localnet_config.update(localnet_config_defaults)
localnet_config.update(localnet_config_file)
if (localnet_config_file != localnet_config) or (
not os.path.exists(localnet_config_path)
):
print("Updating " + localnet_config_path + " with defaults")
local("cat - > " + localnet_config_path, stdin=encode_yaml(localnet_config))
# Configure helm chart reference. If using a local repo, set the path to the local repo; otherwise, use our own helm repo.
helm_repo("pokt-network", "https://pokt-network.github.io/helm-charts/")
sequencer_chart = "pokt-network/poktroll-sequencer"
poktroll_chart = "pokt-network/poktroll"
if localnet_config["helm_chart_local_repo"]["enabled"]:
helm_chart_local_repo = localnet_config["helm_chart_local_repo"]["path"]
hot_reload_dirs.append(helm_chart_local_repo)
print("Using local helm chart repo " + helm_chart_local_repo)
sequencer_chart = helm_chart_local_repo + "/charts/poktroll-sequencer"
poktroll_chart = helm_chart_local_repo + "/charts/poktroll"
# Import files into Kubernetes ConfigMap
def read_files_from_directory(directory):
files = listdir(directory)
config_map_data = {}
for filepath in files:
content = str(read_file(filepath)).strip()
filename = os.path.basename(filepath)
config_map_data[filename] = content
return config_map_data
def generate_config_map_yaml(name, data):
config_map_object = {
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {"name": name},
"data": data,
}
return encode_yaml(config_map_object)
# Import keyring/keybase files into Kubernetes ConfigMap
k8s_yaml(
generate_config_map_yaml(
"pocketd-keys", read_files_from_directory("localnet/pocketd/keyring-test/")
)
) # pocketd/keys
# Import configuration files into Kubernetes ConfigMap
k8s_yaml(
generate_config_map_yaml(
"pocketd-configs", read_files_from_directory("localnet/pocketd/config/")
)
) # pocketd/configs
# Hot reload protobuf changes
local_resource(
"hot-reload: generate protobufs",
"ignite generate proto-go -y",
deps=["proto"],
labels=["hot-reloading"],
)
# Hot reload the pocketd binary used by the k8s cluster
local_resource(
"hot-reload: pocketd",
"GOOS=linux ignite chain build --skip-proto --output=./bin --debug -v",
deps=hot_reload_dirs,
labels=["hot-reloading"],
resource_deps=["hot-reload: generate protobufs"],
)
# Hot reload the local pocketd binary used by the CLI
local_resource(
"hot-reload: pocketd - local cli",
"ignite chain build --skip-proto --debug -v -o $(go env GOPATH)/bin",
deps=hot_reload_dirs,
labels=["hot-reloading"],
resource_deps=["hot-reload: generate protobufs"],
)
# Build an image with a pocketd binary
docker_build_with_restart(
"pocketd",
".",
dockerfile_contents="""FROM golang:1.20.8
RUN apt-get -q update && apt-get install -qyy curl jq
RUN go install github.com/go-delve/delve/cmd/dlv@latest
COPY bin/pocketd /usr/local/bin/pocketd
WORKDIR /
""",
only=["./bin/pocketd"],
entrypoint=["/bin/sh", "/scripts/pocket.sh"],
live_update=[sync("bin/pocketd", "/usr/local/bin/pocketd")],
)
# Run celestia and anvil nodes
k8s_yaml(
["localnet/kubernetes/celestia-rollkit.yaml", "localnet/kubernetes/anvil.yaml"]
)
# Run pocket-specific nodes (sequencer, relayers, etc...)
helm_resource(
"sequencer",
sequencer_chart,
flags=["--values=./localnet/kubernetes/values-common.yaml"],
image_deps=["pocketd"],
image_keys=[("image.repository", "image.tag")],
)
helm_resource(
"relayers",
poktroll_chart,
flags=[
"--values=./localnet/kubernetes/values-common.yaml",
"--set=replicaCount=" + str(localnet_config["relayers"]["count"]),
],
image_deps=["pocketd"],
image_keys=[("image.repository", "image.tag")],
)
# Configure tilt resources (tilt labels and port forwards) for all of the nodes above
k8s_resource(
"celestia-rollkit",
labels=["blockchains"],
port_forwards=["26657", "26658", "26659"],
)
k8s_resource(
"sequencer",
labels=["blockchains"],
resource_deps=["celestia-rollkit"],
port_forwards=["36657", "40004"],
)
k8s_resource(
"relayers",
labels=["blockchains"],
resource_deps=["sequencer"],
port_forwards=["8545", "8546", "40005"],
)
k8s_resource("anvil", labels=["blockchains"], port_forwards=["8547"])