-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
89 lines (78 loc) · 2.41 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
# This how we want to name the binary output
# colors compatible setting
CRED:=$(shell tput setaf 1 2>/dev/null)
CGREEN:=$(shell tput setaf 2 2>/dev/null)
CYELLOW:=$(shell tput setaf 3 2>/dev/null)
CEND:=$(shell tput sgr0 2>/dev/null)
MAINVERSION=$(shell cat version | sed 's/^[ \t]*//g')
GITSHA := $(shell git rev-parse HEAD)
BUILDTIME=$(shell date +%FT%T%z)
REGISTRY=registry.cn-beijing.aliyuncs.com
ACCOUNT=eviltomorrow
.PHONY: go_version_check
GO_VERSION_MIN=1.19
# Parse out the x.y or x.y.z version and output a single value x*10000+y*100+z (e.g., 1.9 is 10900)
# that allows the three components to be checked in a single comparison.
VER_TO_INT:=awk '{split(substr($$0, match ($$0, /[0-9\.]+/)), a, "."); print a[1]*10000+a[2]*100+a[3]}'
go_version_check:
@echo "$(CGREEN)=> Go version check ...$(CEND)"
@if test $(shell go version | $(VER_TO_INT) ) -lt \
$(shell echo "$(GO_VERSION_MIN)" | $(VER_TO_INT)); \
then printf "go version $(GO_VERSION_MIN)+ required, found: "; go version; exit 1; \
else echo "go version check pass"; fi
# Code format
.PHONY: fmt
fmt: go_version_check
@echo "$(CGREEN)=> Run gofmt on all source files ...$(CEND)"
@echo "gofmt -l -s -w ..."
@ret=0 && for d in $$(go list -f '{{.Dir}}' ./... | grep -v /vendor/); do \
gofmt -l -s -w $$d/*.go || ret=$$? ; \
done ; exit $$ret
# build
.PHONY: build
build: export CGO_ENABLED=0
build: fmt
@mkdir -p bin
ifeq (${app},)
@bash build/app_build.sh
else
@bash build/app_build.sh ${app}
endif
# docker
.PHONY: docker
docker: vendor
docker: fmt
ifeq (${app},)
cp -f version deployments/version
@bash build/docker_build.sh ${MAINVERSION} ${GITSHA} ${BUILDTIME}
else
docker build --target prod -t ${REGISTRY}/${ACCOUNT}/${app} . --build-arg APPNAME=${app} --build-arg MAINVERSION=${MAINVERSION} --build-arg GITSHA=${GITSHA} --build-arg BUILDTIME=${BUILDTIME}
endif
# Compile protobuf
.PHONY: compile
compile:
@echo "$(CGREEN)=> Compile protobuf ...$(CEND)"
@rm -rf lib/grpc/pb/*
@bash scripts/protobuf_compile.sh
# clear
.PHONY: clear
clear:
@echo "$(CGREEN)=> Clear ./bin...$(CEND)"
@rm -rf bin/king-*
# mod
.PHONY: mod
mod: export GO111MODULE=on
mod:
@echo "$(CGREEN)=> go mod tidy$(CEND)"
@go mod tidy
# vendor
.PHONY: vendor
vendor: export GO111MODULE=on
vendor:
@echo "$(CGREEN)=> go mod vendor$(CEND)"
@GOWORK=off go mod vendor
# push
.PHONY: push
push:
@echo "$(CGREEN)=> docker push image$(CEND)"
@bash scripts/docker_push.sh ${MAINVERSION}