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.

276 lines
8.5 KiB

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_cli
  126. make test_persistence
  127. make test_p2p
  128. test_release:
  129. @go test -tags release $(PACKAGES)
  130. test100:
  131. @for i in {1..100}; do make test; done
  132. vagrant_test:
  133. vagrant up
  134. vagrant ssh -c 'make test_integrations'
  135. ### go tests
  136. test:
  137. @echo "--> Running go test"
  138. @go test $(PACKAGES)
  139. test_race:
  140. @echo "--> Running go test --race"
  141. @go test -v -race $(PACKAGES)
  142. ########################################
  143. ### Formatting, linting, and vetting
  144. fmt:
  145. @go fmt ./...
  146. metalinter:
  147. @echo "--> Running linter"
  148. @gometalinter.v2 --vendor --deadline=600s --disable-all \
  149. --enable=deadcode \
  150. --enable=gosimple \
  151. --enable=misspell \
  152. --enable=safesql \
  153. ./...
  154. #--enable=gas \
  155. #--enable=maligned \
  156. #--enable=dupl \
  157. #--enable=errcheck \
  158. #--enable=goconst \
  159. #--enable=gocyclo \
  160. #--enable=goimports \
  161. #--enable=golint \ <== comments on anything exported
  162. #--enable=gotype \
  163. #--enable=ineffassign \
  164. #--enable=interfacer \
  165. #--enable=megacheck \
  166. #--enable=staticcheck \
  167. #--enable=structcheck \
  168. #--enable=unconvert \
  169. #--enable=unparam \
  170. #--enable=unused \
  171. #--enable=varcheck \
  172. #--enable=vet \
  173. #--enable=vetshadow \
  174. metalinter_all:
  175. @echo "--> Running linter (all)"
  176. gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
  177. ###########################################################
  178. ### Docker image
  179. build-docker:
  180. cp build/tendermint DOCKER/tendermint
  181. docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
  182. rm -rf DOCKER/tendermint
  183. ###########################################################
  184. ### Local testnet using docker
  185. # Build linux binary on other platforms
  186. build-linux:
  187. GOOS=linux GOARCH=amd64 $(MAKE) build
  188. build-docker-localnode:
  189. cd networks/local
  190. make
  191. # Run a 4-node testnet locally
  192. localnet-start: localnet-stop
  193. @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
  194. docker-compose up
  195. # Stop testnet
  196. localnet-stop:
  197. docker-compose down
  198. ###########################################################
  199. ### Remote full-nodes (sentry) using terraform and ansible
  200. # Server management
  201. sentry-start:
  202. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  203. @if ! [ -f $(HOME)/.ssh/id_rsa.pub ]; then ssh-keygen ; fi
  204. cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  205. @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
  206. cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  207. @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.)"
  208. # Configuration management
  209. sentry-config:
  210. cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$(CURDIR)/build/tendermint -e CONFIGDIR=$(CURDIR)/build
  211. sentry-stop:
  212. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  213. cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  214. # meant for the CI, inspect script & adapt accordingly
  215. build-slate:
  216. bash scripts/slate.sh
  217. # To avoid unintended conflicts with file names, always add to .PHONY
  218. # unless there is a reason not to.
  219. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
  220. .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