This repository has been archived by the owner on Mar 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
172 lines (127 loc) · 4.5 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
GO_VERSION_SHORT:=$(shell echo `go version` | sed -E 's/.* go(.*) .*/\1/g')
ifneq ("1.17","$(shell printf "$(GO_VERSION_SHORT)\n1.17" | sort -V | head -1)")
$(warning NEED GO VERSION >= 1.17. Found: $(GO_VERSION_SHORT))
endif
GITHUB_PATH=github.com/arttet/rock-paper-scissors-lizard-spock
###############################################################################
.PHONY: all
all: .reqs deps gen build
.PHONY: reqs
reqs: .reqs
.PHONY: deps
deps: .deps-go
.PHONY: gen
gen: .generate-go
.PHONY: build
build: .build
.PHONY: debug
debug:
docker stop game-service || true
docker run --rm -d --publish 40000:40000 --publish 8080:8080 --security-opt=seccomp:unconfined --name game-service game-service:debug
.PHONY: test
test:
go test -v -timeout 30s -coverprofile cover.out ./...
go tool cover -func cover.out | grep -v -E '100.0%|total' || echo "OK"
go tool cover -func cover.out | grep total | awk '{print ($$3)}'
.PHONY: lint
lint:
buf lint
golangci-lint run ./...
.PHONY: tidy
tidy:
go mod tidy
.PHONY: fmt
fmt:
find . -iname *.go | xargs gofmt -w
find . -iname *.proto | xargs clang-format -i
.PHONY: cover
cover:
go tool cover -html cover.out
.PHONY: grpcui
grpcui:
grpcui -plaintext localhost:8082
.PHONY: image
image: .image
.PHONY: debug-image
debug-image: .debug-image
.PHONY: clean
clean:
rm -rd ./bin/ || true
docker container rm -f game-service || true
docker volume rm $(docker volume ls-q) || true
################################################################################
.PHONY: install
install:
cd website && npm install && cd ..
.PHONY: start
start:
npm start --prefix website
.PHONY: deploy
deploy:
npm run build --prefix website
################################################################################
.PHONY: .deps-go
.deps-go:
go mod download
go install github.com/golang/mock/mockgen@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/envoyproxy/protoc-gen-validate@latest
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@latest
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
################################################################################
# https://github.com/bufbuild/buf/releases
BUF_VERSION=v1.0.0-rc10
OS_NAME=$(shell uname -s)
OS_ARCH=$(shell uname -m)
GO_BIN=$(shell go env GOPATH)/bin
BUF_EXE=$(GO_BIN)/buf$(shell go env GOEXE)
ifeq ("NT", "$(findstring NT,$(OS_NAME))")
OS_NAME=Windows
endif
.reqs:
@command -v buf 2>&1 > /dev/null || (echo "Install buf" && \
mkdir -p "$(GO_BIN)" && \
curl -k -sSL0 https://github.com/bufbuild/buf/releases/download/$(BUF_VERSION)/buf-$(OS_NAME)-$(OS_ARCH)$(shell go env GOEXE) -o "$(BUF_EXE)" && \
chmod +x "$(BUF_EXE)")
################################################################################
.generate-go: .generate-mock .generate-game-service
.generate-mock:
go generate ./...
.generate-game-service: $(eval SERVICE_NAME := game-service) .generate-template
.generate-template:
@ echo $(SERVICE_NAME)
@ $(BUF_EXE) generate
@ cp -R pkg/$(GITHUB_PATH)/pkg/* pkg/
@ rm -rf pkg/github.com/
@ cd pkg/$(SERVICE_NAME) && ls go.mod || (go mod init $(GITHUB_PATH)/pkg/$(SERVICE_NAME) && go mod tidy)
################################################################################
.build: .build-game-service
.build-game-service: \
$(eval SERVICE_NAME := game-service) \
$(eval SERVICE_MAIN := cmd/$(SERVICE_NAME)/main.go) \
$(eval SERVICE_EXE := ./bin/$(SERVICE_NAME)) \
.build-template
.build-template:
CGO_ENABLED=0 go build \
-mod=mod \
-ldflags=" \
-X '$(GITHUB_PATH)/internal/config.version=$(VERSION)' \
-X '$(GITHUB_PATH)/internal/config.commitHash=$(COMMIT_HASH)' \
" \
-o $(SERVICE_EXE)$(shell go env GOEXE) $(SERVICE_MAIN)
################################################################################
.image: .image-game-service
.image-game-service: \
$(eval SERVICE_NAME := game-service) \
.image-template
.image-template:
docker build . --file deploy/docker/$(SERVICE_NAME)/Dockerfile --tag $(SERVICE_NAME):dev
################################################################################
.debug-image: .debug-image-game-service
.debug-image-game-service: \
$(eval SERVICE_NAME := game-service) \
.debug-image-template
.debug-image-template:
docker build . --file deploy/docker/$(SERVICE_NAME)/Dockerfile.debug --tag $(SERVICE_NAME):debug