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.

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