2018-01-05 22:35:57 -08:00
GOTOOLS = \
2018-07-04 14:48:45 -04:00
github.com/mitchellh/gox \
2018-02-27 03:59:50 -08:00
github.com/golang/dep/cmd/dep \
2018-07-04 14:48:45 -04:00
gopkg.in/alecthomas/gometalinter.v2 \
github.com/gogo/protobuf/protoc-gen-gogo \
2018-07-04 17:11:34 -04:00
github.com/gogo/protobuf/gogoproto \
github.com/square/certstrap
2018-01-05 22:35:57 -08:00
PACKAGES = $( shell go list ./... | grep -v '/vendor/' )
2018-07-04 14:48:45 -04:00
INCLUDE = -I= . -I= ${ GOPATH } /src -I= ${ GOPATH } /src/github.com/gogo/protobuf/protobuf
2018-01-05 22:35:57 -08:00
BUILD_TAGS ?= tendermint
2018-01-08 16:41:23 -06:00
BUILD_FLAGS = -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`"
2017-12-04 17:35:42 -06:00
2018-03-08 18:55:14 +04:00
all : check build test install
2015-07-13 11:49:09 -07:00
2018-02-27 03:59:50 -08:00
check : check_tools ensure_deps
2017-12-23 02:23:05 -08:00
########################################
2018-07-04 14:48:45 -04:00
### Build Tendermint
2014-12-28 16:26:53 -08:00
2017-01-04 00:32:39 +04:00
build :
2018-04-01 13:54:48 -04:00
CGO_ENABLED = 0 go build $( BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/tendermint ./cmd/tendermint/
2015-04-21 19:51:23 -07:00
2017-01-04 00:32:39 +04:00
build_race :
2018-04-01 13:54:48 -04:00
CGO_ENABLED = 0 go build -race $( BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/tendermint ./cmd/tendermint
2018-01-08 16:41:23 -06:00
install :
2018-04-01 13:54:48 -04:00
CGO_ENABLED = 0 go install $( BUILD_FLAGS) -tags '$(BUILD_TAGS)' ./cmd/tendermint
2018-01-08 16:41:23 -06:00
2018-07-04 14:48:45 -04:00
########################################
### Build ABCI
2018-07-04 17:11:34 -04:00
protoc_abci :
2018-07-04 14:48:45 -04:00
## If you get the following error,
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
## See https://stackoverflow.com/a/25518702
protoc $( INCLUDE) --gogo_out= plugins = grpc:. abci/types/*.proto
@echo "--> adding nolint declarations to protobuf generated files"
2018-07-16 20:52:51 +01:00
@awk '/package types/ { print "//nolint: gas"; print; next }1' abci/types/types.pb.go > abci/types/types.pb.go.new
2018-07-04 14:48:45 -04:00
@mv abci/types/types.pb.go.new abci/types/types.pb.go
build_abci :
@go build -i ./abci/cmd/...
install_abci :
@go install ./abci/cmd/...
2018-01-08 16:41:23 -06:00
########################################
### Distribution
2014-12-28 17:10:03 -08:00
2017-01-23 13:45:14 +04:00
# dist builds binaries for all platforms and packages them for distribution
2018-07-04 14:48:45 -04:00
# TODO add abci to these scripts
2017-01-23 13:45:14 +04:00
dist :
@BUILD_TAGS= '$(BUILD_TAGS)' sh -c " ' $( CURDIR) /scripts/dist.sh' "
2017-12-23 02:23:05 -08:00
########################################
### Tools & dependencies
check_tools :
2018-01-05 22:35:57 -08:00
@# https://stackoverflow.com/a/25668869
2018-01-08 16:41:23 -06:00
@echo " Found tools: $( foreach tool,$( notdir $( GOTOOLS) ) ,\
2018-01-05 22:35:57 -08:00
$( if $( shell which $( tool) ) ,$( tool) ,$( error " No $( tool) in PATH " ) ) ) "
2017-12-23 02:23:05 -08:00
get_tools :
@echo "--> Installing tools"
go get -u -v $( GOTOOLS)
2018-03-06 15:32:52 +01:00
@gometalinter.v2 --install
2017-12-23 02:23:05 -08:00
update_tools :
@echo "--> Updating tools"
@go get -u $( GOTOOLS)
2018-02-27 03:59:50 -08:00
#Run this from CI
2017-12-23 02:23:05 -08:00
get_vendor_deps :
@rm -rf vendor/
2018-02-27 03:59:50 -08:00
@echo "--> Running dep"
@dep ensure -vendor-only
#Run this locally.
ensure_deps :
@rm -rf vendor/
@echo "--> Running dep"
2018-02-27 17:20:56 +04:00
@dep ensure
2017-12-23 02:23:05 -08:00
2018-07-04 17:11:34 -04:00
#For ABCI and libs
2018-07-04 14:48:45 -04:00
get_protoc :
@# https://github.com/google/protobuf/releases
curl -L https://github.com/google/protobuf/releases/download/v3.4.1/protobuf-cpp-3.4.1.tar.gz | tar xvz && \
cd protobuf-3.4.1 && \
DIST_LANG = cpp ./configure && \
make && \
make install && \
cd .. && \
rm -rf protobuf-3.4.1
2017-12-23 02:23:05 -08:00
draw_deps :
@# requires brew install graphviz or apt-get install graphviz
go get github.com/RobotsAndPencils/goviz
@goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
2018-02-28 08:23:31 +01:00
get_deps_bin_size :
@# Copy of build recipe with additional flags to perform binary size analysis
$( eval $( shell go build -work -a $( BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o build/tendermint ./cmd/tendermint/ 2>& 1) )
@find $( WORK) -type f -name "*.a" | xargs -I{ } du -hxs "{}" | sort -rh | sed -e s:${ WORK } /::g > deps_bin_size.log
@echo " Results can be found here: $( CURDIR) /deps_bin_size.log "
2017-12-23 02:23:05 -08:00
2018-07-04 17:11:34 -04:00
########################################
### Libs
protoc_libs :
## If you get the following error,
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
## See https://stackoverflow.com/a/25518702
2018-07-16 20:52:51 +01:00
protoc $( INCLUDE) --gogo_out= plugins = grpc:. libs/common/*.proto
2018-07-04 17:11:34 -04:00
@echo "--> adding nolint declarations to protobuf generated files"
2018-07-14 18:33:18 +01:00
@awk '/package common/ { print "//nolint: gas"; print; next }1' libs/common/types.pb.go > libs/common/types.pb.go.new
2018-07-04 17:11:34 -04:00
@mv libs/common/types.pb.go.new libs/common/types.pb.go
gen_certs : clean_certs
## Generating certificates for TLS testing...
certstrap init --common-name "tendermint.com" --passphrase ""
certstrap request-cert -ip "::" --passphrase ""
certstrap sign "::" --CA "tendermint.com" --passphrase ""
mv out/::.crt out/::.key db/remotedb
clean_certs :
## Cleaning TLS testing certificates...
rm -rf out
rm -f db/remotedb/::.crt db/remotedb/::.key
test_libs : gen_certs
GOCACHE = off go test -tags gcc $( shell go list ./... | grep -v vendor)
make clean_certs
grpc_dbserver :
protoc -I db/remotedb/proto/ db/remotedb/proto/defs.proto --go_out= plugins = grpc:db/remotedb/proto
2017-12-23 02:23:05 -08:00
########################################
### Testing
2018-03-08 22:52:38 +08:00
## required to be run first by most tests
build_docker_test_image :
docker build -t tester -f ./test/docker/Dockerfile .
### coverage, app, persistence, and libs tests
test_cover :
# run the go unit tests with coverage
bash test/test_cover.sh
2018-03-08 18:55:14 +04:00
2018-03-08 22:52:38 +08:00
test_apps :
# run the app tests using bash
# requires `abci-cli` and `tendermint` binaries installed
bash test/app/test.sh
2018-07-04 14:48:45 -04:00
test_abci_apps :
bash abci/tests/test_app/test.sh
test_abci_cli :
# test the cli against the examples in the tutorial at:
# ./docs/abci-cli.md
# if test fails, update the docs ^
@ bash abci/tests/test_cli/test.sh
2018-03-08 22:52:38 +08:00
test_persistence :
# run the persistence tests using bash
# requires `abci-cli` installed
docker run --name run_persistence -t tester bash test/persist/test_failure_indices.sh
# TODO undockerize
# bash test/persist/test_failure_indices.sh
test_p2p :
docker rm -f rsyslog || true
rm -rf test/logs || true
mkdir test/logs
cd test/
docker run -d -v "logs:/var/log/" -p 127.0.0.1:5514:514/udp --name rsyslog voxxit/rsyslog
cd ..
# requires 'tester' the image from above
bash test/p2p/test.sh tester
2017-01-04 00:32:39 +04:00
test_integrations :
2018-03-08 22:52:38 +08:00
make build_docker_test_image
make get_tools
make get_vendor_deps
make install
make test_cover
make test_apps
2018-07-04 14:54:53 -04:00
make test_abci_apps
2018-07-04 14:48:45 -04:00
make test_abci_cli
2018-07-04 17:11:34 -04:00
make test_libs
2018-03-08 22:52:38 +08:00
make test_persistence
make test_p2p
2017-12-04 17:37:32 -06:00
test_release :
2017-10-25 19:20:33 -07:00
@go test -tags release $( PACKAGES)
2017-01-30 12:02:24 +04:00
test100 :
2017-01-22 18:03:20 +04:00
@for i in { 1..100} ; do make test; done
2016-04-29 15:32:50 -07:00
2017-12-08 18:36:58 +01:00
vagrant_test :
vagrant up
vagrant ssh -c 'make test_integrations'
2018-03-08 22:52:38 +08:00
### go tests
test :
@echo "--> Running go test"
@go test $( PACKAGES)
test_race :
@echo "--> Running go test --race"
@go test -v -race $( PACKAGES)
2017-02-08 19:28:25 +01:00
2017-12-23 02:23:05 -08:00
########################################
2017-05-30 13:27:31 -04:00
### Formatting, linting, and vetting
2017-12-23 02:23:05 -08:00
fmt :
@go fmt ./...
2017-02-08 19:28:25 +01:00
2017-12-23 02:23:05 -08:00
metalinter :
@echo "--> Running linter"
2018-03-06 15:32:52 +01:00
@gometalinter.v2 --vendor --deadline= 600s --disable-all \
2017-09-21 14:13:13 -04:00
--enable= deadcode \
2017-12-10 17:44:22 +00:00
--enable= gosimple \
2017-09-21 14:13:13 -04:00
--enable= misspell \
--enable= safesql \
./...
2017-12-10 17:44:22 +00:00
#--enable=gas \
2017-10-26 19:24:18 -04:00
#--enable=maligned \
2017-09-21 14:13:13 -04:00
#--enable=dupl \
2017-10-14 14:38:47 -04:00
#--enable=errcheck \
2017-09-21 14:13:13 -04:00
#--enable=goconst \
#--enable=gocyclo \
2017-10-03 18:49:20 -04:00
#--enable=goimports \
2017-09-21 14:13:13 -04:00
#--enable=golint \ <== comments on anything exported
2017-10-03 19:11:55 -04:00
#--enable=gotype \
2017-10-28 11:07:59 -04:00
#--enable=ineffassign \
2017-09-21 14:13:13 -04:00
#--enable=interfacer \
#--enable=megacheck \
#--enable=staticcheck \
2017-11-09 13:59:35 -05:00
#--enable=structcheck \
2017-09-21 14:13:13 -04:00
#--enable=unconvert \
#--enable=unparam \
#--enable=unused \
2017-11-09 13:59:35 -05:00
#--enable=varcheck \
2017-09-21 14:13:13 -04:00
#--enable=vet \
#--enable=vetshadow \
2017-09-21 13:54:34 -04:00
2017-12-23 02:23:05 -08:00
metalinter_all :
@echo "--> Running linter (all)"
gometalinter.v2 --vendor --deadline= 600s --enable-all --disable= lll ./...
2018-04-16 11:34:01 -04:00
###########################################################
### Docker image
build-docker :
cp build/tendermint DOCKER/tendermint
docker build --label= tendermint --tag= "tendermint/tendermint" DOCKER
rm -rf DOCKER/tendermint
2018-04-12 13:15:16 +02:00
###########################################################
### Local testnet using docker
# Build linux binary on other platforms
build-linux :
GOOS = linux GOARCH = amd64 $( MAKE) build
2018-05-19 23:21:19 -04:00
build-docker-localnode :
cd networks/local
make
2018-04-12 13:15:16 +02:00
# Run a 4-node testnet locally
2018-05-10 14:02:31 +04:00
localnet-start : localnet -stop
2018-04-13 21:03:25 -04:00
@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
2018-04-12 13:15:16 +02:00
docker-compose up
# Stop testnet
2018-04-17 12:28:05 -04:00
localnet-stop :
2018-04-12 13:15:16 +02:00
docker-compose down
2018-04-13 21:03:25 -04:00
###########################################################
### Remote full-nodes (sentry) using terraform and ansible
# Server management
2018-04-24 14:22:19 -04:00
sentry-start :
2018-04-16 11:34:01 -04:00
@if [ -z " $( DO_API_TOKEN) " ] ; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
2018-04-13 21:03:25 -04:00
@if ! [ -f $( HOME) /.ssh/id_rsa.pub ] ; then ssh-keygen ; fi
cd networks/remote/terraform && terraform init && terraform apply -var DO_API_TOKEN = " $( DO_API_TOKEN) " -var SSH_KEY_FILE = " $( HOME) /.ssh/id_rsa.pub "
2018-04-16 11:34:01 -04:00
@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
2018-04-24 14:22:19 -04:00
cd networks/remote/ansible && ANSIBLE_HOST_KEY_CHECKING = False ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
2018-05-18 13:22:04 -04:00
@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.)"
2018-04-13 21:03:25 -04:00
# Configuration management
2018-04-24 14:22:19 -04:00
sentry-config :
cd networks/remote/ansible && ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY = $( CURDIR) /build/tendermint -e CONFIGDIR = $( CURDIR) /build
2018-04-16 11:34:01 -04:00
2018-04-24 14:22:19 -04:00
sentry-stop :
2018-04-16 11:34:01 -04:00
@if [ -z " $( DO_API_TOKEN) " ] ; then echo "DO_API_TOKEN environment variable not set." ; false ; fi
cd networks/remote/terraform && terraform destroy -var DO_API_TOKEN = " $( DO_API_TOKEN) " -var SSH_KEY_FILE = " $( HOME) /.ssh/id_rsa.pub "
2018-04-13 21:03:25 -04:00
2018-05-25 07:59:24 -04:00
# meant for the CI, inspect script & adapt accordingly
build-slate :
bash scripts/slate.sh
2017-12-23 02:23:05 -08:00
# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
2018-07-04 17:11:34 -04:00
.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_p 2p test test_race test_integrations test_release test 100 vagrant_test fmt build -linux localnet -start localnet -stop build -docker build -docker -localnode sentry -start sentry -config sentry -stop build -slate