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.

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