Tiltfile 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. if cfg.get("manual", False):
  40. trigger_mode = TRIGGER_MODE_MANUAL
  41. else:
  42. trigger_mode = TRIGGER_MODE_AUTO
  43. # namespace
  44. if not ci:
  45. namespace_create(namespace)
  46. def k8s_yaml_with_ns(objects):
  47. return k8s_yaml(namespace_inject(objects, namespace))
  48. # wasm
  49. local_resource(
  50. name = "wasm-gen",
  51. cmd = "tilt docker build -- -f Dockerfile.wasm -o type=local,dest=. .",
  52. env = {"DOCKER_BUILDKIT": "1"},
  53. labels = ["wasm"],
  54. allow_parallel=True,
  55. trigger_mode = trigger_mode,
  56. )
  57. def build_node_yaml():
  58. node_yaml = read_yaml_stream("devnet/node.yaml")
  59. for obj in node_yaml:
  60. if obj["kind"] == "StatefulSet" and obj["metadata"]["name"] == "guardian":
  61. obj["spec"]["replicas"] = num_guardians
  62. container = obj["spec"]["template"]["spec"]["containers"][0]
  63. if container["name"] != "guardiand":
  64. fail("container 0 is not guardiand")
  65. container["command"] += ["--devNumGuardians", str(num_guardians)]
  66. return encode_yaml_stream(node_yaml)
  67. k8s_yaml_with_ns(build_node_yaml())
  68. k8s_resource(
  69. "guardian",
  70. resource_deps = ["eth-devnet", "eth-devnet2", "terra-terrad", "solana-devnet"],
  71. port_forwards = [
  72. port_forward(6060, name = "Debug/Status Server [:6060]", host = webHost),
  73. port_forward(7070, name = "Public gRPC [:7070]", host = webHost),
  74. port_forward(7071, name = "Public REST [:7071]", host = webHost),
  75. port_forward(2345, name = "Debugger [:2345]", host = webHost),
  76. ],
  77. labels = ["guardian"],
  78. trigger_mode = trigger_mode,
  79. )
  80. # spy
  81. k8s_yaml_with_ns("devnet/spy.yaml")
  82. k8s_resource(
  83. "spy",
  84. resource_deps = ["guardian"],
  85. port_forwards = [
  86. port_forward(6061, container_port = 6060, name = "Debug/Status Server [:6061]", host = webHost),
  87. port_forward(7072, name = "Spy gRPC [:7072]", host = webHost),
  88. ],
  89. labels = ["guardian"],
  90. trigger_mode = trigger_mode,
  91. )
  92. # solana client cli (used for devnet setup)
  93. docker_build(
  94. ref = "bridge-client",
  95. context = ".",
  96. only = ["./solana"],
  97. dockerfile = "Dockerfile.client",
  98. # Ignore target folders from local (non-container) development.
  99. ignore = ["./solana/*/target"],
  100. )
  101. # solana smart contract
  102. docker_build(
  103. ref = "solana-contract",
  104. context = ".",
  105. dockerfile = "Dockerfile.solana",
  106. )
  107. # solana local devnet
  108. k8s_yaml_with_ns("devnet/solana-devnet.yaml")
  109. k8s_resource(
  110. "solana-devnet",
  111. port_forwards = [
  112. port_forward(8899, name = "Solana RPC [:8899]", host = webHost),
  113. port_forward(8900, name = "Solana WS [:8900]", host = webHost),
  114. port_forward(9000, name = "Solana PubSub [:9000]", host = webHost),
  115. ],
  116. labels = ["solana"],
  117. trigger_mode = trigger_mode,
  118. )
  119. # eth devnet
  120. docker_build(
  121. ref = "eth-node",
  122. context = "./",
  123. dockerfile = "./Dockerfile.ethereum",
  124. # ignore local node_modules (in case they're present)
  125. ignore = ["./ethereum/node_modules", "./third_party/pyth/xc-governance-sdk-js/node_modules"],
  126. # sync external scripts for incremental development
  127. # (everything else needs to be restarted from scratch for determinism)
  128. #
  129. # This relies on --update-mode=exec to work properly with a non-root user.
  130. # https://github.com/tilt-dev/tilt/issues/3708
  131. live_update = [
  132. sync("./ethereum/src", "/home/node/app/src"),
  133. ],
  134. )
  135. # pyth autopublisher
  136. docker_build(
  137. ref = "pyth",
  138. context = ".",
  139. dockerfile = "third_party/pyth/Dockerfile.pyth",
  140. )
  141. k8s_yaml_with_ns("./devnet/pyth.yaml")
  142. k8s_resource(
  143. "pyth",
  144. resource_deps = ["solana-devnet"],
  145. labels = ["pyth"],
  146. trigger_mode = trigger_mode,
  147. )
  148. # pyth2wormhole client autoattester
  149. docker_build(
  150. ref = "p2w-attest",
  151. context = ".",
  152. only = ["./solana", "./third_party", "./pythnet"],
  153. dockerfile = "./third_party/pyth/Dockerfile.p2w-attest",
  154. ignore = ["./solana/*/target"],
  155. )
  156. k8s_yaml_with_ns("devnet/p2w-attest.yaml")
  157. k8s_resource(
  158. "p2w-attest",
  159. resource_deps = ["solana-devnet", "pyth", "guardian"],
  160. port_forwards = [port_forward(3000, name = "metrics", host = webHost)],
  161. labels = ["pyth"],
  162. trigger_mode = trigger_mode,
  163. )
  164. # Pyth2wormhole relay
  165. docker_build(
  166. ref = "p2w-relay",
  167. context = ".",
  168. dockerfile = "third_party/pyth/p2w-relay/Dockerfile.pyth_relay",
  169. )
  170. k8s_yaml_with_ns("devnet/p2w-terra-relay.yaml")
  171. k8s_resource(
  172. "p2w-terra-relay",
  173. resource_deps = ["pyth", "p2w-attest", "spy", "terra-terrad", "wasm-gen"],
  174. port_forwards = [
  175. port_forward(4200, name = "Rest API (Status + Query) [:4200]", host = webHost),
  176. port_forward(8081, name = "Prometheus [:8081]", host = webHost)],
  177. labels = ["pyth"]
  178. )
  179. k8s_yaml_with_ns("devnet/p2w-evm-relay.yaml")
  180. k8s_resource(
  181. "p2w-evm-relay",
  182. resource_deps = ["pyth", "p2w-attest", "spy", "eth-devnet", "wasm-gen"],
  183. port_forwards = [
  184. port_forward(4201, container_port = 4200, name = "Rest API (Status + Query) [:4201]", host = webHost),
  185. port_forward(8082, container_port = 8081, name = "Prometheus [:8082]", host = webHost)],
  186. labels = ["pyth"]
  187. )
  188. # Pyth Price service
  189. docker_build(
  190. ref = "pyth-price-service",
  191. context = ".",
  192. dockerfile = "third_party/pyth/price-service/Dockerfile.price_service",
  193. )
  194. k8s_yaml_with_ns("devnet/pyth-price-service.yaml")
  195. k8s_resource(
  196. "pyth-price-service",
  197. resource_deps = ["pyth", "p2w-attest", "spy", "eth-devnet", "wasm-gen"],
  198. port_forwards = [
  199. port_forward(4202, container_port = 4200, name = "Rest API (Status + Query) [:4202]", host = webHost),
  200. port_forward(6202, container_port = 6200, name = "WSS API [:6202]", host = webHost),
  201. port_forward(8083, container_port = 8081, name = "Prometheus [:8083]", host = webHost)],
  202. labels = ["pyth"]
  203. )
  204. # Pyth EVM Watcher
  205. docker_build(
  206. ref = "pyth-evm-watcher",
  207. context = "third_party/pyth/evm-watcher/",
  208. dockerfile = "third_party/pyth/evm-watcher/Dockerfile",
  209. )
  210. k8s_yaml_with_ns("devnet/pyth-evm-watcher.yaml")
  211. k8s_resource(
  212. "pyth-evm-watcher",
  213. resource_deps = ["eth-devnet"],
  214. labels = ["pyth"]
  215. )
  216. k8s_yaml_with_ns("devnet/eth-devnet.yaml")
  217. k8s_resource(
  218. "eth-devnet",
  219. port_forwards = [
  220. port_forward(8545, name = "Ganache RPC [:8545]", host = webHost),
  221. ],
  222. labels = ["evm"],
  223. trigger_mode = trigger_mode,
  224. )
  225. k8s_resource(
  226. "eth-devnet2",
  227. port_forwards = [
  228. port_forward(8546, name = "Ganache RPC [:8546]", host = webHost),
  229. ],
  230. labels = ["evm"],
  231. trigger_mode = trigger_mode,
  232. )
  233. # terra devnet
  234. docker_build(
  235. ref = "terra-image",
  236. context = "./cosmwasm/devnet",
  237. dockerfile = "cosmwasm/devnet/Dockerfile",
  238. )
  239. docker_build(
  240. ref = "cosmwasm-contracts",
  241. context = ".",
  242. dockerfile = "Dockerfile.cosmwasm",
  243. )
  244. k8s_yaml_with_ns("devnet/terra-devnet.yaml")
  245. k8s_resource(
  246. "terra-terrad",
  247. port_forwards = [
  248. port_forward(26657, name = "Terra RPC [:26657]", host = webHost),
  249. port_forward(1317, name = "Terra LCD [:1317]", host = webHost),
  250. ],
  251. labels = ["terra"],
  252. trigger_mode = trigger_mode,
  253. )
  254. k8s_resource(
  255. "terra-postgres",
  256. labels = ["terra"],
  257. trigger_mode = trigger_mode,
  258. )
  259. k8s_resource(
  260. "terra-fcd",
  261. resource_deps = ["terra-terrad", "terra-postgres"],
  262. port_forwards = [port_forward(3060, name = "Terra FCD [:3060]", host = webHost)],
  263. labels = ["terra"],
  264. trigger_mode = trigger_mode,
  265. )
  266. docker_build(
  267. ref = "prometheus",
  268. context = ".",
  269. dockerfile = "Dockerfile.prometheus",
  270. )
  271. k8s_yaml_with_ns("devnet/prometheus.yaml")
  272. k8s_resource(
  273. "prometheus",
  274. port_forwards = [port_forward(9090, name = "Prometheus dashboard", host = webHost)],
  275. labels = ["prometheus"],
  276. trigger_mode = trigger_mode,
  277. )