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.

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