-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
235 lines (184 loc) · 6.86 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
234
235
# khan
# https://github.com/topfreegames/khan
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright © 2016 Top Free Games <[email protected]>
.PHONY: db
GODIRS = $(shell go list ./... | grep -v /vendor/ | sed [email protected]/topfreegames/khan@.@g | egrep -v "^[.]$$")
PMD = "pmd-bin-5.3.3"
OS = "$(shell uname | awk '{ print tolower($$0) }')"
MYIP=`ifconfig | grep --color=none -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep --color=none -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n 1`
setup-hooks:
@cd .git/hooks && ln -sf ../../hooks/pre-commit.sh pre-commit
setup: mod-download
@go get -u github.com/onsi/ginkgo/ginkgo
@go get -u github.com/jteeuwen/go-bindata/...
@go get github.com/mailru/easyjson/...
mod-download:
@go mod download
setup-docs:
@pip install -q --log /tmp/pip.log --no-cache-dir sphinx recommonmark sphinx_rtd_theme
setup-ci:
@go get github.com/mailru/easyjson/...
@go get -u github.com/jteeuwen/go-bindata
@go get -u github.com/jteeuwen/go-bindata/...
@go get github.com/topfreegames/goose/cmd/goose
@go get github.com/mattn/goveralls
@go get github.com/onsi/ginkgo/ginkgo
@go mod tidy
build:
@go build -o ./bin/khan main.go
assets:
@for pkg in $(GODIRS) ; do \
go generate -x $$pkg ; \
done
start-deps: stop-deps
@cd ./scripts && docker-compose --project-name=khan up -d
@until docker exec khan_postgres_1 pg_isready; do echo 'Waiting for Postgres...' && sleep 1; done
@until docker exec khan_elasticsearch_1 curl localhost:9200; do echo 'Waiting for Elasticsearch...' && sleep 1; done
@sleep 5
@curl -XPUT 'http://localhost:9200/khan-test/' -d '{ "settings" : { "index" : { "number_of_shards" : 1, "number_of_replicas" : 1 } } }'
@sleep 5
@curl -XPUT 'http://localhost:9200/khan-test/test/1' -d '{"user" : "whatever"}'
@sleep 5
@docker exec khan_postgres_1 createuser -s -U postgres khan; true
@docker exec khan_postgres_1 createdb -U khan khan; true
@make migrate
stop-deps:
@cd ./scripts && docker-compose --project-name=khan stop
@cd ./scripts && docker-compose --project-name=khan rm -f
cross: assets
@mkdir -p ./bin
@echo "Building for linux-i386..."
@env GOOS=linux GOARCH=386 go build -o ./bin/khan-linux-i386
@echo "Building for linux-x86_64..."
@env GOOS=linux GOARCH=amd64 go build -o ./bin/khan-linux-x86_64
@echo "Building for darwin-x86_64..."
@env GOOS=darwin GOARCH=amd64 go build -o ./bin/khan-darwin-x86_64
@chmod +x bin/*
install:
@go install
run-verbose:
@go run main.go start -d -c ./config/local.yaml
run:
@echo "Khan running at http://localhost:8888/"
@go run main.go start -c ./config/local.yaml
worker:
@echo "Khan Worker running at http://localhost:9999/"
@go run main.go worker -d -c ./config/local.yaml
run-fast:
@go run main.go start --fast -c ./config/local.yaml
build-docker:
@docker build -t khan .
# the crypto
run-docker:
@docker run -i -t --rm \
-e "KHAN_POSTGRES_HOST=${MYIP}" \
-e "KHAN_POSTGRES_PORT=5433" \
-e "KHAN_ELASTICSEARCH_HOST=${MYIP}" \
-e "KHAN_ELASTICSEARCH_PORT=9200" \
-e "SERVER_NAME=localhost" \
-e "AUTH_USERNAME=auth-username" \
-e "AUTH_PASSWORD=auth-password" \
-p 8080:80 \
khan start -p 80 --fast
run-worker-docker:
@docker run -i -t --rm \
-e "KHAN_POSTGRES_HOST=${MYIP}" \
-e "KHAN_POSTGRES_PORT=5433" \
-e "KHAN_ELASTICSEARCH_HOST=${MYIP}" \
-e "KHAN_ELASTICSEARCH_PORT=9200" \
-e "KHAN_RUN_WORKER=true" \
-e "SERVER_NAME=localhost" \
-e "AUTH_USERNAME=auth-username" \
-e "AUTH_PASSWORD=auth-password" \
-p 9999:80 \
khan worker -p 80 --fast
run-prune-docker:
@docker run -i -t --rm \
-e "KHAN_POSTGRES_HOST=${MYIP}" \
-e "KHAN_POSTGRES_PORT=5433" \
-e "KHAN_PRUNING_SLEEP=10" \
khan prune
test: start-test-deps run-test
start-test-deps: schema-update start-deps assets drop-test create-test-db migrate-test
run-test:
@SKIP_ELASTIC_LOG=true ginkgo -nodes=1 -r --cover .
coverage:
@echo "mode: count" > coverage-all.out
@bash -c 'for f in $$(find . -name "*.coverprofile"); do tail -n +2 $$f >> coverage-all.out; done'
test-coverage: test coverage
test-coverage-html coverage-html: test-coverage
@go tool cover -html=coverage-all.out
random-data:
@go run perf/main.go -games 5 -pwc 100 -cpg 10 -use-main
drop:
@psql -d postgres -U postgres -p 5433 -h ${MYIP} -f db/drop.sql > /dev/null
@echo "Database dropped successfully!"
db migrate:
@go run main.go migrate -c ./config/local.yaml
db-test migrate-test:
@go run main.go migrate -c ./config/test.yaml
@go run main.go migrate -t 0 -c ./config/test.yaml
@go run main.go migrate -c ./config/test.yaml
create-test-db:
@psql -d postgres -h localhost -p 5433 -U postgres -f db/create-test.sql > /dev/null
@echo "Test database created successfully!"
drop-test:
@-psql -d postgres -h localhost -p 5433 -U postgres -c "SELECT pg_terminate_backend(pid.pid) FROM pg_stat_activity, (SELECT pid FROM pg_stat_activity where pid <> pg_backend_pid()) pid WHERE datname='khan_test';"
@psql -d postgres -h localhost -p 5433 -U postgres -f db/drop-test.sql > /dev/null
@echo "Test database dropped successfully!"
run-test-khan: build
@rm -rf /tmp/khan-bench.log
@./bin/khan start -p 8888 -q --fast -c ./config/perf.yaml 2>&1 > /tmp/khan-bench.log &
kill-test-khan:
@-ps aux | egrep './bin/khan.+perf.yaml' | egrep -v grep | awk ' { print $$2 } ' | xargs kill -9
ci-perf: migrate-perf run-test-khan run-perf
run-perf:
@go test -bench . -benchtime 3s ./bench/...
db-perf:
@go run perf/main.go
restore-perf:
@psql -d postgres -h localhost -p 5433 -U postgres khan_perf < khan-perf.dump
dump-perf:
@pg_dump khan_perf > khan-perf.dump
create-perf-db:
@psql -d postgres -h localhost -p 5433 -U postgres -f db/create-perf.sql > /dev/null
@echo "Perf database created successfully!"
drop-perf:
@psql -d postgres -h localhost -p 5433 -U postgres -f db/drop-perf.sql > /dev/null
@echo "Perf database created successfully!"
migrate-perf:
@go run main.go migrate -c ./config/perf.yaml
static:
@-gocyclo -over 5 . | egrep -v vendor/
@for pkg in $$(go list ./... | grep -v /vendor/ | grep -v "/db") ; do \
golint $$pkg ; \
done
@#ineffassign
@for pkg in $(GODIRS) ; do \
ineffassign $$pkg ; \
done
@${MAKE} pmd
pmd:
@bash pmd.sh
@for pkg in $(GODIRS) ; do \
exclude=$$(find $$pkg -name '*_test.go') && \
/tmp/pmd-bin-5.4.2/bin/run.sh cpd --minimum-tokens 30 --files $$pkg --exclude $$exclude --language go ; \
done
pmd-full:
@bash pmd.sh
@for pkg in $(GODIRS) ; do \
/tmp/pmd-bin-5.4.2/bin/run.sh cpd --minimum-tokens 30 --files $$pkg --language go ; \
done
rtfd:
@rm -rf docs/_build
@sphinx-build -b html -d ./docs/_build/doctrees ./docs/ docs/_build/html
@open docs/_build/html/index.html
schema-update: schema-clean
@go generate ./models/*.go
@go generate ./api/payload.go
schema-clean:
@rm -rf ./models/*easyjson.go
mock-lib:
@mockgen github.com/topfreegames/khan/lib KhanInterface | sed 's/mock_lib/mocks/' > lib/mocks/khan.go