forked from yeti-switch/yeti-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
255 lines (203 loc) · 6.84 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
SHELL := /bin/sh
pkg_name := yeti-web
user := yeti-web
app_dir := /opt/$(user)
version_file := version.yml
app_files := bin \
app \
.bundle \
config \
config.ru \
db \
doc \
Gemfile \
Gemfile.lock \
lib \
public \
Rakefile \
vendor \
pgq-processors \
$(version_file)
exclude_files := config/database.yml \
config/yeti_web.yml \
*.o \
*.a
version = $(shell dpkg-parsechangelog --help | grep -q '\--show-field' \
&& dpkg-parsechangelog --show-field version \
|| dpkg-parsechangelog | grep Version | awk '{ print $$2; }')
commit = $(shell git rev-parse HEAD)
debian_host_release != lsb_release -sc
export DEBFULLNAME ?= YETI team
export DEBEMAIL ?= [email protected]
gems := $(CURDIR)/vendor/bundler
bundle_bin := $(gems)/bin/bundle
bundler_gems := $(CURDIR)/vendor/bundle
export GEM_PATH := $(gems):$(bundler_gems)
debuild_env := http_proxy \
https_proxy \
SSH_AUTH_SOCK \
TRAVIS_* \
CI_* \
GITLAB_* \
YETI_DB_HOST \
YETI_DB_PORT \
CDR_DB_HOST \
CDR_DB_PORT
debuild_flags := $(foreach e,$(debuild_env),-e '$e') $(if $(findstring yes,$(lintian)),--lintian,--no-lintian)
export no_proxy := 127.0.0.1,localhost
pgq_drop_roles := DROP ROLE IF EXISTS pgq_reader; \
DROP ROLE IF EXISTS pgq_writer; \
DROP ROLE IF EXISTS pgq_admin;
pgq_create_roles := CREATE ROLE pgq_reader; \
CREATE ROLE pgq_writer; \
CREATE ROLE pgq_admin in role pgq_reader,pgq_writer;
define info
@printf '\n\e[33m> msg \e[0m\n\n'
endef
###### Rules ######
.PHONY: all
all: docs assets pgq-processors-gems swagger
debian/changelog:
$(info:msg=Generating changelog)
changelog-gen -p "$(pkg_name)" -d "$(debian_host_release)" -A "s/_/~/g" "s/-master/~master/" "s/-rc/~rc/"
version.yml: debian/changelog
$(info:msg=Create version file (version: $(version), commit: $(commit)))
@echo "version: $(version)" > $@
@echo "commit: $(commit)" >> $@
config/database.yml:
$(info:msg=Creating database.yml for build/tests)
cp config/database.build.yml config/database.yml
config/yeti_web.yml:
$(info:msg=Creating yeti_web.yml for build/tests)
@# explicitly raise error during tests if policy is misconfigured
sed -E 's/( +when_no_(config|policy_class): *)(.*)/\1raise/' \
config/yeti_web.yml.ci > config/yeti_web.yml
config/policy_roles.yml:
$(info:msg=Creating policy_roles.yml for build/tests)
cp config/policy_roles.yml.distr config/policy_roles.yml
.PHONY: bundler
bundler:
$(info:msg=Install bundler)
gem install --no-document --install-dir $(gems) bundler -v 2.1.4
.PHONY: gems
gems: bundler
$(info:msg=Install/Update gems)
$(bundle_bin) config --delete with
$(bundle_bin) config set without 'development test'
$(bundle_bin) config set deployment 'true'
$(bundle_bin) install --jobs=4
$(bundle_bin) clean
.PHONY: gems-test
gems-test: bundler
$(info:msg=Install/Update gems for tests)
$(bundle_bin) config set with 'development test'
$(bundle_bin) config set deployment 'true'
$(bundle_bin) install --jobs=4
$(bundle_bin) clean
$(bundle_bin) binstubs rspec-core
.PHONY: docs
docs: gems-test config/database.yml config/yeti_web.yml config/policy_roles.yml
$(info:msg=Preparing test database for docs generation)
RAILS_ENV=test $(bundle_bin) exec rake \
db:drop \
db:create \
db:schema:load \
db:migrate \
db:seed
$(info:msg=Generating documentation)
RAILS_ENV=test $(bundle_bin) exec rake docs:generate
RAILS_ENV=test $(bundle_bin) exec rake db:drop
.PHONY: assets
assets: gems config/database.yml config/yeti_web.yml config/policy_roles.yml
$(info:msg=Precompile assets)
RAILS_ENV=production $(bundle_bin) exec rake assets:precompile
.PHONY: pgq-processors-gems
pgq-processors-gems:
$(info:msg=call pgq-processors processing)
$(MAKE) -C pgq-processors
.PHONY: swagger
swagger: debian/changelog
$(info:msg=call swagger processing)
$(MAKE) -C swagger version=${version}
.PHONY: prepare-test-db
prepare-test-db: gems-test config/database.yml config/yeti_web.yml config/policy_roles.yml
$(info:msg=Preparing test database)
RAILS_ENV=test $(bundle_bin) exec rake parallel:drop
@# avoid race condition when createing pgq roles in parallel with
@# parallel:spec
@# https://github.com/pgq/pgq/blob/master/functions/pgq.upgrade_schema.sql
psql -h db -U postgres -c '$(pgq_drop_roles)'
psql -h db -U postgres -c '$(pgq_create_roles)'
RAILS_ENV=test $(bundle_bin) exec rake parallel:create
RAILS_ENV=test $(bundle_bin) exec rake parallel:load_schema
RAILS_ENV=test $(bundle_bin) exec rake parallel:rake[db:seed]
.PHONY: test
test: test-pgq-processors lint rspec
.PHONY: rspec
rspec: gems-test config/database.yml config/yeti_web.yml config/policy_roles.yml prepare-test-db
ifdef spec
$(info:msg=Testing spec $(spec))
RAILS_ENV=test $(bundle_bin) exec rspec "$(spec)"
else
$(info:msg=Running rspec tests)
RAILS_ENV=test $(bundle_bin) exec parallel_test \
spec/ \
--type rspec \
$(if $(TEST_GROUP),--only-group $(TEST_GROUP),) \
&& script/format_runtime_log log/parallel_runtime_rspec.log \
|| { script/format_runtime_log log/parallel_runtime_rspec.log; false; }
endif
.PHONY: lint
lint: gems-test config/database.yml config/yeti_web.yml
$(info:msg=Running rubocop and bundle audit)
RAILS_ENV=test $(bundle_bin) exec rubocop -P
RAILS_ENV=test $(bundle_bin) exec rake bundle:audit
.PHONY: test-pgq-processors
test-pgq-processors: config/database.yml config/yeti_web.yml config/policy_roles.yml
$(info:msg=Preparing test database for pgq-processors)
@# PGQ_PROCESSORS_TEST is used in database_build.yml to setup separate db
@# to not interfere with main test suite when running make tasks in parallel
RAILS_ENV=test PGQ_PROCESSORS_TEST=true $(bundle_bin) exec rake \
db:drop \
db:create \
db:schema:load \
db:migrate \
db:seed
$(info:msg=Run pgq-processors tests)
$(MAKE) -C pgq-processors test
RAILS_ENV=test PGQ_PROCESSORS_TEST=true $(bundle_bin) exec rake db:drop
.PHONY: install
install: $(app_files)
$(info:msg=install app files)
@mkdir -p $(DESTDIR)$(app_dir)
tar -c --no-auto-compress $(addprefix --exclude , $(exclude_files)) $^ | tar -x -C $(DESTDIR)$(app_dir)
@mkdir -v -p $(addprefix $(DESTDIR)$(app_dir)/, log tmp )
$(info:msg=install swagger specs)
@$(MAKE) -C swagger install DESTDIR=$(DESTDIR)$(app_dir)/public version=$(version)
@install -v -m0644 -D debian/$(pkg_name).rsyslog $(DESTDIR)/etc/rsyslog.d/$(pkg_name).conf
@install -v -m0644 -d $(DESTDIR)/var/log/yeti
.PHONY: clean
clean:
$(info:msg=Cleaning)
$(MAKE) -C swagger clean
$(MAKE) -C pgq-processors clean
rm -rf public/assets \
.bundle \
doc/api
rm -fv config/database.yml \
config/yeti_web.yml \
config/policy_roles.yml
rm -fv bin/rspec
.PHONY: clean-all
clean-all:
$(info:msg=Cleaning everything)
-@debian/rules clean
rm -rf $(gems)
rm -rf $(bundler_gems)
rm -rf .bundle
rm -f $(version_file)
rm -f debian/changelog
.PHONY: package
package: debian/changelog
$(info:msg=Building package)
debuild $(debuild_flags) -uc -us -b