arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/Makefile
MakefileRaw
  1#! /usr/bin/make -f
  2
  3# Project variables.
  4PACKAGE := github.com/hermeznetwork/hermez-node
  5VERSION := $(shell git describe --tags --always)
  6COMMIT := $(shell git rev-parse --short HEAD)
  7DATE := $(shell date +%Y-%m-%dT%H:%M:%S%z)
  8PROJECT_NAME := $(shell basename "$(PWD)")
  9
 10# Go related variables.
 11GO_FILES ?= $$(find . -name '*.go' | grep -v vendor)
 12GOBASE := $(shell pwd)
 13GOBIN := $(GOBASE)/bin
 14GOPKG := $(.)
 15GOENVVARS := GOBIN=$(GOBIN)
 16GOCMD := $(GOBASE)/cli/node
 17GOPROOF := $(GOBASE)/test/proofserver/cli
 18GOBINARY := node
 19
 20# Project configs.
 21MODE ?= sync
 22CONFIG ?= $(GOBASE)/cli/node/cfg.buidler.toml
 23POSTGRES_PASS ?= yourpasswordhere
 24
 25# Use linker flags to provide version/build settings.
 26LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
 27
 28# PID file will keep the process id of the server.
 29PID_PROOF_MOCK := /tmp/.$(PROJECT_NAME).proof.pid
 30
 31# Make is verbose in Linux. Make it silent.
 32MAKEFLAGS += --silent
 33
 34.PHONY: help
 35help: Makefile
 36	@echo
 37	@echo " Choose a command run in "$(PROJECT_NAME)":"
 38	@echo
 39	@sed -n 's/^##//p' $< | column -t -s ':' |  sed -e 's/^/ /'
 40	@echo
 41
 42## test: Run the application check and all tests.
 43test: govet gocilint test-unit
 44
 45## test-unit: Run all unit tests.
 46test-unit:
 47	@echo "  >  Running unit tests"
 48	$(GOENVVARS) go test -race -p 1 -failfast -timeout 300s -v ./...
 49
 50## test-api-server: Run the API server using the Go tests.
 51test-api-server:
 52	@echo "  >  Running unit tests"
 53	$(GOENVVARS) FAKE_SERVER=yes go test -timeout 0 ./api -p 1 -count 1 -v
 54
 55## gofmt: Run `go fmt` for all go files.
 56gofmt:
 57	@echo "  >  Format all go files"
 58	$(GOENVVARS) gofmt -w ${GO_FILES}
 59
 60## govet: Run go vet.
 61govet:
 62	@echo "  >  Running go vet"
 63	$(GOENVVARS) go vet ./...
 64
 65## golint: Run default golint.
 66golint:
 67	@echo "  >  Running golint"
 68	$(GOENVVARS) golint -set_exit_status ./...
 69
 70## gocilint: Run Golang CI Lint.
 71gocilint:
 72	@echo "  >  Running Golang CI Lint"
 73	$-golangci-lint run --timeout=5m -E whitespace -E gosec -E gci -E misspell -E gomnd -E gofmt -E goimports -E golint --exclude-use-default=false --max-same-issues 0
 74
 75## exec: Run given command. e.g; make exec run="go test ./..."
 76exec:
 77	GOBIN=$(GOBIN) $(run)
 78
 79## clean: Clean build files. Runs `go clean` internally.
 80clean:
 81	@-rm $(GOBIN)/ 2> /dev/null
 82	@echo "  >  Cleaning build cache"
 83	$(GOENVVARS) go clean
 84
 85## build: Build the project.
 86build: install
 87	@echo "  >  Building Hermez binary..."
 88	@bash -c "$(MAKE) migration-pack"
 89	$(GOENVVARS) go build $(LDFLAGS) -o $(GOBIN)/$(GOBINARY) $(GOCMD)
 90	@bash -c "$(MAKE) migration-clean"
 91
 92## install: Install missing dependencies. Runs `go get` internally. e.g; make install get=github.com/foo/bar
 93install:
 94	@echo "  >  Checking if there is any missing dependencies..."
 95	$(GOENVVARS) go get $(GOCMD)/... $(get)
 96
 97## run-node: Run Hermez node.
 98run-node:
 99	@bash -c "$(MAKE) clean build"
100	@echo "  >  Running $(PROJECT_NAME)"
101	@$(GOBIN)/$(GOBINARY) run --mode $(MODE) --cfg $(CONFIG)
102
103## run-proof-mock: Run proof server mock API.
104run-proof-mock: stop-proof-mock
105	@echo "  >  Running Proof Server Mock"
106	$(GOENVVARS) go build -o $(GOBIN)/proof $(GOPROOF)
107	@$(GOBIN)/proof 2>&1 & echo $$! > $(PID_PROOF_MOCK)
108	@cat $(PID_PROOF_MOCK) | sed "/^/s/^/  \>  Proof Server Mock PID: /"
109
110## stop-proof-mock: Stop proof server mock API.
111stop-proof-mock:
112	@-touch $(PID_PROOF_MOCK)
113	@-kill -s INT `cat $(PID_PROOF_MOCK)` 2> /dev/null || true
114	@-rm $(PID_PROOF_MOCK) $(GOBIN)/proof 2> /dev/null || true
115
116## migration-pack: Pack the database migrations into the binary.
117migration-pack:
118	@echo "  >  Packing the migrations..."
119	@cd /tmp && go get -u github.com/gobuffalo/packr/v2/packr2 && cd -
120	@cd $(GOBASE)/db && packr2 && cd -
121
122## migration-clean: Clean the database migrations pack.
123migration-clean:
124	@echo "  >  Cleaning the migrations..."
125	@cd $(GOBASE)/db && packr2 clean && cd -
126
127## run-database-container: Run the Postgres container
128run-database-container:
129	@echo "  >  Running the postgreSQL DB..."
130	@-docker run --rm --name hermez-db -p 5432:5432 -e POSTGRES_DB=hermez -e POSTGRES_USER=hermez -e POSTGRES_PASSWORD="$(POSTGRES_PASS)" -d postgres
131
132## stop-database-container: Stop the Postgres container
133stop-database-container:
134	@echo "  >  Stopping the postgreSQL DB..."
135	@-docker stop hermez-db