-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
113 lines (91 loc) · 3.79 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
GOOS=linux
GOARCH=amd64
EXECUTABLE=chat-bot-hub
RUNTIME_PATH=build
RUNTIME_IMAGE=chat-bot-hub
PACKAGE=github.com/hawkwithwind/$(EXECUTABLE)
PROTOC_PATH=/opt/programs/protoc/bin
GOIMAGE=golang:1.11-alpine3.8
SOURCES=$(shell find server -type f -name '*.go' -not -path "./vendor/*")
BASE=$(GOPATH)/src/$(PACKAGE)
DBPATH="$(chathubdb)"
build-angular: $(RUNTIME_PATH)/$(EXECUTABLE) build-nodejs-image
if [ -d $(RUNTIME_PATH)/static/ ]; then chmod -R +w $(RUNTIME_PATH)/static/ ; fi && \
docker run --rm \
-v $(shell pwd)/frontend:/home/work \
$(RUNTIME_IMAGE):build-nodejs npm install && \
docker run --rm \
-v $(shell pwd)/frontend:/home/work \
-v $(shell pwd)/$(RUNTIME_PATH)/static:/home/build/static \
$(RUNTIME_IMAGE):build-nodejs gulp build && \
cp -R frontend/static/img $(RUNTIME_PATH)/static/ && \
cp -R frontend/static/lib $(RUNTIME_PATH)/static/ && \
cp frontend/index.html $(RUNTIME_PATH)/static/ && \
chmod -f -R -w $(RUNTIME_PATH)/static/
$(RUNTIME_PATH)/$(EXECUTABLE): $(SOURCES) $(RUNTIME_PATH) build-golang-image build-migrate-image
docker run --rm \
--env HTTPS_PROXY=$(https_proxy) \
--env HTTP_PROXY=$(http_proxy) \
--net=host \
-v $(GOPATH)/src:/go/src \
-v $(GOPATH)/pkg:/go/pkg \
-v $(shell pwd)/$(RUNTIME_PATH):/go/bin/${GOOS}_${GOARCH} \
-e GOOS=$(GOOS) -e GOARCH=$(GOARCH) -e GOBIN=/go/bin/$(GOOS)_$(GOARCH) -e CGO_ENABLED=0 \
$(RUNTIME_IMAGE):build-golang go get -a -installsuffix cgo $(PACKAGE)/server/...
#$(RUNTIME_PATH)/dockerfile: runtime-image
# sh make_docker_file.sh $(RUNTIME_PATH)/Dockerfile $(RUNTIME_IMAGE) $(EXECUTABLE)
#runtime-image:
# docker build -t $(RUNTIME_IMAGE) docker/runtime
build-migrate-image:
docker build --build-arg mirror=$(alpine_mirror) -t $(RUNTIME_IMAGE):migrate docker/migrate
build-nodejs-image:
docker build --build-arg mirror=$(debian_mirror) -t $(RUNTIME_IMAGE):build-nodejs docker/build/nodejs
build-golang-image:
docker build --build-arg mirror=$(alpine_mirror) -t $(RUNTIME_IMAGE):build-golang docker/build/golang
$(RUNTIME_PATH):
[ -d $(RUNTIME_PATH) ] || mkdir $(RUNTIME_PATH) && \
[ -d $(RUNTIME_PATH)/static ] || mkdir $(RUNTIME_PATH)/static
clean:
if [ -d $(RUNTIME_PATH)/static/ ]; then chmod -R +w $(RUNTIME_PATH)/static/ ; fi && \
rm -rf $(RUNTIME_PATH)
fmt:
docker run --rm \
-v $(shell pwd):/go/src/$(PACKAGE) \
$(RUNTIME_IMAGE):build-golang sh -c "cd /go/src/$(PACKAGE)/ && gofmt -l -w $(SOURCES)"
test: $(SOURCES) $(RUNTIME_PATH) build-golang-image
docker run --rm \
-e HTTPS_PROXY=$(https_proxy) \
-e HTTP_PROXY=$(http_proxy) \
-e DBPATH="$(TESTDBPATH)" \
--net=host \
-v $(GOPATH)/src:/go/src \
-v $(GOPATH)/pkg:/go/pkg \
-v $(shell pwd)/$(RUNTIME_PATH):/go/bin/${GOOS}_${GOARCH} \
-e GOOS=$(GOOS) -e GOARCH=$(GOARCH) -e GOBIN=/go/bin/$(GOOS)_$(GOARCH) -e CGO_ENABLED=0 \
$(RUNTIME_IMAGE):build-golang sh -c "cd /go/src/$(PACKAGE)/server/ && go test -v ./..."
cgo: $(RUNTIME_PATH)/$(EXECUTABLE)
npm-audit-fix: build-nodejs-image
docker run --rm \
-v $(shell pwd)/frontend:/home/work \
$(RUNTIME_IMAGE):build-nodejs npm audit fix
.PHONY: gen cgo
gen:
docker run --rm \
-e HTTPS_PROXY=$(https_proxy) \
-e HTTP_PROXY=$(http_proxy) \
--net=host \
-v $(GOPATH)/src:/go/src \
-v $(GOPATH)/pkg:/go/pkg \
-v $(GOPATH)/bin:/go/bin \
-v $(PROTOC_PATH):/home/bin \
-e PATH="/go/bin:/home/bin:${PATH}" \
-v $(shell pwd):/home/work \
-w /home/work \
$(RUNTIME_IMAGE):build-golang sh -c \
"go get -u github.com/golang/protobuf/protoc-gen-go && \
go get -u github.com/favadi/protoc-go-inject-tag && \
cd proto && \
protoc -I chatbothub/ chatbothub/chatbothub.proto --go_out=plugins=grpc:chatbothub && \
protoc-go-inject-tag -input=chatbothub/chatbothub.pb.go && \
protoc -I web/ web/web.proto --go_out=plugins=grpc:web && \
protoc-go-inject-tag -input=web/web.pb.go"