You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.3 KiB

  1. # Stack
  2. This is a stripped down version of https://github.com/segmentio/stack
  3. plus some shell scripts.
  4. It is responsible for the following:
  5. - spin up a cluster of nodes
  6. - copy config files for a tendermint testnet to each node
  7. - copy linux binaries for tendermint and the app to each node
  8. - start tendermint on every node
  9. # How it Works
  10. To use, a user must only provide a directory containing two files: `bins` and `run.sh`.
  11. The `bins` file is a list of binaries, for instance:
  12. ```
  13. $GOPATH/bin/tendermint
  14. $GOPATH/bin/dummy
  15. ```
  16. and the `run.sh` specifies how those binaries ought to be started:
  17. ```
  18. #! /bin/bash
  19. if [[ "$SEEDS" != "" ]]; then
  20. SEEDS_FLAG="--seeds=$SEEDS"
  21. fi
  22. ./dummy --persist .tendermint/data/dummy_data >> app.log 2>&1 &
  23. ./tendermint node --log_level=info $SEEDS_FLAG >> tendermint.log 2>&1 &
  24. ```
  25. This let's you specify exactly which versions of Tendermint and the application are to be used,
  26. and how they ought to be started.
  27. Note that these binaries *MUST* be compiled for Linux.
  28. If you are not on Linux, you can compile binaries for linux using `go build` with the `GOOS` variable:
  29. ```
  30. GOOS=linux go build -o $GOPATH/bin/tendermint-linux $GOPATH/src/github.com/tendermint/tendermint/cmd/tendermint
  31. ```
  32. This cross-compilation must be done for each binary you want to copy over.
  33. If you want to use an application that requires more than just a few binaries, you may need to do more manual work,
  34. for instance using `terraforce` to set up the development environment on every machine.
  35. # Dependencies
  36. We use `terraform` for spinning up the machines,
  37. and a custom rolled tool, `terraforce`,
  38. for running commands on many machines in parallel.
  39. You can download terraform here: https://www.terraform.io/downloads.html
  40. To download terraforce, run `go get github.com/ebuchman/terraforce`
  41. We use `tendermint` itself to generate files for a testnet.
  42. You can install `tendermint` with
  43. ```
  44. cd $GOPATH/src/github.com/tendermint/tendermint
  45. glide install
  46. go install ./cmd/tendermint
  47. ```
  48. You also need to set the `DIGITALOCEAN_TOKEN` environment variables so that terraform can
  49. spin up nodes on digital ocean.
  50. This stack is currently some terraform and a bunch of shell scripts,
  51. so its helpful to work out of a directory containing everything.
  52. Either change directory to `$GOPATH/src/github.com/tendermint/tendermint/test/net`
  53. or make a copy of that directory and change to it. All commands are expected to be executed from there.
  54. For terraform to work, you must first run `terraform get`
  55. # Create
  56. To create a cluster with 4 nodes, run
  57. ```
  58. terraform apply
  59. ```
  60. To use a different number of nodes, change the `desired_capacity` parameter in the `main.tf`.
  61. Note that terraform keeps track of the current state of your infrastructure,
  62. so if you change the `desired_capacity` and run `terraform apply` again, it will add or remove nodes as necessary.
  63. If you think that's amazing, so do we.
  64. To get some info about the cluster, run `terraform output`.
  65. See the [terraform docs](https://www.terraform.io/docs/index.html) for more details.
  66. To tear down the cluster, run `terraform destroy`.
  67. # Initialize
  68. Now that we have a cluster up and running, let's generate the necessary files for a Tendermint node and copy them over.
  69. A Tendermint node needs, at the least, a `priv_validator.json` and a `genesis.json`.
  70. To generate files for the nodes, run
  71. ```
  72. tendermint testnet 4 mytestnet
  73. ```
  74. This will create the directory `mytestnet`, containing one directory for each of the 4 nodes.
  75. Each node directory contains a unique `priv_validator.json` and a `genesis.json`,
  76. where the `genesis.json` contains the public keys of all `priv_validator.json` files.
  77. If you want to add more files to each node for your particular app, you'll have to add them to each of the node directories.
  78. Now we can copy everything over to the cluster.
  79. If you are on Linux, run
  80. ```
  81. bash scripts/init.sh 4 mytestnet examples/in-proc
  82. ```
  83. Otherwise (if you are not on Linux), make sure you ran
  84. ```
  85. GOOS=linux go build -o $GOPATH/bin/tendermint-linux $GOPATH/src/github.com/tendermint/tendermint/cmd/tendermint
  86. ```
  87. and now run
  88. ```
  89. bash scripts/init.sh 4 mytestnet examples/in-proc-linux
  90. ```
  91. # Start
  92. Finally, to start Tendermint on all the nodes, run
  93. ```
  94. bash scripts/start.sh 4
  95. ```
  96. # Check
  97. Query the status of all your nodes:
  98. ```
  99. bash scripts/query.sh 4 status
  100. ```