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.

229 lines
7.0 KiB

7 years ago
9 years ago
7 years ago
7 years ago
7 years ago
  1. GOTOOLS = \
  2. github.com/golang/dep/cmd/dep \
  3. gopkg.in/alecthomas/gometalinter.v2
  4. PACKAGES=$(shell go list ./... | grep -v '/vendor/')
  5. BUILD_TAGS?=tendermint
  6. BUILD_FLAGS = -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`"
  7. all: check build test install
  8. check: check_tools ensure_deps
  9. ########################################
  10. ### Build
  11. build:
  12. CGO_ENABLED=0 go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/tendermint ./cmd/tendermint/
  13. build_race:
  14. CGO_ENABLED=0 go build -race $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/tendermint ./cmd/tendermint
  15. install:
  16. CGO_ENABLED=0 go install $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' ./cmd/tendermint
  17. ########################################
  18. ### Distribution
  19. # dist builds binaries for all platforms and packages them for distribution
  20. dist:
  21. @BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/dist.sh'"
  22. ########################################
  23. ### Tools & dependencies
  24. check_tools:
  25. @# https://stackoverflow.com/a/25668869
  26. @echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),\
  27. $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
  28. get_tools:
  29. @echo "--> Installing tools"
  30. go get -u -v $(GOTOOLS)
  31. @gometalinter.v2 --install
  32. update_tools:
  33. @echo "--> Updating tools"
  34. @go get -u $(GOTOOLS)
  35. #Run this from CI
  36. get_vendor_deps:
  37. @rm -rf vendor/
  38. @echo "--> Running dep"
  39. @dep ensure -vendor-only
  40. #Run this locally.
  41. ensure_deps:
  42. @rm -rf vendor/
  43. @echo "--> Running dep"
  44. @dep ensure
  45. draw_deps:
  46. @# requires brew install graphviz or apt-get install graphviz
  47. go get github.com/RobotsAndPencils/goviz
  48. @goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
  49. get_deps_bin_size:
  50. @# Copy of build recipe with additional flags to perform binary size analysis
  51. $(eval $(shell go build -work -a $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/tendermint ./cmd/tendermint/ 2>&1))
  52. @find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
  53. @echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
  54. ########################################
  55. ### Testing
  56. ## required to be run first by most tests
  57. build_docker_test_image:
  58. docker build -t tester -f ./test/docker/Dockerfile .
  59. ### coverage, app, persistence, and libs tests
  60. test_cover:
  61. # run the go unit tests with coverage
  62. bash test/test_cover.sh
  63. test_apps:
  64. # run the app tests using bash
  65. # requires `abci-cli` and `tendermint` binaries installed
  66. bash test/app/test.sh
  67. test_persistence:
  68. # run the persistence tests using bash
  69. # requires `abci-cli` installed
  70. docker run --name run_persistence -t tester bash test/persist/test_failure_indices.sh
  71. # TODO undockerize
  72. # bash test/persist/test_failure_indices.sh
  73. test_p2p:
  74. docker rm -f rsyslog || true
  75. rm -rf test/logs || true
  76. mkdir test/logs
  77. cd test/
  78. docker run -d -v "logs:/var/log/" -p 127.0.0.1:5514:514/udp --name rsyslog voxxit/rsyslog
  79. cd ..
  80. # requires 'tester' the image from above
  81. bash test/p2p/test.sh tester
  82. need_abci:
  83. bash scripts/install_abci_apps.sh
  84. test_integrations:
  85. make build_docker_test_image
  86. make get_tools
  87. make get_vendor_deps
  88. make install
  89. make need_abci
  90. make test_cover
  91. make test_apps
  92. make test_persistence
  93. make test_p2p
  94. test_release:
  95. @go test -tags release $(PACKAGES)
  96. test100:
  97. @for i in {1..100}; do make test; done
  98. vagrant_test:
  99. vagrant up
  100. vagrant ssh -c 'make test_integrations'
  101. ### go tests
  102. test:
  103. @echo "--> Running go test"
  104. @go test $(PACKAGES)
  105. test_race:
  106. @echo "--> Running go test --race"
  107. @go test -v -race $(PACKAGES)
  108. ########################################
  109. ### Formatting, linting, and vetting
  110. fmt:
  111. @go fmt ./...
  112. metalinter:
  113. @echo "--> Running linter"
  114. @gometalinter.v2 --vendor --deadline=600s --disable-all \
  115. --enable=deadcode \
  116. --enable=gosimple \
  117. --enable=misspell \
  118. --enable=safesql \
  119. ./...
  120. #--enable=gas \
  121. #--enable=maligned \
  122. #--enable=dupl \
  123. #--enable=errcheck \
  124. #--enable=goconst \
  125. #--enable=gocyclo \
  126. #--enable=goimports \
  127. #--enable=golint \ <== comments on anything exported
  128. #--enable=gotype \
  129. #--enable=ineffassign \
  130. #--enable=interfacer \
  131. #--enable=megacheck \
  132. #--enable=staticcheck \
  133. #--enable=structcheck \
  134. #--enable=unconvert \
  135. #--enable=unparam \
  136. #--enable=unused \
  137. #--enable=varcheck \
  138. #--enable=vet \
  139. #--enable=vetshadow \
  140. metalinter_all:
  141. @echo "--> Running linter (all)"
  142. gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
  143. ###########################################################
  144. ### Docker image
  145. build-docker:
  146. cp build/tendermint DOCKER/tendermint
  147. docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
  148. rm -rf DOCKER/tendermint
  149. ###########################################################
  150. ### Local testnet using docker
  151. # Build linux binary on other platforms
  152. build-linux:
  153. GOOS=linux GOARCH=amd64 $(MAKE) build
  154. # Run a 4-node testnet locally
  155. localnet-start:
  156. @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
  157. docker-compose up
  158. # Stop testnet
  159. localnet-stop:
  160. docker-compose down
  161. ###########################################################
  162. ### Remote full-nodes (sentry) using terraform and ansible
  163. # Server management
  164. server-setup:
  165. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  166. @if ! [ -f $(HOME)/.ssh/id_rsa.pub ]; then ssh-keygen ; fi
  167. cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  168. @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
  169. cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/digital_ocean.py -l remotenet install.yml
  170. @echo "Next step: Add your validator setup in the genesis.json and config.tml files and run \"make server-config\". (Public key of validator, chain ID, peer IP and node ID.)"
  171. # Configuration management
  172. server-config:
  173. cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l remotenet config.yml -e BINARY=$(CURDIR)/build/tendermint -e CONFIGDIR=$(CURDIR)/build
  174. server-destroy:
  175. @if [ -z "$(DO_API_TOKEN)" ]; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
  176. cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN="$(DO_API_TOKEN)" -var SSH_KEY_FILE="$(HOME)/.ssh/id_rsa.pub"
  177. # To avoid unintended conflicts with file names, always add to .PHONY
  178. # unless there is a reason not to.
  179. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
  180. .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 server-setup server-config server-destroy