Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
153 lines (126 loc) · 5.11 KB
/
Copy pathMakefile
File metadata and controls
153 lines (126 loc) · 5.11 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
include scripts/env
# 全局通用变量
GO := go
GORUN := ${GO} run
GOPATH := $(shell ${GO} env GOPATH)
GOOS ?= $(shell ${GO} env GOOS)
GOARCH ?= $(shell ${GO} env GOARCH)
GOBUILD := ${GO} build
WORKDIR := $(shell pwd)
GOHOSTOS := $(shell ${GO} env GOHOSTOS)
SHORTNAME ?= $(shell basename $(shell pwd))
NAMESPACE ?= $(shell basename $(shell cd ../;pwd))
# 自动化版本号
GIT_COMMIT := $(shell git rev-parse HEAD 2>/dev/null)
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
BUILD_DATE := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
COMMIT_DATE := $(shell git --no-pager log -1 --format='%ct' 2>/dev/null)
PREFIX_VERSION := $(shell ./scripts/version.sh prefix)
RELEASE_VERSION ?= $(shell ./scripts/version.sh release)
BUILD_LD_FLAGS := "-s -w \
-X 'github.com/grpc-kit/pkg/vars.Appname=known-testbed-v1' \
-X 'github.com/grpc-kit/pkg/vars.CliVersion=${CLI_VERSION}' \
-X 'github.com/grpc-kit/pkg/vars.GitCommit=${GIT_COMMIT}' \
-X 'github.com/grpc-kit/pkg/vars.GitBranch=${GIT_BRANCH}' \
-X 'github.com/grpc-kit/pkg/vars.BuildDate=${BUILD_DATE}' \
-X 'github.com/grpc-kit/pkg/vars.CommitUnixTime=${COMMIT_DATE}' \
-X 'github.com/grpc-kit/pkg/vars.ReleaseVersion=${RELEASE_VERSION}'"
##@ General
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Check
.PHONY: precheck
precheck: ## Check environment.
@echo ">> precheck environment"
@./scripts/precheck.sh
##@ Development
.PHONY: generate
manifests: ## Generate deployment manifests files, like: "make manifests TEMPLATES=kubernetes".
@./scripts/manifests.sh
generate: precheck ## Generate code from proto files.
@echo ">> generation release version"
@./scripts/version.sh update
@echo ">> generation code from proto files"
@./scripts/generate.sh
@echo ">> synchronize Go module dependencies"
@${GO} mod tidy
@echo ">> generation database schema"
@./scripts/generate.sh gen_ent
.PHONY: lint
lint: generate ## Run go fmt and vet against code.
@${GO} mod tidy
@${GO} fmt ./...
@${GO} vet ./...
@${GO} vet -tags=e2e ./test/e2e/...
.PHONY: test
test: generate ## Run unit tests.
@${GO} mod tidy
@${GO} test ./... -timeout 3m -v -gcflags=-l -cover=true
.PHONY: test-e2e
test-e2e: ## Run black-box API e2e tests against a running local server (make run).
@${GO} test -tags=e2e -p 1 -count=1 ./test/e2e/... -timeout 5m -v
.PHONY: skills
skills: ## Install or update grpc-kit common skills.
@if [ ! -d ".git" ]; then \
echo "==> Initializing git repository..."; \
git init; \
fi
@if [ ! -e "scripts/skills/.git" ]; then \
echo "==> scripts/skills not found or not a submodule. Initializing..."; \
if [ -d "scripts/skills" ]; then rm -rf scripts/skills; fi; \
git submodule add -f https://github.com/grpc-kit/skills.git scripts/skills; \
git submodule update --init --recursive; \
else \
echo "==> scripts/skills exists. Syncing with remote (main)..."; \
git submodule update --remote --rebase scripts/skills; \
fi
@echo "==> Skills are up-to-date."
##@ Build
.PHONY: build
build: clean generate ## Build binary files according to the target system arch.
@mkdir build
@mkdir build/deploy
@${GO} mod tidy
@GOOS=${GOOS} GOARCH=${GOARCH} ${GOBUILD} -ldflags ${BUILD_LD_FLAGS} -o build/service cmd/server/main.go
.PHONY: run
run: generate ## Run a application from your host.
@${GO} mod tidy
@${GORUN} -ldflags ${BUILD_LD_FLAGS} cmd/server/main.go -c config/app-dev-local.yaml
.PHONY: docker-run
docker-run: ## Run a application from your docker.
@./scripts/docker.sh run
.PHONY: docker-build
docker-build: build manifests ## Build docker image with the application.
@echo ">> docker build"
@./scripts/docker.sh build
.PHONY: docker-push
docker-push: ## Push docker image with the application.
@echo ">> docker push"
@./scripts/docker.sh push
##@ Build Dependencies
.PHONY: protoc
protoc: ## Download protoc locally if necessary.
@echo ">> download binary protoc"
@./scripts/binaries.sh protoc
.PHONY: protoc-gen-go
protoc-gen-go: ## Download protoc-gen-go locally if necessary.
@echo ">> download binary protoc-gen-go"
@./scripts/binaries.sh protoc-gen-go
.PHONY: protoc-gen-go-grpc
protoc-gen-go-grpc: ## Download protoc-gen-go-grpc locally if necessary.
@echo ">> download binary protoc-gen-go-grpc"
@./scripts/binaries.sh protoc-gen-go-grpc
.PHONY: protoc-gen-grpc-gateway
protoc-gen-grpc-gateway: ## Download protoc-gen-grpc-gateway locally if necessary.
@echo ">> download binary protoc-gen-grpc-gateway"
@./scripts/binaries.sh protoc-gen-grpc-gateway
.PHONY: protoc-gen-openapiv2
protoc-gen-openapiv2: ## Download protoc-gen-openapiv2 locally if necessary.
@echo ">> download binary protoc-gen-openapiv2"
@./scripts/binaries.sh protoc-gen-openapiv2
##@ Clean
.PHONY: clean
clean: ## Clean build.
@echo ">> clean build"
@rm -rf build/