-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
108 lines (87 loc) · 3.08 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
MODULE := $(shell go list -m)
MODULE_NAME := $(lastword $(subst /, ,$(MODULE)))
BUILD := $(shell git rev-parse --short HEAD)@$(shell date +%s)
CURRENT_OS := $(shell uname | tr "[A-Z]" "[a-z]")
CURRENT_ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
DOCKER_IMAGE ?= ghcr.io/tbxark/$(MODULE_NAME)
DOCKER_FILE := cmd/app/Dockerfile
LD_FLAGS := "-X $(MODULE)/internal/config.BuildVersion=$(BUILD)"
GO_BUILD := CGO_ENABLED=0 go build -trimpath -ldflags $(LD_FLAGS) -tags=jsoniter
.PHONY: init
init: ## Init all dependencies
go mod download
go get entgo.io/ent/cmd/ent@latest
go get github.com/google/wire/cmd/wire@latest
go install github.com/swaggo/swag/cmd/swag@latest
go install github.com/bufbuild/buf/cmd/buf@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install github.com/favadi/protoc-go-inject-tag@latest
$(MAKE) install
$(MAKE) gen-ent
$(MAKE) gen-docs
$(MAKE) gen-wire
buf dep update
go mod tidy
.PHONY: install
install: ## Install all dependencies
cd contrib/protoc-gen-sphere && go mod download && go install .
cd contrib/protoc-gen-route && go mod download && go install .
cd contrib/ent-gen-proto && go mod download && go install .
.PHONY: gen-proto
gen-proto: ## Generate proto files and run protoc plugins
ent-gen-proto -path=./internal/pkg/database/schema
buf generate
protoc-go-inject-tag -input="./api/*/*/*.pb.go" -remove_tag_comment
.PHONY: gen-ent
gen-ent: ## Generate ent code
go generate ./internal/pkg/database/generate.go
.PHONY: gen-docs
gen-docs: gen-proto ## Generate swagger docs
go generate docs.go
.PHONY: gen-wire
gen-wire: ## Generate wire code
go generate ./cmd/...
.PHONY: gen-conf
gen-conf: ## Generate example config
go run ./cmd/cli/config gen
.PHONY: generate
generate: ## Run all generate command
go generate ./...
.PHONY: dash
dash: ## Build dash
sh ./assets/dash/build.sh
.PHONY: build
build: ## Build binary
$(GO_BUILD) -o ./build/$(CURRENT_OS)_$(CURRENT_ARCH)/ ./...
.PHONY: build-linux-amd64
build-linux-amd64: ## Build linux amd64 binary
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o ./build/linux_amd64/ ./...
.PHONY: build-linux-arm64
build-linux-arm64: ## Build linux arm64 binary
GOOS=linux GOARCH=arm64 $(GO_BUILD) -o ./build/linux_arm64/ ./...
.PHONY: build-all
build-all: build-linux-amd64 build-linux-arm64 ## Build all arch binary
.PHONY: build-docker
build-docker: ## Build docker image
docker buildx build --platform=linux/amd64,linux/arm64 -t $(DOCKER_IMAGE) . -f $(DOCKER_FILE) --push --provenance=false
.PHONY: delpoy
deploy: ## Deploy binary
ansible-playbook -i devops/hosts/inventory.ini devops/delpoy-binary.yaml
.PHONY: lint
lint: ## Run linter
golangci-lint run
buf lint
.PHONY: fmt
fmt: ## Run formatter
go fmt ./...
buf format
.PHONY: clean
clean: ## Clean build files
rm -rf ./build
rm -rf ./swagger
rm -rf ./api
rm -rf ./internal/pkg/database/ent
.PHONY: help
help: ## Show this help message
@echo "\n\033[1mSphere build tool.\033[0m Usage: make [target]\n"
@grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/\(.*\):.*##\(.*\)/\1:\2/' | column -t -s ':' | sed -e 's/^/ /'