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.

135 lines
4.2 KiB

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