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.

321 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_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. ########################################
  106. ### Testing
  107. ## required to be run first by most tests
  108. build_docker_test_image:
  109. docker build -t tester -f ./test/docker/Dockerfile .
  110. ### coverage, app, persistence, and libs tests
  111. test_cover:
  112. # run the go unit tests with coverage
  113. bash test/test_cover.sh
  114. test_apps:
  115. # run the app tests using bash
  116. # requires `abci-cli` and `tendermint` binaries installed
  117. bash test/app/test.sh
  118. test_abci_apps:
  119. bash abci/tests/test_app/test.sh
  120. test_abci_cli:
  121. # test the cli against the examples in the tutorial at:
  122. # ./docs/abci-cli.md
  123. # if test fails, update the docs ^
  124. @ bash abci/tests/test_cli/test.sh
  125. test_persistence:
  126. # run the persistence tests using bash
  127. # requires `abci-cli` installed
  128. docker run --name run_persistence -t tester bash test/persist/test_failure_indices.sh
  129. # TODO undockerize
  130. # bash test/persist/test_failure_indices.sh
  131. test_p2p:
  132. docker rm -f rsyslog || true
  133. rm -rf test/logs || true
  134. mkdir test/logs
  135. cd test/
  136. docker run -d -v "logs:/var/log/" -p 127.0.0.1:5514:514/udp --name rsyslog voxxit/rsyslog
  137. cd ..
  138. # requires 'tester' the image from above
  139. bash test/p2p/test.sh tester
  140. test_integrations:
  141. make build_docker_test_image
  142. make get_tools
  143. make get_vendor_deps
  144. make install
  145. make test_cover
  146. make test_apps
  147. make test_abci_apps
  148. make test_abci_cli
  149. make test_libs
  150. make test_persistence
  151. make test_p2p
  152. test_release:
  153. @go test -tags release $(PACKAGES)
  154. test100:
  155. @for i in {1..100}; do make test; done
  156. vagrant_test:
  157. vagrant up
  158. vagrant ssh -c 'make test_integrations'
  159. ### go tests
  160. test:
  161. @echo "--> Running go test"
  162. @GOCACHE=off go test -p 1 $(PACKAGES)
  163. test_race:
  164. @echo "--> Running go test --race"
  165. @GOCACHE=off go test -p 1 -v -race $(PACKAGES)
  166. ########################################
  167. ### Formatting, linting, and vetting
  168. fmt:
  169. @go fmt ./...
  170. metalinter:
  171. @echo "--> Running linter"
  172. @gometalinter.v2 $(LINT_FLAGS) --disable-all \
  173. --enable=deadcode \
  174. --enable=gosimple \
  175. --enable=misspell \
  176. --enable=safesql \
  177. ./...
  178. #--enable=gas \
  179. #--enable=maligned \
  180. #--enable=dupl \
  181. #--enable=errcheck \
  182. #--enable=goconst \
  183. #--enable=gocyclo \
  184. #--enable=goimports \
  185. #--enable=golint \ <== comments on anything exported
  186. #--enable=gotype \
  187. #--enable=ineffassign \
  188. #--enable=interfacer \
  189. #--enable=megacheck \
  190. #--enable=staticcheck \
  191. #--enable=structcheck \
  192. #--enable=unconvert \
  193. #--enable=unparam \
  194. #--enable=unused \
  195. #--enable=varcheck \
  196. #--enable=vet \
  197. #--enable=vetshadow \
  198. metalinter_all:
  199. @echo "--> Running linter (all)"
  200. gometalinter.v2 $(LINT_FLAGS) --enable-all --disable=lll ./...
  201. DESTINATION = ./index.html.md
  202. rpc-docs:
  203. cat rpc/core/slate_header.txt > $(DESTINATION)
  204. 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)
  205. check_dep:
  206. dep status >> /dev/null
  207. !(grep -n branch Gopkg.toml)
  208. ###########################################################
  209. ### Docker image
  210. build-docker:
  211. cp build/tendermint DOCKER/tendermint
  212. docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
  213. rm -rf DOCKER/tendermint
  214. ###########################################################
  215. ### Local testnet using docker
  216. # Build linux binary on other platforms
  217. build-linux:
  218. GOOS=linux GOARCH=amd64 $(MAKE) build
  219. build-docker-localnode:
  220. cd networks/local
  221. make
  222. # Run a 4-node testnet locally
  223. localnet-start: localnet-stop
  224. @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
  225. docker-compose up
  226. # Stop testnet
  227. localnet-stop:
  228. docker-compose down
  229. ###########################################################
  230. ### Remote full-nodes (sentry) using terraform and ansible
  231. # Server management
  232. sentry-start:
  233. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  234. @if ! [ -f $(HOME)/.ssh/id_rsa.pub ]; then ssh-keygen ; fi
  235. cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  236. @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
  237. cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  238. @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.)"
  239. # Configuration management
  240. sentry-config:
  241. cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$(CURDIR)/build/tendermint -e CONFIGDIR=$(CURDIR)/build
  242. sentry-stop:
  243. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  244. cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  245. # meant for the CI, inspect script & adapt accordingly
  246. build-slate:
  247. bash scripts/slate.sh
  248. # To avoid unintended conflicts with file names, always add to .PHONY
  249. # unless there is a reason not to.
  250. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
  251. .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