-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
134 lines (112 loc) · 3.52 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
122
123
124
125
126
127
128
129
130
131
132
133
134
GOPATH:=$(shell go env GOPATH)
VERSION:=tmp-$(shell git describe --abbrev=8 --tags --always --dirty)
INTERNAL_PROTO_FILES=$(shell find internal -name *.proto)
API_PROTO_FILES=$(shell find api -name *.proto)
ARCH := amd64
IMAGE_REGISTRY ?= docker-reg.github.com:5000/k8s/service
PROJECT_NAME := $(shell pwd | awk -F '/' '{print $$NF}')
ORG := xdev
IMAGE_NAME ?= $(ORG)-$(PROJECT_NAME)-$(ARCH)
ifeq ($(IMAGE_REGISTRY),)
IMAGE := $(IMAGE_NAME)
else
IMAGE := $(IMAGE_REGISTRY)/$(IMAGE_NAME)
endif
APP_NAME := $(ORG)-$(PROJECT_NAME)
HELM_RELEASE_NAME := $(APP_NAME)
HELM_CHART_NAME := github-chartmuseum/$(ORG)-service
HELM_CHART_DIR := $(shell cd ./deploy/helm-charts && pwd)
#DEPLOYMENT := $(ORG)
HELM_VALUES_FILE := $(HELM_CHART_DIR)/$(DEPLOYMENT)-values.yaml
HELM_RELEASE_NAMESPACE := $(ORG)
.PHONY: init
# init tool
init:
GOPROXY=https://goproxy.cn,direct
go mod tidy
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/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest
go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
go install github.com/nicksnyder/go-i18n/v2/goi18n@latest
go install github.com/golangci/golangci-lint/cmd/[email protected]
go install github.com/favadi/protoc-go-inject-tag@latest
go install github.com/google/wire/cmd/wire@latest
go install github.com/onsi/ginkgo/v2/ginkgo@latest
.PHONY: api
# generate api
api:
$(shell protoc --proto_path=./api \
--proto_path=./third_party \
--go_out=paths=source_relative:./api \
--go-grpc_out=paths=source_relative:./api \
--go-errors_out=paths=source_relative:./api \
$(API_PROTO_FILES))
@for f in $(shell find api -name *.pb.go); do protoc-go-inject-tag -input=$${f} ;done
.PHONY: generate
# generate
generate:
go mod tidy
GOFLAGS=-mod=mod go generate ./...
.PHONY: wire
# generate DI code
wire:
cd cmd/server && wire
.PHONY: i18n
# generate i18n
i18n:
cd i18n && goi18n merge active.*.toml translate.*.toml && go run internal/i18n/generate.go
.PHONY: all
# generate all
all:
make api;
make generate;
.PHONY: lint
# lint
lint:
@echo "===========> Run lint to lint source codes"
golangci-lint run
.PHONY: fmt
# fmt
fmt:
@echo "===========> Run fmt to check source codes"
go fmt ./...
# build
.PHONY: build
build:
@echo "===========> Run go build"
mkdir -p bin && CGO_ENABLED=0 go build -o ./bin/ ./...
chmod +x ./bin/server
Package ?= ./...
Method ?= .
.PHONY: test
test:
@echo "===========> Run test to run Unit Test"
@echo "DOCKER_MACHINE_NAME:$(DOCKER_MACHINE_NAME)"
@echo "DOCKER_HOST:$(DOCKER_HOST)"
@echo "DOCKER_URL:$(DOCKER_URL)"
@echo "DOCKER_CERT_PATH:$(DOCKER_CERT_PATH)"
ls /var/run/docker.sock
go test --count=1 -v $(Package) -test.run $(Method) -covermode=set -coverprofile=report.txt
.PHONY:test-local
test-local:
go test --count=1 -v $(Package) -test.run $(Method) -covermode=set -coverprofile=report.txt
# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help