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.

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