-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
74 lines (59 loc) · 2.23 KB
/
Makefile
File metadata and controls
74 lines (59 loc) · 2.23 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
.PHONY: build clean run build-linux images push release-images ver
define echo_green
printf "\e[38;5;40m"
echo "${1}"
printf "\e[0m \n"
endef
#项目名
Project=fuck-gpu
BINARY=${Project}
Path=github.com/deeprpa/${Project}/version
#当前版本号,每次更新服务时都必须更新版本号, 或使用 tag, 更新 tag
# Version=v1.0.1
Version=$(shell git describe --tags --dirty)
GitCommit=$(shell git rev-parse --short HEAD || echo unsupported)
GoVersion=$(shell go version)
BuildTime=$(shell date "+%Y-%m-%d_%H:%M:%S")
current_dir=$(shell pwd)
#pb_go_files=./pb/common.pb.go ./pb/service.pb.go
#goflags=GOFLAGS="-mod=readonly"
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS=-ldflags "-w -s \
-X ${Path}.Version=${Version} \
-X '${Path}.GitCommit=${GitCommit}' \
-X '${Path}.GoVersion=${GoVersion}' \
-X '${Path}.BuildTime=${BuildTime}'"
clean:
rm -rf ./build
build:
${goflags} go build ${LDFLAGS} -v -o ./build/${Project}
# @ before command only output result
@echo "build finish !!!"
@echo "Version: " $(Version)
@echo "Git commit:" $(GitCommit)
@echo "Go version:" $(GoVersion)
@echo "Build time:" $(BuildTime)
@${call echo_green,"build finished! The target is ${current_dir}/build/${Project}."}
run:
${goflags} go run ${LDFLAGS} main.go d
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o build/${Project} -v
# @ before command only output result
@echo "build finish !!!"
@echo "Version: " $(Version)
@echo "Git commit:" $(GitCommit)
@echo "Go version:" $(GoVersion)
@echo "Build time:" $(BuildTime)
@${call echo_green,"build finished! The target is ${current_dir}/build/${Project}."}
images:
docker build -t registry.cn-hangzhou.aliyuncs.com/pedge-platform/${Project}:${Version} .
push: images
docker push registry.cn-hangzhou.aliyuncs.com/pedge-platform/${Project}:${Version}
release-images: push
docker tag registry.cn-hangzhou.aliyuncs.com/pedge-platform/${Project}:${Version} registry.cn-hangzhou.aliyuncs.com/pedge-platform/${Project}:latest
docker push registry.cn-hangzhou.aliyuncs.com/pedge-platform/${Project}:latest
ver:
@echo "Version: " $(Version)
@echo "Git commit:" $(GitCommit)
@echo "Go version:" $(GoVersion)
@echo "Build time:" $(BuildTime)