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.

277 lines
8.6 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/gogo/protobuf/gogoproto
  7. PACKAGES=$(shell go list ./... | grep -v '/vendor/')
  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. all: check build test install
  12. check: check_tools ensure_deps
  13. ########################################
  14. ### Build Tendermint
  15. build:
  16. CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/tendermint ./cmd/tendermint/
  17. build_race:
  18. CGO_ENABLED=0 go build -race $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/tendermint ./cmd/tendermint
  19. install:
  20. CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' ./cmd/tendermint
  21. ########################################
  22. ### Build ABCI
  23. protoc:
  24. ## If you get the following error,
  25. ## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
  26. ## See https://stackoverflow.com/a/25518702
  27. protoc $(INCLUDE) --gogo_out=plugins=grpc:. abci/types/*.proto
  28. @echo "--> adding nolint declarations to protobuf generated files"
  29. @awk '/package abci/types/ { print "//nolint: gas"; print; next }1' abci/types/types.pb.go > abci/types/types.pb.go.new
  30. @mv abci/types/types.pb.go.new abci/types/types.pb.go
  31. build_abci:
  32. @go build -i ./abci/cmd/...
  33. install_abci:
  34. @go install ./abci/cmd/...
  35. ########################################
  36. ### Distribution
  37. # dist builds binaries for all platforms and packages them for distribution
  38. # TODO add abci to these scripts
  39. dist:
  40. @BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/dist.sh'"
  41. ########################################
  42. ### Tools & dependencies
  43. check_tools:
  44. @# https://stackoverflow.com/a/25668869
  45. @echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
  46. $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
  47. get_tools:
  48. @echo "--> Installing tools"
  49. go get -u -v $(GOTOOLS)
  50. @gometalinter.v2 --install
  51. update_tools:
  52. @echo "--> Updating tools"
  53. @go get -u $(GOTOOLS)
  54. #Run this from CI
  55. get_vendor_deps:
  56. @rm -rf vendor/
  57. @echo "--> Running dep"
  58. @dep ensure -vendor-only
  59. #Run this locally.
  60. ensure_deps:
  61. @rm -rf vendor/
  62. @echo "--> Running dep"
  63. @dep ensure
  64. #For ABCI
  65. get_protoc:
  66. @# https://github.com/google/protobuf/releases
  67. curl -L https://github.com/google/protobuf/releases/download/v3.4.1/protobuf-cpp-3.4.1.tar.gz | tar xvz && \
  68. cd protobuf-3.4.1 && \
  69. DIST_LANG=cpp ./configure && \
  70. make && \
  71. make install && \
  72. cd .. && \
  73. rm -rf protobuf-3.4.1
  74. draw_deps:
  75. @# requires brew install graphviz or apt-get install graphviz
  76. go get github.com/RobotsAndPencils/goviz
  77. @goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
  78. get_deps_bin_size:
  79. @# Copy of build recipe with additional flags to perform binary size analysis
  80. $(eval $(shell go build -work -a $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/tendermint ./cmd/tendermint/ 2>&1))
  81. @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
  82. @echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
  83. ########################################
  84. ### Testing
  85. ## required to be run first by most tests
  86. build_docker_test_image:
  87. docker build -t tester -f ./test/docker/Dockerfile .
  88. ### coverage, app, persistence, and libs tests
  89. test_cover:
  90. # run the go unit tests with coverage
  91. bash test/test_cover.sh
  92. test_apps:
  93. # run the app tests using bash
  94. # requires `abci-cli` and `tendermint` binaries installed
  95. bash test/app/test.sh
  96. test_abci_apps:
  97. bash abci/tests/test_app/test.sh
  98. test_abci_cli:
  99. # test the cli against the examples in the tutorial at:
  100. # ./docs/abci-cli.md
  101. # if test fails, update the docs ^
  102. @ bash abci/tests/test_cli/test.sh
  103. test_persistence:
  104. # run the persistence tests using bash
  105. # requires `abci-cli` installed
  106. docker run --name run_persistence -t tester bash test/persist/test_failure_indices.sh
  107. # TODO undockerize
  108. # bash test/persist/test_failure_indices.sh
  109. test_p2p:
  110. docker rm -f rsyslog || true
  111. rm -rf test/logs || true
  112. mkdir test/logs
  113. cd test/
  114. docker run -d -v "logs:/var/log/" -p 127.0.0.1:5514:514/udp --name rsyslog voxxit/rsyslog
  115. cd ..
  116. # requires 'tester' the image from above
  117. bash test/p2p/test.sh tester
  118. test_integrations:
  119. make build_docker_test_image
  120. make get_tools
  121. make get_vendor_deps
  122. make install
  123. make test_cover
  124. make test_apps
  125. make test_abci_apps
  126. make test_abci_cli
  127. make test_persistence
  128. make test_p2p
  129. test_release:
  130. @go test -tags release $(PACKAGES)
  131. test100:
  132. @for i in {1..100}; do make test; done
  133. vagrant_test:
  134. vagrant up
  135. vagrant ssh -c 'make test_integrations'
  136. ### go tests
  137. test:
  138. @echo "--> Running go test"
  139. @go test $(PACKAGES)
  140. test_race:
  141. @echo "--> Running go test --race"
  142. @go test -v -race $(PACKAGES)
  143. ########################################
  144. ### Formatting, linting, and vetting
  145. fmt:
  146. @go fmt ./...
  147. metalinter:
  148. @echo "--> Running linter"
  149. @gometalinter.v2 --vendor --deadline=600s --disable-all \
  150. --enable=deadcode \
  151. --enable=gosimple \
  152. --enable=misspell \
  153. --enable=safesql \
  154. ./...
  155. #--enable=gas \
  156. #--enable=maligned \
  157. #--enable=dupl \
  158. #--enable=errcheck \
  159. #--enable=goconst \
  160. #--enable=gocyclo \
  161. #--enable=goimports \
  162. #--enable=golint \ <== comments on anything exported
  163. #--enable=gotype \
  164. #--enable=ineffassign \
  165. #--enable=interfacer \
  166. #--enable=megacheck \
  167. #--enable=staticcheck \
  168. #--enable=structcheck \
  169. #--enable=unconvert \
  170. #--enable=unparam \
  171. #--enable=unused \
  172. #--enable=varcheck \
  173. #--enable=vet \
  174. #--enable=vetshadow \
  175. metalinter_all:
  176. @echo "--> Running linter (all)"
  177. gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
  178. ###########################################################
  179. ### Docker image
  180. build-docker:
  181. cp build/tendermint DOCKER/tendermint
  182. docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
  183. rm -rf DOCKER/tendermint
  184. ###########################################################
  185. ### Local testnet using docker
  186. # Build linux binary on other platforms
  187. build-linux:
  188. GOOS=linux GOARCH=amd64 $(MAKE) build
  189. build-docker-localnode:
  190. cd networks/local
  191. make
  192. # Run a 4-node testnet locally
  193. localnet-start: localnet-stop
  194. @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
  195. docker-compose up
  196. # Stop testnet
  197. localnet-stop:
  198. docker-compose down
  199. ###########################################################
  200. ### Remote full-nodes (sentry) using terraform and ansible
  201. # Server management
  202. sentry-start:
  203. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  204. @if ! [ -f $(HOME)/.ssh/id_rsa.pub ]; then ssh-keygen ; fi
  205. cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  206. @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
  207. cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  208. @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.)"
  209. # Configuration management
  210. sentry-config:
  211. cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$(CURDIR)/build/tendermint -e CONFIGDIR=$(CURDIR)/build
  212. sentry-stop:
  213. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  214. cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  215. # meant for the CI, inspect script & adapt accordingly
  216. build-slate:
  217. bash scripts/slate.sh
  218. # To avoid unintended conflicts with file names, always add to .PHONY
  219. # unless there is a reason not to.
  220. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
  221. .PHONY: check build build_race dist install check_tools get_tools update_tools get_vendor_deps draw_deps 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