-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
174 lines (136 loc) · 6.2 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
.PHONY: test check clean build dist all
TOP_DIR := $(shell pwd)
# ifeq ($(FILE), $(wildcard $(FILE)))
# @ echo target file not found
# endif
DIST_VERSION := 1.0.0
DIST_OS := linux
DIST_ARCH := amd64
DIST_OS_DOCKER ?= linux
DIST_ARCH_DOCKER ?= amd64
ROOT_NAME ?= bclog
ROOT_DOCKER_SERVICE ?= $(ROOT_NAME)
ROOT_BUILD_PATH ?= ./build
ROOT_DIST ?= ./dist
ROOT_REPO ?= ./dist
ROOT_TEST_BUILD_PATH ?= $(ROOT_BUILD_PATH)/test/$(DIST_VERSION)
ROOT_TEST_DIST_PATH ?= $(ROOT_DIST)/test/$(DIST_VERSION)
ROOT_TEST_OS_DIST_PATH ?= $(ROOT_DIST)/$(DIST_OS)/test/$(DIST_VERSION)
ROOT_REPO_DIST_PATH ?= $(ROOT_REPO)/$(DIST_VERSION)
ROOT_REPO_OS_DIST_PATH ?= $(ROOT_REPO)/$(DIST_OS)/release/$(DIST_VERSION)
ROOT_LOG_PATH ?= ./log
# can use as https://goproxy.io/ https://gocenter.io https://mirrors.aliyun.com/goproxy/
INFO_GO_PROXY ?= https://mirrors.aliyun.com/goproxy/
checkEnvGo:
ifndef GOPATH
@echo Environment variable GOPATH is not set
exit 1
endif
init: checkEnvGo
@echo "~> start init this project"
@echo "-> check version"
go version
@echo "-> check env golang"
go env
@echo "~> you can use [ make help ] see more task"
-GOPROXY="$(INFO_GO_PROXY)" GO111MODULE=on go mod vendor
@echo "~> you can use [ make help ] see more task"
checkDepends:
# in GOPATH just use GO111MODULE=on go mod init to init after golang 1.12
-GOPROXY="$(INFO_GO_PROXY)" GO111MODULE=on go mod verify
dependenciesVendor:
-GOPROXY="$(INFO_GO_PROXY)" GO111MODULE=on go mod vendor
dep: checkDepends dependenciesVendor
@echo "just check dependencies info below"
dependenciesInit:
-GOPROXY="$(INFO_GO_PROXY)" GO111MODULE=on go mod init
dependenciesTidy:
-GOPROXY="$(INFO_GO_PROXY)" GO111MODULE=on go mod tidy
dependenciesDownload:
-GOPROXY="$(INFO_GO_PROXY)" GO111MODULE=on go mod download
dependenciesGraph:
GOPROXY="$(INFO_GO_PROXY)" GO111MODULE=on go mod graph
cleanBuild:
@if [ -d ${ROOT_BUILD_PATH} ]; then rm -rf ${ROOT_BUILD_PATH} && echo "~> cleaned ${ROOT_BUILD_PATH}"; else echo "~> has cleaned ${ROOT_BUILD_PATH}"; fi
cleanLog:
@if [ -d ${ROOT_LOG_PATH} ]; then rm -rf ${ROOT_LOG_PATH} && echo "~> cleaned ${ROOT_LOG_PATH}"; else echo "~> has cleaned ${ROOT_LOG_PATH}"; fi
cleanDist:
@if [ -d ${ROOT_DIST} ]; then rm -rf ${ROOT_DIST} && echo "~> cleaned ${ROOT_DIST}"; else echo "~> has cleaned ${ROOT_DIST}"; fi
clean: cleanBuild cleanLog
@echo "~> clean finish"
checkTestBuildPath:
@if [ ! -d ${ROOT_TEST_BUILD_PATH} ]; then mkdir -p ${ROOT_TEST_BUILD_PATH} && echo "~> mkdir ${ROOT_TEST_BUILD_PATH}"; fi
checkTestDistPath:
@if [ ! -d ${ROOT_TEST_DIST_PATH} ]; then mkdir -p ${ROOT_TEST_DIST_PATH} && echo "~> mkdir ${ROOT_TEST_DIST_PATH}"; fi
checkTestOSDistPath:
@if [ ! -d ${ROOT_TEST_OS_DIST_PATH} ]; then mkdir -p ${ROOT_TEST_OS_DIST_PATH} && echo "~> mkdir ${ROOT_TEST_OS_DIST_PATH}"; fi
checkReleaseDistPath:
@if [ ! -d ${ROOT_REPO_DIST_PATH} ]; then mkdir -p ${ROOT_REPO_DIST_PATH} && echo "~> mkdir ${ROOT_REPO_DIST_PATH}"; fi
checkReleaseOSDistPath:
@if [ ! -d ${ROOT_REPO_OS_DIST_PATH} ]; then mkdir -p ${ROOT_REPO_OS_DIST_PATH} && echo "~> mkdir ${ROOT_REPO_OS_DIST_PATH}"; fi
buildMain:
@go build -o build/main example/demo/demo.go
buildARCH:
@echo "-> start build OS:$(DIST_OS) ARCH:$(DIST_ARCH)"
@GOOS=$(DIST_OS) GOARCH=$(DIST_ARCH) go build -o build/main example/demo/demo.go
buildDocker: checkDepends cleanBuild
@echo "-> start build OS:$(DIST_OS_DOCKER) ARCH:$(DIST_ARCH_DOCKER)"
@GOOS=$(DIST_OS_DOCKER) GOARCH=$(DIST_ARCH_DOCKER) go build -o build/main example/demo/demo.go
dev: buildMain
-./build/main
runTest: buildMain
-./build/main
test: checkDepends buildMain checkTestDistPath
mv ./build/main $(ROOT_TEST_DIST_PATH)
cp ./conf/test/config.yaml $(ROOT_TEST_DIST_PATH)
@echo "=> pkg at: $(ROOT_TEST_DIST_PATH)"
testOS: checkDepends buildARCH checkTestOSDistPath
@echo "=> Test at: $(DIST_OS) ARCH as: $(DIST_ARCH)"
mv ./build/main $(ROOT_TEST_OS_DIST_PATH)
cp ./conf/test/config.yaml $(ROOT_TEST_OS_DIST_PATH)
@echo "=> pkg at: $(ROOT_TEST_OS_DIST_PATH)"
release: checkDepends buildMain checkReleaseDistPath
mv ./build/main $(ROOT_REPO_DIST_PATH)
cp ./conf/release/config.yaml $(ROOT_REPO_DIST_PATH)
@echo "=> pkg at: $(ROOT_REPO_DIST_PATH)"
releaseOS: checkDepends buildARCH checkReleaseOSDistPath
@echo "=> Release at: $(DIST_OS) ARCH as: $(DIST_ARCH)"
mv ./build/main $(ROOT_REPO_OS_DIST_PATH)
cp ./conf/release/config.yaml $(ROOT_REPO_OS_DIST_PATH)
@echo "=> pkg at: $(ROOT_REPO_OS_DIST_PATH)"
# just use test config and build as linux amd64
dockerRun: buildDocker checkTestBuildPath
mv ./build/main $(ROOT_TEST_BUILD_PATH)
@echo "=> pkg at: $(ROOT_TEST_BUILD_PATH)"
@echo "-> try run docker container $(ROOT_NAME)"
ROOT_NAME=$(ROOT_NAME) DIST_VERSION=$(DIST_VERSION) docker-compose up -d
-sleep 5
@echo "=> container $(ROOT_NAME) now status"
docker inspect --format='{{ .State.Status}}' $(ROOT_NAME)
docker logs $(ROOT_NAME)
dockerStop:
ROOT_NAME=$(ROOT_NAME) DIST_VERSION=$(DIST_VERSION) docker-compose stop
dockerRemove: dockerStop
ROOT_NAME=$(ROOT_NAME) DIST_VERSION=$(DIST_VERSION) docker-compose rm -f $(ROOT_DOCKER_SERVICE)
docker network prune
help:
@echo "make init - check base env of this project"
@echo "make dep - check dependencies of project"
@echo "make dependenciesGraph - see dependencies graph of project"
@echo "make dependenciesTidy - tidy dependencies graph of project"
@echo ""
@echo "make clean - remove binary file and log files"
@echo ""
@echo "-- now build name: $(ROOT_NAME) version: $(DIST_VERSION)"
@echo "-- testOS or releaseOS will out abi as: $(DIST_OS) $(DIST_ARCH) --"
@echo "make test - build dist at $(ROOT_TEST_DIST_PATH)"
@echo "make testOS - build dist at $(ROOT_TEST_OS_DIST_PATH)"
@echo "make testOSTar - build dist at $(ROOT_TEST_OS_DIST_PATH) and tar"
@echo "make release - build dist at $(ROOT_REPO_DIST_PATH)"
@echo "make releaseOS - build dist at $(ROOT_REPO_OS_DIST_PATH)"
@echo "make releaseOSTar - build dist at $(ROOT_REPO_OS_DIST_PATH) and tar"
@echo ""
@echo "make runTest - run server use conf/test/config.yaml"
@echo "make dev - run server use conf/config.yaml"
@echo "make dockerRun - run docker-compose server as $(ROOT_DOCKER_SERVICE) container-name at $(ROOT_NAME)"
@echo "make dockerStop - stop docker-compose server as $(ROOT_DOCKER_SERVICE) container-name at $(ROOT_NAME)"