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.

331 lines
10 KiB

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