Tiltfile 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. # This Tiltfile contains the deployment and build config for the Wormhole devnet.
  2. #
  3. # We use Buildkit cache mounts and careful layering to avoid unnecessary rebuilds - almost
  4. # all source code changes result in small, incremental rebuilds. Dockerfiles are written such
  5. # that, for example, changing the contract source code won't cause Solana itself to be rebuilt.
  6. #
  7. load("ext://namespace", "namespace_create", "namespace_inject")
  8. load("ext://secret", "secret_yaml_generic")
  9. allow_k8s_contexts("ci")
  10. # Disable telemetry by default
  11. analytics_settings(False)
  12. # Moar updates (default is 3)
  13. update_settings(max_parallel_updates=10)
  14. # Runtime configuration
  15. config.define_bool("ci", False, "We are running in CI")
  16. config.define_bool("manual", False, "Set TRIGGER_MODE_MANUAL by default")
  17. config.define_string("num", False, "Number of guardian nodes to run")
  18. # You do not usually need to set this argument - this argument is for debugging only. If you do use a different
  19. # namespace, note that the "wormhole" namespace is hardcoded in tests and don't forget specifying the argument
  20. # when running "tilt down".
  21. #
  22. config.define_string("namespace", False, "Kubernetes namespace to use")
  23. # These arguments will enable writing Guardian events to a cloud BigTable instance.
  24. # Writing to a cloud BigTable is optional. These arguments are not required to run the devnet.
  25. config.define_string("gcpProject", False, "GCP project ID for BigTable persistence")
  26. config.define_string("bigTableKeyPath", False, "Path to BigTable json key file")
  27. # When running Tilt on a server, this can be used to set the public hostname Tilt runs on
  28. # for service links in the UI to work.
  29. config.define_string("webHost", False, "Public hostname for port forwards")
  30. # Components
  31. config.define_bool("pyth", False, "Enable Pyth-to-Wormhole component")
  32. cfg = config.parse()
  33. num_guardians = int(cfg.get("num", "1"))
  34. namespace = cfg.get("namespace", "wormhole")
  35. gcpProject = cfg.get("gcpProject", "local-dev")
  36. bigTableKeyPath = cfg.get("bigTableKeyPath", "./event_database/devnet_key.json")
  37. webHost = cfg.get("webHost", "localhost")
  38. ci = cfg.get("ci", False)
  39. pyth = cfg.get("pyth", ci)
  40. if cfg.get("manual", False):
  41. trigger_mode = TRIGGER_MODE_MANUAL
  42. else:
  43. trigger_mode = TRIGGER_MODE_AUTO
  44. # namespace
  45. if not ci:
  46. namespace_create(namespace)
  47. def k8s_yaml_with_ns(objects):
  48. return k8s_yaml(namespace_inject(objects, namespace))
  49. # wasm
  50. local_resource(
  51. name = "wasm-gen",
  52. cmd = "tilt docker build -- -f Dockerfile.wasm -o type=local,dest=. .",
  53. env = {"DOCKER_BUILDKIT": "1"},
  54. labels = ["wasm"],
  55. allow_parallel=True,
  56. trigger_mode = trigger_mode,
  57. )
  58. docker_build(
  59. ref = "guardiand-image",
  60. context = ".",
  61. dockerfile = "Dockerfile.guardian",
  62. )
  63. def build_node_yaml():
  64. node_yaml = read_yaml_stream("devnet/node.yaml")
  65. for obj in node_yaml:
  66. if obj["kind"] == "StatefulSet" and obj["metadata"]["name"] == "guardian":
  67. obj["spec"]["replicas"] = num_guardians
  68. container = obj["spec"]["template"]["spec"]["containers"][0]
  69. if container["name"] != "guardiand":
  70. fail("container 0 is not guardiand")
  71. container["command"] += ["--devNumGuardians", str(num_guardians)]
  72. return encode_yaml_stream(node_yaml)
  73. k8s_yaml_with_ns(build_node_yaml())
  74. k8s_resource(
  75. "guardian",
  76. resource_deps = ["eth-devnet", "eth-devnet2", "terra-terrad", "solana-devnet"],
  77. port_forwards = [
  78. port_forward(6060, name = "Debug/Status Server [:6060]", host = webHost),
  79. port_forward(7070, name = "Public gRPC [:7070]", host = webHost),
  80. port_forward(7071, name = "Public REST [:7071]", host = webHost),
  81. port_forward(2345, name = "Debugger [:2345]", host = webHost),
  82. ],
  83. labels = ["guardian"],
  84. trigger_mode = trigger_mode,
  85. )
  86. # spy
  87. k8s_yaml_with_ns("devnet/spy.yaml")
  88. k8s_resource(
  89. "spy",
  90. resource_deps = ["guardian"],
  91. port_forwards = [
  92. port_forward(6061, container_port = 6060, name = "Debug/Status Server [:6061]", host = webHost),
  93. port_forward(7072, name = "Spy gRPC [:7072]", host = webHost),
  94. ],
  95. labels = ["guardian"],
  96. trigger_mode = trigger_mode,
  97. )
  98. # solana client cli (used for devnet setup)
  99. docker_build(
  100. ref = "bridge-client",
  101. context = ".",
  102. only = ["./solana"],
  103. dockerfile = "Dockerfile.client",
  104. # Ignore target folders from local (non-container) development.
  105. ignore = ["./solana/*/target"],
  106. )
  107. # solana smart contract
  108. docker_build(
  109. ref = "solana-contract",
  110. context = ".",
  111. dockerfile = "Dockerfile.solana",
  112. )
  113. # solana local devnet
  114. k8s_yaml_with_ns("devnet/solana-devnet.yaml")
  115. k8s_resource(
  116. "solana-devnet",
  117. port_forwards = [
  118. port_forward(8899, name = "Solana RPC [:8899]", host = webHost),
  119. port_forward(8900, name = "Solana WS [:8900]", host = webHost),
  120. port_forward(9000, name = "Solana PubSub [:9000]", host = webHost),
  121. ],
  122. labels = ["solana"],
  123. trigger_mode = trigger_mode,
  124. )
  125. # eth devnet
  126. docker_build(
  127. ref = "eth-node",
  128. context = "./ethereum",
  129. dockerfile = "./ethereum/Dockerfile",
  130. # ignore local node_modules (in case they're present)
  131. ignore = ["./ethereum/node_modules"],
  132. # sync external scripts for incremental development
  133. # (everything else needs to be restarted from scratch for determinism)
  134. #
  135. # This relies on --update-mode=exec to work properly with a non-root user.
  136. # https://github.com/tilt-dev/tilt/issues/3708
  137. live_update = [
  138. sync("./ethereum/src", "/home/node/app/src"),
  139. ],
  140. )
  141. if pyth:
  142. # pyth autopublisher
  143. docker_build(
  144. ref = "pyth",
  145. context = ".",
  146. dockerfile = "third_party/pyth/Dockerfile.pyth",
  147. )
  148. k8s_yaml_with_ns("./devnet/pyth.yaml")
  149. k8s_resource(
  150. "pyth",
  151. resource_deps = ["solana-devnet"],
  152. labels = ["pyth"],
  153. trigger_mode = trigger_mode,
  154. )
  155. # pyth2wormhole client autoattester
  156. docker_build(
  157. ref = "p2w-attest",
  158. context = ".",
  159. only = ["./solana", "./third_party"],
  160. dockerfile = "./third_party/pyth/Dockerfile.p2w-attest",
  161. ignore = ["./solana/*/target"],
  162. )
  163. k8s_yaml_with_ns("devnet/p2w-attest.yaml")
  164. k8s_resource(
  165. "p2w-attest",
  166. resource_deps = ["solana-devnet", "pyth", "guardian"],
  167. port_forwards = [],
  168. labels = ["pyth"],
  169. trigger_mode = trigger_mode,
  170. )
  171. # Pyth2wormhole relay
  172. docker_build(
  173. ref = "p2w-relay",
  174. context = ".",
  175. dockerfile = "third_party/pyth/p2w-relay/Dockerfile.pyth_relay",
  176. )
  177. k8s_yaml_with_ns("devnet/p2w-terra-relay.yaml")
  178. k8s_resource(
  179. "p2w-terra-relay",
  180. resource_deps = ["pyth", "p2w-attest", "spy", "terra-terrad", "wasm-gen"],
  181. port_forwards = [
  182. port_forward(4200, name = "Rest API (Status + Query) [:4200]", host = webHost),
  183. port_forward(8081, name = "Prometheus [:8081]", host = webHost)],
  184. labels = ["pyth"]
  185. )
  186. k8s_yaml_with_ns("devnet/p2w-evm-relay.yaml")
  187. k8s_resource(
  188. "p2w-evm-relay",
  189. resource_deps = ["pyth", "p2w-attest", "spy", "eth-devnet", "wasm-gen"],
  190. port_forwards = [
  191. port_forward(4201, container_port = 4200, name = "Rest API (Status + Query) [:4201]", host = webHost),
  192. port_forward(8082, container_port = 8081, name = "Prometheus [:8082]", host = webHost)],
  193. labels = ["pyth"]
  194. )
  195. # Pyth Price service
  196. docker_build(
  197. ref = "pyth-price-service",
  198. context = ".",
  199. dockerfile = "third_party/pyth/price-service/Dockerfile.price_service",
  200. )
  201. k8s_yaml_with_ns("devnet/pyth-price-service.yaml")
  202. k8s_resource(
  203. "pyth-price-service",
  204. resource_deps = ["pyth", "p2w-attest", "spy", "eth-devnet", "wasm-gen"],
  205. port_forwards = [
  206. port_forward(4202, container_port = 4200, name = "Rest API (Status + Query) [:4202]", host = webHost),
  207. port_forward(8083, container_port = 8081, name = "Prometheus [:8083]", host = webHost)],
  208. labels = ["pyth"]
  209. )
  210. k8s_yaml_with_ns("devnet/eth-devnet.yaml")
  211. k8s_resource(
  212. "eth-devnet",
  213. port_forwards = [
  214. port_forward(8545, name = "Ganache RPC [:8545]", host = webHost),
  215. ],
  216. labels = ["evm"],
  217. trigger_mode = trigger_mode,
  218. )
  219. k8s_resource(
  220. "eth-devnet2",
  221. port_forwards = [
  222. port_forward(8546, name = "Ganache RPC [:8546]", host = webHost),
  223. ],
  224. labels = ["evm"],
  225. trigger_mode = trigger_mode,
  226. )
  227. # terra devnet
  228. docker_build(
  229. ref = "terra-image",
  230. context = "./terra/devnet",
  231. dockerfile = "terra/devnet/Dockerfile",
  232. )
  233. docker_build(
  234. ref = "terra-contracts",
  235. context = ".",
  236. dockerfile = "Dockerfile.terra",
  237. )
  238. k8s_yaml_with_ns("devnet/terra-devnet.yaml")
  239. k8s_resource(
  240. "terra-terrad",
  241. port_forwards = [
  242. port_forward(26657, name = "Terra RPC [:26657]", host = webHost),
  243. port_forward(1317, name = "Terra LCD [:1317]", host = webHost),
  244. ],
  245. labels = ["terra"],
  246. trigger_mode = trigger_mode,
  247. )
  248. k8s_resource(
  249. "terra-postgres",
  250. labels = ["terra"],
  251. trigger_mode = trigger_mode,
  252. )
  253. k8s_resource(
  254. "terra-fcd",
  255. resource_deps = ["terra-terrad", "terra-postgres"],
  256. port_forwards = [port_forward(3060, name = "Terra FCD [:3060]", host = webHost)],
  257. labels = ["terra"],
  258. trigger_mode = trigger_mode,
  259. )