-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
executable file
·121 lines (104 loc) · 3.28 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
109
110
111
112
113
114
115
116
117
118
119
120
121
# note: call scripts from /scripts
GOHOSTOS:=$(shell go env GOHOSTOS)
GOPATH:=$(shell go env GOPATH)
VERSION=$(shell git describe --tags --always)
ifeq ($(GOHOSTOS), windows)
#the `find.exe` is different from `find` in bash/shell.
#to see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find.
#changed to use git-bash.exe to run find cli or other cli friendly, caused of every developer has a Git.
Git_Bash= $(subst cmd\,bin\bash.exe,$(dir $(shell where git)))
INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name *.proto")
API_PROTO_FILES=$(shell $(Git_Bash) -c "find api -name *.proto")
else
INTERNAL_PROTO_FILES=$(shell find internal -name *.proto)
API_PROTO_FILES=$(shell find api -name *.proto)
endif
.PHONY: init
# init env
init:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
go install github.com/google/wire/cmd/wire@latest
.PHONY: config
# generate internal proto
config:
protoc --proto_path=./internal \
--proto_path=./third_party \
--go_out=paths=source_relative:./internal \
$(INTERNAL_PROTO_FILES)
.PHONY: api
# generate api proto
api:
mkdir -p api/my/v1/my && rm -rf api/my/v1/my/*
protoc --proto_path=./api/my/v1 \
--proto_path=./third_party \
--go_out=paths=source_relative:./api/my/v1/my \
--go-http_out=paths=source_relative:./api/my/v1/my \
--go-grpc_out=paths=source_relative:./api/my/v1/my \
$(API_PROTO_FILES)
.PHONY: swagger
# generate swagger file
swagger:
protoc --proto_path=. \
--proto_path=./third_party \
--openapiv2_out . \
--openapiv2_opt logtostderr=true \
--openapiv2_opt json_names_for_fields=false \
$(API_PROTO_FILES)
.PHONY: generate
# generate client code
generate:
go generate ./...
.PHONY: wire
# generate wire code
wire:
make wire-outer
.PHONY: wire-router
# generate wire code
wire-router:
go mod tidy
cd cmd/router && wire
.PHONY: build
# build
build:
make wire
mkdir -p bin/ && go build -ldflags "-s -w -X main.Version=$(VERSION)" -o ./bin/ ./...
# project name
PROJECTNAME=$(shell basename "$(PWD)")
# project path
ROOT=$(shell pwd)
.PHONY: help
all: help
help: Makefile
@echo
@echo " Choose a command run in "$(PROJECTNAME)":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo
## mysql-init: init mysql db, example.. make mysql-init env=test
mysql-init:
@echo "init db..."
@./scripts/init_db_env.sh $(ROOT) $(env)
## test: run project all unit tests
test:
@echo "run project unit test"
@./scripts/init_db_env.sh $(ROOT)
@go test -p 1 -cover ./...
### build: build project, all binaries for programs to $GOPATH/bin
#build:
# @echo "build project"
# #@./scripts/shell.sh
#
### mod: update or clear mod pkg, do=tidy or do=vendor
#mod:
# @echo "use mod"
# @./scripts/pkg.sh $(ROOT) $(do)
## docker-image: make docker image, env=test/dev/prod
docker-image:
@$(ROOT)/gw/docker/mk_image.sh $(env) 1
## docker-image-timer: make docker image, env=test/dev/prod
docker-image-timer:
@$(ROOT)/gw-timer/docker/mk_image.sh $(env) 1