-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·72 lines (57 loc) · 2.67 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
.PHONY: aLl clean website
all: gotool depend commit config target website images
SHELL= /bin/bash
images_prefix=z-gour.com/perch
deploy_dir = ${shell pwd}/deploy
webserver_dir =${shell pwd}/web/server
website_dir = ${shell pwd}/website
bin_dir = ${shell pwd}/deploy/bin
dockerfiles_dir= ${shell pwd}/deploy/dockerfiles
gotool:
@echo "格式化代码"
go fmt ./
go vet ./
commit:
GIt_COMMIT=$(shell cd ${shell pwd} && git rev-parse --short HEAD)
depend:
go mod tidy
config:
cp -rv ../configs/* resource/config/
#p2pnetwork:
# go build -mod=mod -race -o bin/application/p2pnetwork ../internal/p2p/application/p2p_network.go
# go build -gcflags="all=-m" -ldflags="-X main.version=1.2.3" -o ${bin_dir}/$${server} ${webserver_dir}/$${server}/$${server}.go;
# 参考:https://blog.kowalczyk.info/article/vEja/embedding-build-number-in-go-executable.html
target:
@for server in `ls ${webserver_dir}`; \
do \
echo "go build -o ${bin_dir}/$${server} ${webserver_dir}/$${server}/$${server}.go" && \
go build -o ${bin_dir}/$${server} ${webserver_dir}/$${server}/$${server}.go; \
done
website:
npm --prefix ${website_dir} install
npm --prefix ${website_dir} run build:prod
mv -v ${website_dir}/dist ${deploy_dir}/resource/
website_image:
$(eval GIT_COMMIT=$(shell cd ${shell pwd} && git rev-parse --short HEAD))
docker build -t ${images_prefix}/website:$(GIT_COMMIT) -f ${deploy_dir}/dockerfiles/website/Dockerfile ${deploy_dir}
images:
#@for server in `ls ${bin_dir}`; do echo " docker build -t github.com/perch/$${server} . " && go build -o ${bin_dir}/$${server} ${webserver_dir}/$${server}/$${server}.go; docker build -t done
$(eval GIT_COMMIT=$(shell cd ${shell pwd} && git rev-parse --short HEAD))
#docker build -t ${images_prefix}/website:$(GIT_COMMIT) -f ${deploy_dir}/dockerfiles/website/Dockerfile ${deploy_dir}
@for service in `ls ${bin_dir}`; \
do echo $${service} && \
sed "s/service_bin/$${service}/g" ${dockerfiles_dir}/services/Dockerfile > ${dockerfiles_dir}/services/Dockerfile_$${service} && \
docker build -t ${images_prefix}/$${service}:$(GIT_COMMIT) -f ${deploy_dir}/dockerfiles/services/Dockerfile_$${service} ${deploy_dir} && \
rm -rf ${deploy_dir}/dockerfiles/services/Dockerfile_$${service} ;\
done
clean:
rm -rf ${deploy_dir}/bin/*
rm -rf ${deploy_dir}/resource/bin/*
rm -rf ${deploy_dir}/resource/dist/
rm -rf ${deploy_dir}/resource/config/configs
help:
@echo "make - 格式化 Go 代码, 并编译生成二进制文件"
@echo "make build - 编译 Go 代码, 生成二进制文件"
@echo "make run - 直接运行 Go 代码"
@echo "make clean - 移除二进制文件和 vim swap files"
@echo "make gotool - 运行 Go 工具 'fmt' and 'vet'"