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.

326 lines
10 KiB

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