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.

310 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/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. ### Build ABCI
  24. protoc_abci:
  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=plugins=grpc:. abci/types/*.proto
  29. @echo "--> adding nolint declarations to protobuf generated files"
  30. @awk '/package abci/types/ { print "//nolint: gas"; print; next }1' abci/types/types.pb.go > abci/types/types.pb.go.new
  31. @mv abci/types/types.pb.go.new abci/types/types.pb.go
  32. build_abci:
  33. @go build -i ./abci/cmd/...
  34. install_abci:
  35. @go install ./abci/cmd/...
  36. ########################################
  37. ### Distribution
  38. # dist builds binaries for all platforms and packages them for distribution
  39. # TODO add abci to these scripts
  40. dist:
  41. @BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/dist.sh'"
  42. ########################################
  43. ### Tools & dependencies
  44. check_tools:
  45. @# https://stackoverflow.com/a/25668869
  46. @echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
  47. $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
  48. get_tools:
  49. @echo "--> Installing tools"
  50. go get -u -v $(GOTOOLS)
  51. @gometalinter.v2 --install
  52. update_tools:
  53. @echo "--> Updating tools"
  54. @go get -u $(GOTOOLS)
  55. #Run this from CI
  56. get_vendor_deps:
  57. @rm -rf vendor/
  58. @echo "--> Running dep"
  59. @dep ensure -vendor-only
  60. #Run this locally.
  61. ensure_deps:
  62. @rm -rf vendor/
  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.4.1/protobuf-cpp-3.4.1.tar.gz | tar xvz && \
  69. cd protobuf-3.4.1 && \
  70. DIST_LANG=cpp ./configure && \
  71. make && \
  72. make install && \
  73. cd .. && \
  74. rm -rf protobuf-3.4.1
  75. draw_deps:
  76. @# requires brew install graphviz or apt-get install graphviz
  77. go get github.com/RobotsAndPencils/goviz
  78. @goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
  79. get_deps_bin_size:
  80. @# Copy of build recipe with additional flags to perform binary size analysis
  81. $(eval $(shell go build -work -a $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/tendermint ./cmd/tendermint/ 2>&1))
  82. @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
  83. @echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
  84. ########################################
  85. ### Libs
  86. protoc_libs:
  87. ## If you get the following error,
  88. ## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
  89. ## See https://stackoverflow.com/a/25518702
  90. protoc $(INCLUDE) --go_out=plugins=grpc:. libs/common/*.proto
  91. @echo "--> adding nolint declarations to protobuf generated files"
  92. @awk '/package common/ { print "//nolint: gas"; print; next }1' libs/common/types.pb.go > libs/common/types.pb.go.new
  93. @mv libs/common/types.pb.go.new libs/common/types.pb.go
  94. gen_certs: clean_certs
  95. ## Generating certificates for TLS testing...
  96. certstrap init --common-name "tendermint.com" --passphrase ""
  97. certstrap request-cert -ip "::" --passphrase ""
  98. certstrap sign "::" --CA "tendermint.com" --passphrase ""
  99. mv out/::.crt out/::.key db/remotedb
  100. clean_certs:
  101. ## Cleaning TLS testing certificates...
  102. rm -rf out
  103. rm -f db/remotedb/::.crt db/remotedb/::.key
  104. test_libs: gen_certs
  105. GOCACHE=off go test -tags gcc $(PACKAGES)
  106. make clean_certs
  107. grpc_dbserver:
  108. protoc -I db/remotedb/proto/ db/remotedb/proto/defs.proto --go_out=plugins=grpc:db/remotedb/proto
  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. test_integrations:
  145. make build_docker_test_image
  146. make get_tools
  147. make get_vendor_deps
  148. make install
  149. make test_cover
  150. make test_apps
  151. make test_abci_apps
  152. make test_abci_cli
  153. make test_libs
  154. make test_persistence
  155. make test_p2p
  156. test_release:
  157. @go test -tags release $(PACKAGES)
  158. test100:
  159. @for i in {1..100}; do make test; done
  160. vagrant_test:
  161. vagrant up
  162. vagrant ssh -c 'make test_integrations'
  163. ### go tests
  164. test:
  165. @echo "--> Running go test"
  166. @go test $(PACKAGES)
  167. test_race:
  168. @echo "--> Running go test --race"
  169. @go test -v -race $(PACKAGES)
  170. ########################################
  171. ### Formatting, linting, and vetting
  172. fmt:
  173. @go fmt ./...
  174. metalinter:
  175. @echo "--> Running linter"
  176. @gometalinter.v2 --vendor --deadline=600s --disable-all \
  177. --enable=deadcode \
  178. --enable=gosimple \
  179. --enable=misspell \
  180. --enable=safesql \
  181. ./...
  182. #--enable=gas \
  183. #--enable=maligned \
  184. #--enable=dupl \
  185. #--enable=errcheck \
  186. #--enable=goconst \
  187. #--enable=gocyclo \
  188. #--enable=goimports \
  189. #--enable=golint \ <== comments on anything exported
  190. #--enable=gotype \
  191. #--enable=ineffassign \
  192. #--enable=interfacer \
  193. #--enable=megacheck \
  194. #--enable=staticcheck \
  195. #--enable=structcheck \
  196. #--enable=unconvert \
  197. #--enable=unparam \
  198. #--enable=unused \
  199. #--enable=varcheck \
  200. #--enable=vet \
  201. #--enable=vetshadow \
  202. metalinter_all:
  203. @echo "--> Running linter (all)"
  204. gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
  205. ###########################################################
  206. ### Docker image
  207. build-docker:
  208. cp build/tendermint DOCKER/tendermint
  209. docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
  210. rm -rf DOCKER/tendermint
  211. ###########################################################
  212. ### Local testnet using docker
  213. # Build linux binary on other platforms
  214. build-linux:
  215. GOOS=linux GOARCH=amd64 $(MAKE) build
  216. build-docker-localnode:
  217. cd networks/local
  218. make
  219. # Run a 4-node testnet locally
  220. localnet-start: localnet-stop
  221. @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
  222. docker-compose up
  223. # Stop testnet
  224. localnet-stop:
  225. docker-compose down
  226. ###########################################################
  227. ### Remote full-nodes (sentry) using terraform and ansible
  228. # Server management
  229. sentry-start:
  230. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  231. @if ! [ -f $(HOME)/.ssh/id_rsa.pub ]; then ssh-keygen ; fi
  232. cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  233. @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
  234. cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  235. @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.)"
  236. # Configuration management
  237. sentry-config:
  238. cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$(CURDIR)/build/tendermint -e CONFIGDIR=$(CURDIR)/build
  239. sentry-stop:
  240. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  241. cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  242. # meant for the CI, inspect script & adapt accordingly
  243. build-slate:
  244. bash scripts/slate.sh
  245. # To avoid unintended conflicts with file names, always add to .PHONY
  246. # unless there is a reason not to.
  247. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
  248. .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