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.

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