Tiltfile 9.7 KB

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