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.

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