-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
357 lines (294 loc) · 9.34 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
.PHONY: all .FORCE
.DEFAULT_GOAL := all
include Makefile.inc
include Makefile.versions
# Build daemon
define gen-gobuild
swy-$(1): $$(go-$(1)-y) .FORCE
$$(call msg-gen,$$@)
$$(Q) $$(GO) $$(GO-BUILD-OPTS) -o $$@ $$(go-$(1)-y)
all-y += swy-$(1)
endef
# Build service daemon
define gen-gobuild-daemon-n
src/$(1)/version.go: .FORCE
$$(call msg-gen, $$@)
$$(Q) echo '// Autogenerated' > $$@
$$(Q) echo 'package main' >> $$@
$$(Q) echo 'var Version string = "$(GITID)"' >> $$@
$$(Q) echo 'var Flavor string = "$(FLAVOR)"' >> $$@
swy-$(2): .FORCE src/$(1)/version.go
$$(call msg-gen,$$@)
$$(Q) cd src/$(1)/ && $$(GO-BUILD)
$$(Q) $$(MV) src/$(1)/$$(shell basename $(1)) $$@
all-y += swy-$(2)
endef
define gen-gobuild-daemon
$(eval $(call gen-gobuild-daemon-n,$(1),$(1)))
endef
TOOL_BINS =
# Build tool
define gen-gobuild-tool
TOOL_BINS += swy$(1)
swy$(1): $$(go-$(1)-y) .FORCE
$$(call msg-gen,$$@)
$$(Q) $$(GO-BUILD) -o $$@ $$(go-$(1)-y)
all-y += swy$(1)
endef
go-pgrest-y += src/pgrest/main.go
go-mquotad-y += src/mquotad/main.go
TOLVER = src/tools/version.go
$(TOLVER): .FORCE
$(call msg-gen, $@)
$(Q) echo '// Autogenerated' > $@
$(Q) echo 'package main' >> $@
$(Q) echo 'var Version string = "$(GITID)"' >> $@
go-ctl-y += src/tools/ctl.go $(TOLVER)
go-trace-y += src/tools/tracer.go
go-s3fsck-y += src/tools/s3-fsck.go
go-sg-y += src/tools/sg.go
go-runtest-y += src/tools/runner-tester.go
#$(eval $(call gen-gobuild,pgrest))
#$(eval $(call gen-gobuild,mquotad))
#
# Docker lang images
#
IMAGES =
define gen-pack-lang
IMAGES += swifty/$(1)
swifty/$(1): swy-wdog swy-runner kubectl/docker/wdog/$(1)/Dockerfile
swifty/$(1):
$$(call msg-gen, $$@)
$$(Q) $$(MAKE) -C kubectl/docker/wdog/$(1) image
swifty/$(1)-push:
$$(call msg-gen, $$@)
$$(Q) $$(MAKE) -C kubectl/docker/wdog/$(1) push
.PHONY: swifty/$(1)
endef
swifty/python: src/wdog/runner/runner.py
swifty/golang: src/wdog/runner/runner.go go-sca
swifty/swift: src/wdog/runner/runner.swift
swifty/csharp: src/wdog/runner/runner.cs src/wdog/lib/XStream.dll
swifty/nodejs: src/wdog/runner/runner.js
swifty/ruby: src/wdog/runner/runner.rb
src/wdog/lib/XStream.dll: src/wdog/lib/XStream.cs
$(call msg-gen,$@)
$(Q) $(DOCKER) -v $(CURDIR)/src/wdog/lib/:/mono mono csc /mono/XStream.cs -out:/mono/XStream.dll -target:library -r:Mono.Posix.dll -unsafe
swy-runner: src/wdog/runner/runner.c
$(call msg-gen,$@)
$(Q) $(CC) -Wall -Werror -O2 -static -o $@ $<
go-sca: src/tools/go-sca.go
$(call msg-gen,$@)
go build $<
#
# Services
#
S_IMAGES =
S_BINARIES =
define gen-pack-service-n
swifty/$(1): swy-$(2) kubectl/docker/$(1)/Dockerfile
swifty/$(1):
$$(call msg-gen, $$@)
$$(Q) $$(CP) swy-$(2) kubectl/docker/$(1)/swy-$(2)
$$(Q) $$(MAKE) -C kubectl/docker/$(1) all
.PHONY: swifty/$(1)
endef
define gen-pack-service
S_IMAGES += swifty/$(1)
S_BINARIES += swy-$(1)
$(eval $(call gen-pack-service-n,$(1),$(1)))
endef
swifty/client:
$(call msg-gen $@)
$(Q) $(CP) swyctl kubectl/docker/client/
$(Q) $(MAKE) -C kubectl/docker/client all
#
# Core rules generation
#
SRVCS = gate admd s3
LANGS = python golang swift ruby nodejs csharp
TOOLS = ctl trace s3fsck sg runtest
SCRPR = gate s3
PROXY = mgo maria
# BUILD
$(foreach s,$(SRVCS),$(eval $(call gen-gobuild-daemon,$s)))
$(foreach s,$(SCRPR),$(eval $(call gen-gobuild-daemon-n,scrapers/$s,dbscr-$s)))
$(foreach s,$(PROXY),$(eval $(call gen-gobuild-daemon-n,proxies/$s,proxy-$s)))
$(foreach t,$(TOOLS),$(eval $(call gen-gobuild-tool,$t)))
$(eval $(call gen-gobuild-daemon,wdog))
# Each service has its swifty/$name docker image
$(foreach s,$(SRVCS),$(eval $(call gen-pack-service,$s)))
$(foreach s,$(SCRPR),$(eval $(call gen-pack-service,dbscr-$s)))
# Each lang has its swifty/$lang docker image
$(foreach l,$(LANGS),$(eval $(call gen-pack-lang,$l)))
# Wdog is packed into swifty/proxy image
$(eval $(call gen-pack-service-n,proxy,wdog))
# Default target
all: $(all-y)
images: $(IMAGES)
@true
.PHONY: images
images-push: $(foreach i,$(IMAGES),$(i)-push)
@true
.PHONY: images-push
simages: $(S_IMAGES)
@true
.PHONY: simages
services: $(S_BINARIES)
@true
.PHONY: services
tools: $(TOOL_BINS)
@true
.PHONY: tools
help:
@echo ' Targets:'
@echo ' images - Build all wdog docker images'
@echo ' images-push - Push all wdog docker images'
@echo ' simages - Build add services images'
@echo ' docs - Build documentation'
@echo ' Services ($(SRVCS)):'
@echo ' swy-$$SRV - Build $$SRV binary'
@echo ' swifty/$$SRV - Pack $$SRV image'
@echo ' Tools:'
@echo ' swyctl - Build gate cli'
@echo ' swytrace - Build gate eq tracing tool'
@echo ' swys3fsck - Build s3 databaase integrity checker'
@echo ' swysg - Build secrets generator cli'
@echo ' swydbscr - Build DB scraper tool'
@echo ' swydbscr-s3 - Build S3 DB scraper tool'
@echo ' swyruntest - Build runner tester tool'
@echo ' Languages ($(LANGS)):'
@echo ' swifty/$$LANG - Build $$LANG docker image'
@echo ' Random:'
@echo ' swifty/dbscr - Pack scraper into image'
@echo ' swy-wdog - Build wdog'
.PHONY: help
tags:
$(Q) $(GOTAGS) -R src/ > tags
.PHONY: tags
#docs: .FORCE
# $(Q) $(MAKE) -C docs/ html
#.PHONY: docs
tar:
$(Q) $(GIT) archive --format=tar --prefix=swifty/ HEAD > swifty.tar
.PHONY: tar
gtar:
$(Q) $(GIT) repack -ad
$(Q) $(GIT) gc
$(TAR) -c -C ../ -f ../swifty-git.tar --exclude 'vendor/*' $(shell basename $(CURDIR))
.PHONY: tar
ifneq ($(filter mqclean,$(MAKECMDGOALS)),)
rabbit-users := $(filter-out guest root, $(shell rabbitmqctl list_users | tail -n +2 | cut -f 1))
rabbit-vhosts := $(filter-out /, $(shell rabbitmqctl list_vhosts | tail -n +2 | cut -f 1))
endif
mqclean: .FORCE
$(call msg-gen,"Cleaning up MessageQ")
ifneq ($(rabbit-users),)
$(Q) rabbitmqctl delete_user $(rabbit-users)
endif
ifneq ($(rabbit-vhosts),)
$(Q) rabbitmqctl delete_vhost $(rabbit-vhosts)
endif
.PHONY: mqclean
ifneq ($(filter sqlclean,$(MAKECMDGOALS)),)
mysql-user ?= "root"
mysql-pass ?= "aiNe1sah9ichu1re"
sql-users := $(filter-out root, \
$(shell mysql -u$(mysql-user) -p$(mysql-pass) -N -e'select user from mysql.user' | cut -f1))
sql-dbases := $(filter-out information_schema mysql performance_schema test, \
$(shell mysql -u$(mysql-user) -p$(mysql-pass) -N -e'show databases' | cut -f1))
endif
sqlclean: .FORCE
$(call msg-gen,"Cleaning up SQL")
ifneq ($(sql-users),)
$(foreach user,$(sql-users),$(shell mysql -u$(mysql-user) -p$(mysql-pass) -e'drop user $(user)'))
endif
ifneq ($(sql-dbases),)
$(foreach db,$(sql-dbases),$(shell mysql -u$(mysql-user) -p$(mysql-pass) -e'drop database $(db)'))
endif
.PHONY: sqlclean
DB-SWIFTY := swifty
DB-S3 := swifty-s3
deps:
sh deps.sh
mgo-swifty-creds :=
ifneq ($(mgo-swifty-user),)
ifneq ($(mgo-swifty-pass),)
mgo-swifty-creds := -u $(mgo-swifty-user) -p $(mgo-swifty-pass)
endif
endif
mgo-s3-creds :=
ifneq ($(mgo-s3-user),)
ifneq ($(mgo-s3-pass),)
mgo-s3-creds := -u $(mgo-s3-user) -p $(mgo-s3-pass)
endif
endif
clean-db-swifty:
$(call msg-gen,"Cleaning up main MongoDB")
$(Q) $(MONGO)/$(DB-SWIFTY) $(mgo-swifty-creds) --eval 'db.Function.remove({});'
$(Q) $(MONGO)/$(DB-SWIFTY) $(mgo-swifty-creds) --eval 'db.Mware.remove({});'
$(Q) $(MONGO)/$(DB-SWIFTY) $(mgo-swifty-creds) --eval 'db.FnStats.remove({});'
$(Q) $(MONGO)/$(DB-SWIFTY) $(mgo-swifty-creds) --eval 'db.Pods.remove({});'
$(Q) $(MONGO)/$(DB-SWIFTY) $(mgo-swifty-creds) --eval 'db.Balancer.remove({});'
$(Q) $(MONGO)/$(DB-SWIFTY) $(mgo-swifty-creds) --eval 'db.BalancerRS.remove({});'
$(Q) $(MONGO)/$(DB-SWIFTY) $(mgo-swifty-creds) --eval 'db.Logs.remove({});'
.PHONY: clean-db-swifty
clean-db-s3:
$(call msg-gen,"Cleaning up s3 MongoDB")
$(Q) $(MONGO)/$(DB-S3) $(mgo-s3-creds) --eval 'db.S3Iams.remove({});'
$(Q) $(MONGO)/$(DB-S3) $(mgo-s3-creds) --eval 'db.S3Buckets.remove({});'
$(Q) $(MONGO)/$(DB-S3) $(mgo-s3-creds) --eval 'db.S3Objects.remove({});'
$(Q) $(MONGO)/$(DB-S3) $(mgo-s3-creds) --eval 'db.S3Uploads.remove({});'
$(Q) $(MONGO)/$(DB-S3) $(mgo-s3-creds) --eval 'db.S3ObjectData.remove({});'
$(Q) $(MONGO)/$(DB-S3) $(mgo-s3-creds) --eval 'db.S3AccessKeys.remove({});'
.PHONY: clean-db-s3
rsclean: clean-db-swifty clean-db-s3
$(call msg-gen,"Cleaning up kubernetes")
$(Q) $(KUBECTL) delete deployment --all
$(Q) $(KUBECTL) delete secret --all
#$(Q) $(KUBECTL) delete service --all
$(Q) $(KUBECTL) delete pod --all
$(call msg-gen,"Cleaning up IPVS")
$(Q) $(IPVSADM) -C
$(call msg-gen,"Cleaning up FS")
ifneq ($(wildcard $(LOCAL_SOURCES)/.*),)
$(Q) $(RM) -r $(LOCAL_SOURCES)/*
endif
ifneq ($(wildcard $(VOLUME_DIR)/.*),)
$(Q) $(RM) -r $(VOLUME_DIR)/*
endif
ifneq ($(wildcard $(TEST_REPO)/.*),)
$(Q) $(RM) -r $(TEST_REPO)/*
endif
clean:
$(call msg-clean,swy-gate)
$(Q) $(RM) swy-gate
$(call msg-clean,swy-wdog)
$(Q) $(RM) swy-wdog
$(call msg-clean,swy-admd)
$(Q) $(RM) swy-admd
$(call msg-clean,swy-pgrest)
$(Q) $(RM) swy-pgrest
$(call msg-clean,swy-mquotad)
$(Q) $(RM) swy-mquotad
$(call msg-clean,swy-wdog)
$(Q) $(RM) swy-wdog
$(call msg-clean,swy-s3)
$(Q) $(RM) swy-s3
$(call msg-clean,swyctl)
$(Q) $(RM) swyctl
$(call msg-clean,swytrace)
$(Q) $(RM) swytrace
$(call msg-clean,swydbscr)
$(Q) $(RM) swydbscr
$(call msg-clean,swys3fsck)
$(Q) $(RM) swys3fsck
$(call msg-clean,swysg)
$(Q) $(RM) swysg
# $(Q) $(MAKE) -C docs clean
.PHONY: clean
mrproper: clean
$(call msg-clean,tags)
$(Q) $(RM) tags
.PHONY: mrproper
.SUFFIXES: