forked from topfreegames/pitaya
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
233 lines (174 loc) · 9.38 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
ifeq ($(OS), Windows_NT)
BIN := pitaya-cli.exe
XK6_BIN := k6.exe
MKFOLDER := if not exist "build" mkdir build
GREP_CMD := findstr /V
else
BIN := pitaya-cli
XK6_BIN := k6
MKFOLDER := mkdir -p build
GREP_CMD := grep -v
endif
TESTABLE_PACKAGES = `go list ./... | $(GREP_CMD) examples | $(GREP_CMD) constants | $(GREP_CMD) mocks | $(GREP_CMD) helpers | $(GREP_CMD) interfaces | $(GREP_CMD) protos | $(GREP_CMD) e2e | $(GREP_CMD) benchmark`
init-toolchain:
#download protoc url=https://github.com/protocolbuffers/protobuf/releases then add bin to PATH
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
@go install github.com/alkaid/goerrors/cmd/protoc-gen-go-errors@latest
setup: init-submodules
@go mod tidy
build-cli:
@$(MKFOLDER)
@go build -o build/$(BIN) github.com/topfreegames/pitaya/v2/pitaya-cli
@echo "build pitaya-cli at ./build/$(BIN)"
build-k6-extension:
@$(MKFOLDER)
@xk6 build --with github.com/topfreegames/xk6-pitaya=./xk6-pitaya/ --with github.com/topfreegames/pitaya/v2=./ --with google.golang.org/grpc=google.golang.org/[email protected] --output ./build/$(XK6_BIN)
@echo "build pitaya k6 extension at ./build/$(XK6_BIN)"
init-submodules:
@git submodule init
setup-ci:
@go get github.com/mattn/goveralls
@go get -u github.com/wadey/gocovmerge
setup-protobuf-macos:
@brew install protobuf
@go get github.com/golang/protobuf/protoc-gen-go
run-jaeger-aio:
@docker-compose -f ./examples/testing/docker-compose-jaeger.yml up -d
@echo "Access jaeger UI @ http://localhost:16686"
run-chat-example:
@cd examples/testing && docker-compose up -d etcd nats && cd ../demo/chat/ && go run main.go
run-cluster-example-frontend-tracing:
@PITAYA_METRICS_PROMETHEUS_PORT=9090 JAEGER_SAMPLER_PARAM=1 JAEGER_DISABLED=false JAEGER_SERVICE_NAME=example-frontend JAEGER_AGENT_PORT=6832 go run examples/demo/cluster/main.go
run-cluster-example-backend-tracing:
@PITAYA_METRICS_PROMETHEUS_PORT=9091 JAEGER_SAMPLER_PARAM=1 JAEGER_DISABLED=false JAEGER_SERVICE_NAME=example-backend JAEGER_AGENT_PORT=6832 go run examples/demo/cluster/main.go --port 3251 --type room --frontend=false
run-cluster-example-frontend:
@PITAYA_METRICS_PROMETHEUS_PORT=9090 go run examples/demo/cluster/main.go
run-cluster-protobuf-frontend-example:
@cd examples/demo/cluster_protobuf && go run main.go
run-cluster-protobuf-backend-example:
@cd examples/demo/cluster_protobuf && go run main.go --port 3251 --type room --frontend=false
run-cluster-example-backend:
@PITAYA_METRICS_PROMETHEUS_PORT=9091 go run examples/demo/cluster/main.go --port 3251 --type room --frontend=false
run-cluster-grpc-example-connector:
@cd examples/demo/cluster_grpc && go run main.go
run-cluster-grpc-example-room:
@cd examples/demo/cluster_grpc && go run main.go --port 3251 --rpcsvport 3435 --type room --frontend=false
run-cluster-worker-example-room:
@cd examples/demo/worker && go run main.go --type room --frontend=true
run-cluster-worker-example-metagame:
@cd examples/demo/worker && go run main.go --type metagame --frontend=false
run-cluster-worker-example-worker:
@cd examples/demo/worker && go run main.go --type worker --frontend=false
run-custom-metrics-example:
@cd examples/demo/custom_metrics && go run main.go --port 3250
run-rate-limiting-example:
@go run examples/demo/rate_limiting/main.go
protos-compile-demo:
@protoc -I examples/demo/protos examples/demo/protos/*.proto --go_out=.
@protoc -I examples/testing/protos examples/testing/protos/*.proto --go_out=.
@protoc -I examples/demo/cluster_protobuf/protos examples/demo/cluster_protobuf/protos/*.proto --go_out=.
@protoc -I examples/demo/worker/protos examples/demo/worker/protos/*.proto --go_out=.
@#protoc -I examples/demo/cluster_ak/protos examples/demo/cluster_ak/protos/*.proto --go_out=.
#https://developers.google.com/protocol-buffers/docs/reference/go-generated
protos-compile:
@cd benchmark/testdata && ./gen_proto.sh
@protoc --proto_path=. --proto_path=./pitaya-protos/lib/alkaid/goerrors pitaya-protos/*.proto --go_out=. --go_opt=paths=import --go-errors_out=.
@protoc --proto_path=. --proto_path=./pitaya-protos/lib/alkaid/goerrors pitaya-protos/*.proto --go-grpc_out=.
@protoc -I pitaya-protos/test pitaya-protos/test/*.proto --go_out=protos/test --go_opt=paths=import
rm-test-temp-files:
@rm -f cluster/127.0.0.1* 127.0.0.1*
@rm -f cluster/localhost* localhost*
ensure-testing-bin:
@[ -f ./examples/testing/server ] || go build -o ./examples/testing/server ./examples/testing/main.go
ensure-testing-deps:
@cd ./examples/testing && docker-compose up -d
ensure-e2e-deps-grpc:
@cd ./examples/testing && docker-compose up -d etcd
kill-testing-deps:
@cd ./examples/testing && docker-compose down; true
kill-jaeger:
@docker-compose -f ./examples/testing/docker-compose-jaeger.yml down; true
e2e-test: e2e-test-nats e2e-test-grpc
e2e-test-nats: ensure-testing-deps ensure-testing-bin
@echo "===============RUNNING E2E NATS TESTS==============="
@go test ./e2e/e2e_test.go -update
e2e-test-grpc: ensure-testing-deps ensure-testing-bin
@echo "===============RUNNING E2E GRPC TESTS==============="
@go test ./e2e/e2e_test.go -update -grpc
bench-nats-sv:
@PITAYA_METRICS_PROMETHEUS_PORT=9098 ./examples/testing/server -type game -frontend=false > /dev/null 2>&1 & echo $$! > back.PID
@PITAYA_METRICS_PROMETHEUS_PORT=9099 ./examples/testing/server -type connector -frontend=true > /dev/null 2>&1 & echo $$! > front.PID
bench-grpc-sv:
@PITAYA_METRICS_PROMETHEUS_PORT=9098 ./examples/testing/server -grpc -grpcport=3435 -type game -frontend=false > /dev/null 2>&1 & echo $$! > back.PID
@PITAYA_METRICS_PROMETHEUS_PORT=9099 ./examples/testing/server -grpc -grpcport=3436 -type connector -frontend=true > /dev/null 2>&1 & echo $$! > front.PID
benchmark-test-nats: ensure-testing-deps ensure-testing-bin
@echo "===============RUNNING BENCHMARK TESTS WITH NATS==============="
@echo "--- starting testing servers"
@echo "--- sleeping for 5 seconds"
@make bench-nats-sv
@sleep 5
@go test ./benchmark/benchmark_test.go -bench=.
@echo "--- killing testing servers"
@kill `cat back.PID` && rm back.PID
@kill `cat front.PID` && rm front.PID
benchmark-test-grpc: ensure-e2e-deps-grpc ensure-testing-bin
@echo "===============RUNNING BENCHMARK TESTS WITH GRPC==============="
@echo "--- starting testing servers"
@echo "--- sleeping for 5 seconds"
@make bench-grpc-sv
@sleep 5
@go test ./benchmark/benchmark_test.go -bench=.
@echo "--- killing testing servers"
@kill `cat back.PID` && rm back.PID
@kill `cat front.PID` && rm front.PID
unit-test-coverage: kill-testing-deps
@echo "===============RUNNING UNIT TESTS==============="
@go test $(TESTABLE_PACKAGES) -coverprofile coverprofile.out
test: kill-testing-deps test-coverage
@make rm-test-temp-files
@make ensure-testing-deps
@sleep 10
@make e2e-test
test-coverage: unit-test-coverage
@make rm-test-temp-files
test-coverage-html: test-coverage
@go tool cover -html=coverprofile.out
merge-profiles:
@rm -f coverage-all.out
@gocovmerge *.out > coverage-all.out
test-coverage-func coverage-func: test-coverage merge-profiles
@echo
@echo "\033[1;34m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\033[0m"
@echo "\033[1;34mFunctions NOT COVERED by Tests\033[0m"
@echo "\033[1;34m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\033[0m"
@go tool cover -func=coverage-all.out | egrep -v "100.0[%]"
mocks: agent-mock session-mock networkentity-mock pitaya-mock serializer-mock metrics-mock acceptor-mock message-mock protos-client-mock cluster-mock discovery-mock
agent-mock:
@mockgen github.com/topfreegames/pitaya/v2/agent Agent,AgentFactory | sed 's/mock_agent/mocks/' > agent/mocks/agent.go
session-mock:
@mockgen github.com/topfreegames/pitaya/v2/session Session,SessionPool | sed 's/mock_session/mocks/' > session/mocks/session.go
networkentity-mock:
@mockgen github.com/topfreegames/pitaya/v2/networkentity NetworkEntity | sed 's/mock_networkentity/mocks/' > networkentity/mocks/networkentity.go
pitaya-mock:
@mockgen github.com/topfreegames/pitaya/v2 Pitaya | sed 's/mock_v2/mocks/' > mocks/app.go
metrics-mock:
@mockgen github.com/topfreegames/pitaya/v2/metrics Reporter | sed 's/mock_metrics/mocks/' > metrics/mocks/reporter.go
@mockgen github.com/topfreegames/pitaya/v2/metrics Client | sed 's/mock_metrics/mocks/' > metrics/mocks/statsd_reporter.go
serializer-mock:
@mockgen github.com/topfreegames/pitaya/v2/serialize Serializer | sed 's/mock_serialize/mocks/' > serialize/mocks/serializer.go
acceptor-mock:
@mockgen github.com/topfreegames/pitaya/v2/acceptor PlayerConn,Acceptor | sed 's/mock_acceptor/mocks/' > mocks/acceptor.go
message-mock:
@mockgen github.com/topfreegames/pitaya/v2/conn/message Encoder | sed 's/mock_message/mocks/' > conn/message/mocks/message_encoder.go
protos-client-mock:
@mockgen github.com/topfreegames/pitaya/v2/protos PitayaClient,PitayaServer | sed 's/mock_protos/mocks/' > protos/mocks/pitaya.go
cluster-mock:
@mockgen -source=cluster/cluster.go | sed 's/mock_cluster/mocks/' > cluster/mocks/cluster.go
discovery-mock:
@mockgen -source=cluster/service_discovery.go | sed 's/mock_cluster/mocks/' > cluster/mocks/service_discovery.go
build-dev-image:
@docker build . -f dev.Dockerfile -t pitaya-dev:latest --build-arg GOPROXY=https://goproxy.io,direct --build-arg GOPRIVATE=git.mycompany.com,github.com/my/private
ensure-dev-image-exists:
@docker images | grep pitaya-dev || make build-dev-image
test-many-clients-in-container:ensure-dev-image-exists
@docker run pitaya-dev go test -v benchmark/benchmark_test.go -bench=CreateManyClients -benchmem -benchtime=50x