forked from wormhole-foundation/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
374 lines (305 loc) · 10.9 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# This Tiltfile contains the deployment and build config for the Wormhole devnet.
#
# We use Buildkit cache mounts and careful layering to avoid unnecessary rebuilds - almost
# all source code changes result in small, incremental rebuilds. Dockerfiles are written such
# that, for example, changing the contract source code won't cause Solana itself to be rebuilt.
#
load("ext://namespace", "namespace_create", "namespace_inject")
load("ext://secret", "secret_yaml_generic")
allow_k8s_contexts("ci")
# Disable telemetry by default
analytics_settings(False)
# Runtime configuration
config.define_bool("ci", False, "We are running in CI")
config.define_string("num", False, "Number of guardian nodes to run")
# You do not usually need to set this argument - this argument is for debugging only. If you do use a different
# namespace, note that the "wormhole" namespace is hardcoded in tests and don't forget specifying the argument
# when running "tilt down".
#
config.define_string("namespace", False, "Kubernetes namespace to use")
# These arguments will enable writing Guardian events to a cloud BigTable instance.
# Writing to a cloud BigTable is optional. These arguments are not required to run the devnet.
config.define_string("gcpProject", False, "GCP project ID for BigTable persistence")
config.define_string("bigTableKeyPath", False, "Path to BigTable json key file")
# Components
config.define_bool("pyth", False, "Enable Pyth-to-Wormhole component")
config.define_bool("explorer", False, "Enable explorer component")
config.define_bool("bridge_ui", False, "Enable bridge UI component")
cfg = config.parse()
num_guardians = int(cfg.get("num", "1"))
namespace = cfg.get("namespace", "wormhole")
gcpProject = cfg.get("gcpProject", "local-dev")
bigTableKeyPath = cfg.get("bigTableKeyPath", "./event_database/devnet_key.json")
ci = cfg.get("ci", False)
pyth = cfg.get("pyth", ci)
explorer = cfg.get("explorer", ci)
bridge_ui = cfg.get("bridge_ui", ci)
# namespace
if not ci:
namespace_create(namespace)
def k8s_yaml_with_ns(objects):
return k8s_yaml(namespace_inject(objects, namespace))
# protos
proto_deps = ["./proto", "./generate-protos.sh", "buf.yaml", "buf.gen.yaml"]
local_resource(
name = "proto-gen",
deps = proto_deps,
cmd = "tilt docker build -- --target go-export -f Dockerfile.proto -o type=local,dest=node .",
env = {"DOCKER_BUILDKIT": "1"},
)
local_resource(
name = "proto-gen-web",
deps = proto_deps,
resource_deps = ["proto-gen"],
cmd = "tilt docker build -- --target node-export -f Dockerfile.proto -o type=local,dest=. .",
env = {"DOCKER_BUILDKIT": "1"},
)
# wasm
local_resource(
name = "wasm-gen",
deps = ["solana"],
dir = "solana",
cmd = "tilt docker build -- -f Dockerfile.wasm -o type=local,dest=.. .",
env = {"DOCKER_BUILDKIT": "1"},
)
# node
if explorer:
k8s_yaml_with_ns(
secret_yaml_generic(
"node-bigtable-key",
from_file = "bigtable-key.json=" + bigTableKeyPath,
),
)
docker_build(
ref = "guardiand-image",
context = "node",
dockerfile = "node/Dockerfile",
)
def build_node_yaml():
node_yaml = read_yaml_stream("devnet/node.yaml")
for obj in node_yaml:
if obj["kind"] == "StatefulSet" and obj["metadata"]["name"] == "guardian":
obj["spec"]["replicas"] = num_guardians
container = obj["spec"]["template"]["spec"]["containers"][0]
if container["name"] != "guardiand":
fail("container 0 is not guardiand")
container["command"] += ["--devNumGuardians", str(num_guardians)]
if explorer:
container["command"] += [
"--bigTablePersistenceEnabled",
"--bigTableInstanceName",
"wormhole",
"--bigTableTableName",
"v2Events",
"--bigTableKeyPath",
"/tmp/mounted-keys/bigtable-key.json",
"--bigTableGCPProject",
gcpProject,
]
return encode_yaml_stream(node_yaml)
k8s_yaml_with_ns(build_node_yaml())
k8s_resource("guardian", resource_deps = ["proto-gen", "solana-devnet"], port_forwards = [
port_forward(6060, name = "Debug/Status Server [:6060]"),
port_forward(7070, name = "Public gRPC [:7070]"),
port_forward(7071, name = "Public REST [:7071]"),
port_forward(2345, name = "Debugger [:2345]"),
])
# solana client cli (used for devnet setup)
docker_build(
ref = "bridge-client",
context = ".",
only = ["./proto", "./solana", "./ethereum", "./clients"],
dockerfile = "Dockerfile.client",
# Ignore target folders from local (non-container) development.
ignore = ["./solana/*/target"],
)
# solana smart contract
docker_build(
ref = "solana-contract",
context = "solana",
dockerfile = "solana/Dockerfile",
)
# solana local devnet
k8s_yaml_with_ns("devnet/solana-devnet.yaml")
k8s_resource(
"solana-devnet",
resource_deps = ["wasm-gen"],
port_forwards = [
port_forward(8899, name = "Solana RPC [:8899]"),
port_forward(8900, name = "Solana WS [:8900]"),
port_forward(9000, name = "Solana PubSub [:9000]"),
],
)
# eth devnet
docker_build(
ref = "eth-node",
context = "./ethereum",
dockerfile = "./ethereum/Dockerfile",
# ignore local node_modules (in case they're present)
ignore = ["./ethereum/node_modules"],
# sync external scripts for incremental development
# (everything else needs to be restarted from scratch for determinism)
#
# This relies on --update-mode=exec to work properly with a non-root user.
# https://github.com/tilt-dev/tilt/issues/3708
live_update = [
sync("./ethereum/src", "/home/node/app/src"),
],
)
if pyth:
# pyth autopublisher
docker_build(
ref = "pyth",
context = ".",
dockerfile = "third_party/pyth/Dockerfile.pyth",
)
k8s_yaml_with_ns("./devnet/pyth.yaml")
k8s_resource("pyth", resource_deps = ["solana-devnet"])
# pyth2wormhole client autoattester
docker_build(
ref = "p2w-attest",
context = ".",
only = ["./solana", "./third_party"],
dockerfile = "./third_party/pyth/Dockerfile.p2w-attest",
ignore = ["./solana/*/target"],
)
k8s_yaml_with_ns("devnet/p2w-attest.yaml")
k8s_resource(
"p2w-attest",
resource_deps = ["solana-devnet", "pyth", "guardian"],
port_forwards = [],
)
k8s_yaml_with_ns("devnet/eth-devnet.yaml")
k8s_resource("eth-devnet", port_forwards = [
port_forward(8545, name = "Ganache RPC [:8545]"),
])
k8s_resource("eth-devnet2", port_forwards = [
port_forward(8546, name = "Ganache RPC [:8546]"),
])
if bridge_ui:
docker_build(
ref = "bridge-ui",
context = ".",
only = ["./ethereum", "./sdk", "./bridge_ui"],
dockerfile = "bridge_ui/Dockerfile",
live_update = [
sync("./bridge_ui/src", "/app/bridge_ui/src"),
],
)
k8s_yaml_with_ns("devnet/bridge-ui.yaml")
k8s_resource(
"bridge-ui",
resource_deps = ["proto-gen-web", "wasm-gen"],
port_forwards = [
port_forward(3000, name = "Bridge UI [:3000]"),
],
)
# bigtable
def build_cloud_function(container_name, go_func_name, path, builder):
# Invokes Tilt's custom_build(), with a Pack command.
# inspired by https://github.com/tilt-dev/tilt-extensions/tree/master/pack
tag = "latest"
caching_ref = container_name + ":" + tag
pack_build_cmd = " ".join([
"./tools/bin/pack build",
caching_ref,
"--path " + path,
"--builder " + builder,
"--run-image devnet-cloud-function",
"--env " + "GOOGLE_FUNCTION_TARGET=%s" % go_func_name,
"--env " + "GOOGLE_FUNCTION_SIGNATURE_TYPE=http",
])
disable_push = True
skips_local_docker = True
if ci:
# inherit the DOCKER_HOST socket provided by custom_build.
pack_build_cmd = pack_build_cmd + " --docker-host inherit"
# do not attempt to access Docker cache in CI
# pack_build_cmd = pack_build_cmd + " --clear-cache"
# don't try to pull previous container versions in CI
pack_build_cmd = pack_build_cmd + " --pull-policy never"
# push to kubernetes registry
disable_push = False
skips_local_docker = False
docker_tag_cmd = "tilt docker -- tag " + caching_ref + " $EXPECTED_REF"
custom_build(
container_name,
pack_build_cmd + " && " + docker_tag_cmd,
[path],
tag=tag,
skips_local_docker=skips_local_docker,
disable_push=disable_push,
)
if explorer:
local_resource(
name = "devnet-cloud-function",
cmd = "tilt docker -- build -f ./event_database/cloud_functions/Dockerfile.run . -t devnet-cloud-function --label builtby=tilt",
env = {"DOCKER_BUILDKIT": "1"},
labels = ["explorer"],
)
local_resource(
name = "pack-bin",
cmd = "go build -mod=readonly -o bin/pack github.com/buildpacks/pack/cmd/pack",
dir = "tools",
labels = ["explorer"],
)
k8s_yaml_with_ns("devnet/bigtable.yaml")
k8s_resource("bigtable-emulator",
port_forwards = [port_forward(8086, name = "BigTable clients [:8086]")],
labels = ["explorer"],
)
build_cloud_function(
container_name = "bigtable-functions",
go_func_name = "Entry",
path = "./event_database/cloud_functions",
builder = "gcr.io/buildpacks/builder:v1",
)
k8s_resource(
"bigtable-functions",
resource_deps = ["proto-gen", "bigtable-emulator"],
port_forwards = [port_forward(8090, name = "BigTable Functions [:8090]")],
labels = ["explorer"]
)
# explorer web app
docker_build(
ref = "explorer",
context = "./explorer",
dockerfile = "./explorer/Dockerfile",
ignore = ["./explorer/node_modules"],
live_update = [
sync("./explorer/src", "/home/node/app/src"),
sync("./explorer/public", "/home/node/app/public"),
],
)
k8s_yaml_with_ns("devnet/explorer.yaml")
k8s_resource(
"explorer",
resource_deps = ["proto-gen-web"],
port_forwards = [
port_forward(8001, name = "Explorer Web UI [:8001]"),
],
labels = ["explorer"],
)
# terra devnet
docker_build(
ref = "terra-image",
context = "./terra/devnet",
dockerfile = "terra/devnet/Dockerfile",
)
docker_build(
ref = "terra-contracts",
context = "./terra",
dockerfile = "./terra/Dockerfile",
)
k8s_yaml_with_ns("devnet/terra-devnet.yaml")
k8s_resource(
"terra-terrad",
port_forwards = [
port_forward(26657, name = "Terra RPC [:26657]"),
port_forward(1317, name = "Terra LCD [:1317]"),
],
)
k8s_resource(
"terra-fcd",
port_forwards = [port_forward(3060, name = "Terra FCD [:3060]")],
)