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.

306 lines
10 KiB

7 years ago
9 years ago
  1. GOTOOLS = \
  2. github.com/mitchellh/gox \
  3. github.com/golangci/golangci-lint/cmd/golangci-lint \
  4. github.com/gogo/protobuf/protoc-gen-gogo \
  5. github.com/square/certstrap
  6. GOBIN?=${GOPATH}/bin
  7. PACKAGES=$(shell go list ./...)
  8. OUTPUT?=build/tendermint
  9. export GO111MODULE = on
  10. INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
  11. BUILD_TAGS?='tendermint'
  12. BUILD_FLAGS = -mod=readonly -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`"
  13. all: check build test install
  14. check: check_tools
  15. ########################################
  16. ### Build Tendermint
  17. build:
  18. CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/
  19. build_c:
  20. CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" -o $(OUTPUT) ./cmd/tendermint/
  21. build_race:
  22. CGO_ENABLED=0 go build -race $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint
  23. install:
  24. CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tendermint
  25. install_c:
  26. CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS) cleveldb" ./cmd/tendermint
  27. ########################################
  28. ### Protobuf
  29. protoc_all: protoc_libs protoc_merkle protoc_abci protoc_grpc protoc_proto3types
  30. %.pb.go: %.proto
  31. ## If you get the following error,
  32. ## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
  33. ## See https://stackoverflow.com/a/25518702
  34. ## Note the $< here is substituted for the %.proto
  35. ## Note the $@ here is substituted for the %.pb.go
  36. protoc $(INCLUDE) $< --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,plugins=grpc:.
  37. ########################################
  38. ### Build ABCI
  39. # see protobuf section above
  40. protoc_abci: abci/types/types.pb.go
  41. protoc_proto3types: types/proto3/block.pb.go
  42. build_abci:
  43. @go build -mod=readonly -i ./abci/cmd/...
  44. install_abci:
  45. @go install -mod=readonly ./abci/cmd/...
  46. ########################################
  47. ### Distribution
  48. # dist builds binaries for all platforms and packages them for distribution
  49. # TODO add abci to these scripts
  50. dist:
  51. @BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'"
  52. ########################################
  53. ### Tools & dependencies
  54. check_tools:
  55. @# https://stackoverflow.com/a/25668869
  56. @echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
  57. $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
  58. get_tools:
  59. @echo "--> Installing tools"
  60. ./scripts/get_tools.sh
  61. update_tools:
  62. @echo "--> Updating tools"
  63. ./scripts/get_tools.sh
  64. #For ABCI and libs
  65. get_protoc:
  66. @# https://github.com/google/protobuf/releases
  67. curl -L https://github.com/google/protobuf/releases/download/v3.6.1/protobuf-cpp-3.6.1.tar.gz | tar xvz && \
  68. cd protobuf-3.6.1 && \
  69. DIST_LANG=cpp ./configure && \
  70. make && \
  71. make check && \
  72. sudo make install && \
  73. sudo ldconfig && \
  74. cd .. && \
  75. rm -rf protobuf-3.6.1
  76. draw_deps:
  77. @# requires brew install graphviz or apt-get install graphviz
  78. go get github.com/RobotsAndPencils/goviz
  79. @goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
  80. get_deps_bin_size:
  81. @# Copy of build recipe with additional flags to perform binary size analysis
  82. $(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/ 2>&1))
  83. @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
  84. @echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
  85. ########################################
  86. ### Libs
  87. protoc_libs: libs/common/types.pb.go
  88. gen_certs: clean_certs
  89. ## Generating certificates for TLS testing...
  90. certstrap init --common-name "tendermint.com" --passphrase ""
  91. certstrap request-cert -ip "::" --passphrase ""
  92. certstrap sign "::" --CA "tendermint.com" --passphrase ""
  93. mv out/::.crt out/::.key db/remotedb
  94. clean_certs:
  95. ## Cleaning TLS testing certificates...
  96. rm -rf out
  97. rm -f db/remotedb/::.crt db/remotedb/::.key
  98. test_libs: gen_certs
  99. go test -tags clevedb boltdb $(PACKAGES)
  100. make clean_certs
  101. grpc_dbserver:
  102. protoc -I db/remotedb/proto/ db/remotedb/proto/defs.proto --go_out=plugins=grpc:db/remotedb/proto
  103. protoc_grpc: rpc/grpc/types.pb.go
  104. protoc_merkle: crypto/merkle/merkle.pb.go
  105. ########################################
  106. ### Testing
  107. ## required to be run first by most tests
  108. build_docker_test_image:
  109. docker build -t tester -f ./test/docker/Dockerfile .
  110. ### coverage, app, persistence, and libs tests
  111. test_cover:
  112. # run the go unit tests with coverage
  113. bash test/test_cover.sh
  114. test_apps:
  115. # run the app tests using bash
  116. # requires `abci-cli` and `tendermint` binaries installed
  117. bash test/app/test.sh
  118. test_abci_apps:
  119. bash abci/tests/test_app/test.sh
  120. test_abci_cli:
  121. # test the cli against the examples in the tutorial at:
  122. # ./docs/abci-cli.md
  123. # if test fails, update the docs ^
  124. @ bash abci/tests/test_cli/test.sh
  125. test_persistence:
  126. # run the persistence tests using bash
  127. # requires `abci-cli` installed
  128. docker run --name run_persistence -t tester bash test/persist/test_failure_indices.sh
  129. # TODO undockerize
  130. # bash test/persist/test_failure_indices.sh
  131. test_p2p:
  132. docker rm -f rsyslog || true
  133. rm -rf test/logs || true
  134. mkdir test/logs
  135. cd test/
  136. docker run -d -v "logs:/var/log/" -p 127.0.0.1:5514:514/udp --name rsyslog voxxit/rsyslog
  137. cd ..
  138. # requires 'tester' the image from above
  139. bash test/p2p/test.sh tester
  140. # the `docker cp` takes a really long time; uncomment for debugging
  141. #
  142. # mkdir -p test/p2p/logs && docker cp rsyslog:/var/log test/p2p/logs
  143. test_integrations:
  144. make build_docker_test_image
  145. make get_tools
  146. make install
  147. make test_cover
  148. make test_apps
  149. make test_abci_apps
  150. make test_abci_cli
  151. make test_libs
  152. make test_persistence
  153. make test_p2p
  154. test_release:
  155. @go test -tags release $(PACKAGES)
  156. test100:
  157. @for i in {1..100}; do make test; done
  158. vagrant_test:
  159. vagrant up
  160. vagrant ssh -c 'make test_integrations'
  161. ### go tests
  162. test:
  163. @echo "--> Running go test"
  164. @go test -p 1 $(PACKAGES)
  165. test_race:
  166. @echo "--> Running go test --race"
  167. @go test -p 1 -v -race $(PACKAGES)
  168. # uses https://github.com/sasha-s/go-deadlock/ to detect potential deadlocks
  169. test_with_deadlock:
  170. make set_with_deadlock
  171. make test
  172. make cleanup_after_test_with_deadlock
  173. set_with_deadlock:
  174. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.RWMutex/deadlock.RWMutex/'
  175. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.Mutex/deadlock.Mutex/'
  176. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
  177. # cleanes up after you ran test_with_deadlock
  178. cleanup_after_test_with_deadlock:
  179. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/deadlock.RWMutex/sync.RWMutex/'
  180. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/deadlock.Mutex/sync.Mutex/'
  181. find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
  182. ########################################
  183. ### Formatting, linting, and vetting
  184. fmt:
  185. @go fmt ./...
  186. lint:
  187. @echo "--> Running linter"
  188. @golangci-lint run
  189. DESTINATION = ./index.html.md
  190. rpc-docs:
  191. cat rpc/core/slate_header.txt > $(DESTINATION)
  192. godoc2md -template rpc/core/doc_template.txt github.com/tendermint/tendermint/rpc/core | grep -v -e "pipe.go" -e "routes.go" -e "dev.go" | sed 's,/src/target,https://github.com/tendermint/tendermint/tree/master/rpc/core,' >> $(DESTINATION)
  193. ###########################################################
  194. ### Docker image
  195. build-docker:
  196. cp $(OUTPUT) DOCKER/tendermint
  197. docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
  198. rm -rf DOCKER/tendermint
  199. ###########################################################
  200. ### Local testnet using docker
  201. # Build linux binary on other platforms
  202. build-linux: get_tools
  203. GOOS=linux GOARCH=amd64 $(MAKE) build
  204. build-docker-localnode:
  205. @cd networks/local && make
  206. # Run a 4-node testnet locally
  207. localnet-start: localnet-stop
  208. @if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --v 4 --o . --populate-persistent-peers --starting-ip-address 192.167.10.2 ; fi
  209. docker-compose up
  210. # Stop testnet
  211. localnet-stop:
  212. docker-compose down
  213. ###########################################################
  214. ### Remote full-nodes (sentry) using terraform and ansible
  215. # Server management
  216. sentry-start:
  217. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  218. @if ! [ -f $(HOME)/.ssh/id_rsa.pub ]; then ssh-keygen ; fi
  219. cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  220. @if ! [ -f $(CURDIR)/build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/tendermint:Z tendermint/localnode testnet --v 0 --n 4 --o . ; fi
  221. cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  222. @echo "Next step: Add your validator setup in the genesis.json and config.tml files and run \"make sentry-config\". (Public key of validator, chain ID, peer IP and node ID.)"
  223. # Configuration management
  224. sentry-config:
  225. cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$(CURDIR)/build/tendermint -e CONFIGDIR=$(CURDIR)/build
  226. sentry-stop:
  227. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  228. cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  229. # meant for the CI, inspect script & adapt accordingly
  230. build-slate:
  231. bash scripts/slate.sh
  232. # To avoid unintended conflicts with file names, always add to .PHONY
  233. # unless there is a reason not to.
  234. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
  235. .PHONY: check build build_race build_abci dist install install_abci check_tools get_tools update_tools draw_deps get_protoc protoc_abci protoc_libs gen_certs clean_certs grpc_dbserver test_cover test_apps test_persistence test_p2p test test_race test_integrations test_release test100 vagrant_test fmt rpc-docs build-linux localnet-start localnet-stop build-docker build-docker-localnode sentry-start sentry-config sentry-stop build-slate protoc_grpc protoc_all build_c install_c test_with_deadlock cleanup_after_test_with_deadlock lint