Tiltfile 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. # Graph of dependencies between Dockerfiles, image refs and k8s StatefulSets:
  8. #
  9. # Dockerfile Image ref StatefulSet
  10. # +------------------------------------------------------------------------------+
  11. # rust-1.*
  12. # + +-----------------+
  13. # +-> Dockerfile.agent +-> solana-agent +--------+-----> | [agent] |
  14. # | | +--> | guardian-N |
  15. # +-> solana/Dockerfile +-> solana-contract +---+ | | +-- --------------+
  16. # | | |
  17. # | | |
  18. # | | | +-----------------+
  19. # +--|-----> | solana-devnet |
  20. # golang:1.* +-----> | [setup] |
  21. # + | +-----------------+
  22. # +-> node/Dockerfile +-> guardiand-image +---------+
  23. #
  24. #
  25. # node:lts-alpine
  26. # + +-----------------+
  27. # +-> ethereum/Dockerfile +-> eth-node +------------------> | eth-devnet |
  28. # +-----------------+
  29. #
  30. load("ext://namespace", "namespace_create", "namespace_inject")
  31. allow_k8s_contexts("ci")
  32. # Runtime configuration
  33. config.define_string("num", False, "Number of guardian nodes to run")
  34. # You do not usually need to set this argument - this argument is for debugging only. If you do use a different
  35. # namespace, note that the "wormhole" namespace is hardcoded in the e2e test and don't forget specifying the argument
  36. # when running "tilt down".
  37. #
  38. config.define_string("namespace", False, "Kubernetes namespace to use")
  39. config.define_bool("ci", False, "We are running in CI")
  40. cfg = config.parse()
  41. num_guardians = int(cfg.get("num", "5"))
  42. namespace = cfg.get("namespace", "wormhole")
  43. ci = cfg.get("ci", False)
  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. # protos
  50. proto_deps = ["./proto", "buf.yaml", "buf.gen.yaml"]
  51. local_resource(
  52. name = "proto-gen",
  53. deps = proto_deps,
  54. cmd = "tilt docker build -- --target go-export -f Dockerfile.proto -o type=local,dest=node .",
  55. env = {"DOCKER_BUILDKIT": "1"},
  56. labels = ["protobuf"],
  57. allow_parallel = True,
  58. )
  59. # node
  60. docker_build(
  61. ref = "guardiand-image",
  62. context = "node",
  63. dockerfile = "node/Dockerfile",
  64. )
  65. def build_node_yaml():
  66. node_yaml = read_yaml_stream("devnet/node.yaml")
  67. for obj in node_yaml:
  68. if obj["kind"] == "StatefulSet" and obj["metadata"]["name"] == "guardian":
  69. obj["spec"]["replicas"] = num_guardians
  70. container = obj["spec"]["template"]["spec"]["containers"][0]
  71. if container["name"] != "guardiand":
  72. fail("container 0 is not guardiand")
  73. container["command"] += ["--devNumGuardians", str(num_guardians)]
  74. return encode_yaml_stream(node_yaml)
  75. k8s_yaml_with_ns(build_node_yaml())
  76. k8s_resource(
  77. "guardian",
  78. resource_deps = ["proto-gen", "solana-devnet"],
  79. port_forwards = [
  80. port_forward(6060, name = "Debug/Status Server [:6060]"),
  81. ],
  82. )
  83. # solana agent and cli (runs alongside node)
  84. docker_build(
  85. ref = "solana-agent",
  86. context = ".",
  87. only = ["./proto", "./solana"],
  88. dockerfile = "Dockerfile.agent",
  89. # Ignore target folders from local (non-container) development.
  90. ignore = ["./solana/target", "./solana/agent/target", "./solana/cli/target"],
  91. )
  92. # solana smart contract
  93. docker_build(
  94. ref = "solana-contract",
  95. context = "solana",
  96. dockerfile = "solana/Dockerfile",
  97. )
  98. # solana local devnet
  99. k8s_yaml_with_ns("devnet/solana-devnet.yaml")
  100. k8s_resource("solana-devnet", port_forwards = [
  101. port_forward(8899, name = "Solana RPC [:8899]"),
  102. port_forward(8900, name = "Solana WS [:8900]"),
  103. port_forward(9000, name = "Solana PubSub [:9000]"),
  104. ])
  105. # eth devnet
  106. docker_build(
  107. ref = "eth-node",
  108. context = "./ethereum",
  109. dockerfile = "./ethereum/Dockerfile",
  110. # ignore local node_modules (in case they're present)
  111. ignore = ["./ethereum/node_modules"],
  112. # sync external scripts for incremental development
  113. # (everything else needs to be restarted from scratch for determinism)
  114. #
  115. # This relies on --update-mode=exec to work properly with a non-root user.
  116. # https://github.com/tilt-dev/tilt/issues/3708
  117. live_update = [
  118. sync("./ethereum/src", "/home/node/app/src"),
  119. ],
  120. )
  121. k8s_yaml_with_ns("devnet/eth-devnet.yaml")
  122. k8s_resource("eth-devnet", port_forwards = [
  123. port_forward(8545, name = "Ganache RPC [:8545]"),
  124. ])