forked from debiki/talkyard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
516 lines (391 loc) · 15.1 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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# GNU Make tips:
# Variables:
# $@ The file name of the target of the rule
# E.g. make watch what=target
watch:
while true; do \
make $(what); \
inotifywait -qre close_write . ; \
done
.PHONY: \
clean \
dev-images \
prod-images \
build \
up \
down \
dead \
prod_asset_bundles \
prod_asset_bundle_files \
debug_asset_bundles \
debug_asset_bundles_files \
git-subm-init-upd \
node_modules \
play-cli
.DEFAULT_GOAL := print_help
print_help:
@echo
@echo "This is Talkyard's Makefile."
@echo
@echo "(How do you debug a Makefile, when it does weird things?"
@echo "Like so: make -nd the_target e.g.: make -nd up"
@echo "And to show only interesting things like commands: (not indented)"
@echo "make -nd debug_asset_bundles | grep -v 'older than' | egrep -i -C2 '^[^ ]|newer than|does not exist|must remake'"
@echo ")"
@echo
@echo "Usage:"
@echo
@echo "Building production images"
@echo "--------------------------"
@echo
@echo "Edit version.txt and commit. Edit DOCKER_REPOSITORY in .env."
@echo "Then:"
@echo
@echo " Build production images: make prod-images"
@echo " Push to your repo: make tag-and-push-latest-images"
@echo
@echo "Running a development server"
@echo "--------------------------"
@echo
@echo " Start a dev server: make up"
@echo " Stop the dev server: make dead"
@echo " View logs: make logs"
@echo
@echo " Open PostgreSQL prompt: make db-cli"
@echo
@echo " Start a Scala CLI: make dead-app ; make play-cli"
@echo
@echo "Running tests"
@echo "--------------------------"
@echo
@echo "End-to-End tests:"
@echo " Start Talkyard: make up
@echo " Start Selenium: d/selenium chrome"
@echo " Run the tests: s/run-e2e-tests # or: d/n s/run-e2e-tests ?"
@echo " Stop Selenium: d/selenium kill"
@echo
@echo "Unit tests:"
@echo " Stop the app server: make dead-app"
@echo " Start a Scala CLI: make play-cli"
@echo " Run tests: test # in the CLI"
@echo
@echo "What more do you want to know? Talk with us at"
@echo "https://www.talkyard.io/forum/."
@echo
DOCKER_REPOSITORY := \
$(shell sed -nr 's/DOCKER_REPOSITORY=([a-zA-Z0-9\._-]*).*/\1/p' .env)
TALKYARD_VERSION := \
$(shell cat version.txt)
define ask_for_root_password
sudo echo
endef
# ----- Git submodules
# This'll be all Git submodule directories. If some are missing, need to git-clone them.
git_modules := \
$(shell grep submodule .gitmodules | egrep -v '^ *\#' | sed -r 's/^.submodule "([^"]+).*$$/\1\/.git/')
git-subm-init-upd: $(git_modules)
$(git_modules): $@
git submodule update --init
# ----- Javascript and CSS bundles
# If these are present, probably all js modules have been installed?
node_modules: \
node_modules/.bin/gulp
#node_modules/react/umd/react.development.js \
#node_modules/zxcvbn/dist/zxcvbn.js
node_modules/.bin/gulp: git-subm-init-upd
s/yarn
# BUG RISK sync with Gulp so won't accidentally forget to (re)build? [GZPATHS]
# Sync with the languages in the /translations/ dir. [5JUKQR2]
# public/res/2d-bundle.min.js.gz // [SLIMTYPE]
prod_asset_bundle_files:=\
images/web/assets/talkyard-comments.min.js.gz \
images/web/assets/talkyard-service-worker.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/editor-bundle.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/more-bundle.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/slim-bundle.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/staff-bundle.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/styles-bundle.min.css.gz \
images/web/assets/$(TALKYARD_VERSION)/styles-bundle.rtl.css.gz \
images/web/assets/$(TALKYARD_VERSION)/styles-bundle.rtl.min.css.gz \
images/web/assets/$(TALKYARD_VERSION)/zxcvbn.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/en_US/i18n.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/en_US/i18n.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/es_CL/i18n.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/es_CL/i18n.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/he_IL/i18n.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/he_IL/i18n.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/lv_LV/i18n.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/lv_LV/i18n.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/pl_PL/i18n.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/pl_PL/i18n.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/pt_BR/i18n.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/pt_BR/i18n.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/ru_RU/i18n.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/ru_RU/i18n.min.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/sv_SE/i18n.js.gz \
images/web/assets/$(TALKYARD_VERSION)/translations/sv_SE/i18n.min.js.gz \
images/app/assets/server-bundle.min.js \
images/app/assets/translations/en_US/i18n.js \
images/app/assets/translations/en_US/i18n.min.js \
images/app/assets/translations/es_CL/i18n.js \
images/app/assets/translations/es_CL/i18n.min.js \
images/app/assets/translations/he_IL/i18n.js \
images/app/assets/translations/he_IL/i18n.min.js \
images/app/assets/translations/pl_PL/i18n.js \
images/app/assets/translations/pl_PL/i18n.min.js
# Sync this task name w e2e test [MKBUNDLS].
prod_asset_bundles: node_modules debug_asset_bundles $(prod_asset_bundle_files)
$(prod_asset_bundle_files): $@
s/d-gulp build_release_dont_clean_before
# Use .js.gz, because .js files get deleted (aren't needed). [UNCOMPRAST]
# Except for the server bundle — it loads non-gz scripts.
debug_asset_bundles_files: \
images/app/assets/server-bundle.js \
images/web/assets/talkyard-comments.js.gz \
images/web/assets/talkyard-service-worker.js.gz \
images/web/assets/$(TALKYARD_VERSION)/editor-bundle.js.gz \
images/web/assets/$(TALKYARD_VERSION)/more-bundle.js.gz \
images/web/assets/$(TALKYARD_VERSION)/slim-bundle.js.gz \
images/web/assets/$(TALKYARD_VERSION)/staff-bundle.js.gz \
images/web/assets/$(TALKYARD_VERSION)/zxcvbn.js.gz \
images/web/assets/$(TALKYARD_VERSION)/styles-bundle.css.gz
images/app/assets/server-bundle.js: \
$(shell find client/server/ -type f \( -name '*.ts' -o -name '*.js' \))
@echo "Regenerating $@"
s/d-gulp compileServerTypescriptConcatJavascript
images/web/assets/talkyard-comments.js.gz: \
$(shell find client/embedded-comments/ -type f \( -name '*.ts' -o -name '*.js' \))
@echo "Regenerating $@"
s/d-gulp compileBlogCommentsTypescript-concatScripts
images/web/assets/talkyard-service-worker.js.gz: \
$(shell find client/serviceworker/ -type f \( -name '*.ts' -o -name '*.js' \))
@echo "Regenerating $@"
s/d-gulp compileSwTypescript-concatScripts
images/web/assets/$(TALKYARD_VERSION)/editor-bundle.js.gz: \
$(shell find client/app-editor/ -type f \( -name '*.ts' -o -name '*.js' \))
@echo "Regenerating $@"
s/d-gulp compileEditorTypescript-concatScripts
images/web/assets/$(TALKYARD_VERSION)/more-bundle.js.gz: \
$(shell find client/app-more/ -type f \( -name '*.ts' -o -name '*.js' \))
@echo "Regenerating $@"
s/d-gulp compileMoreTypescript-concatScripts
images/web/assets/$(TALKYARD_VERSION)/slim-bundle.js.gz: \
$(shell find client/app-slim/ -type f \( -name '*.ts' -o -name '*.js' \))
@echo "Regenerating $@"
s/d-gulp compileSlimTypescript-concatScripts
images/web/assets/$(TALKYARD_VERSION)/staff-bundle.js.gz: \
$(shell find client/app-staff/ -type f \( -name '*.ts' -o -name '*.js' \))
@echo "Regenerating $@"
s/d-gulp compileStaffTypescript-concatScripts
images/web/assets/$(TALKYARD_VERSION)/zxcvbn.js.gz: \
node_modules/zxcvbn/dist/zxcvbn.js
@echo "Bundling $@"
s/d-gulp bundleZxcvbn
images/web/assets/$(TALKYARD_VERSION)/styles-bundle.css.gz: \
$(shell find client/ -type f \( -name '*.styl' -o -name '*.css' \) )
@echo "Regenerating $@"
s/d-gulp compile-stylus
debug_asset_bundles: debug_asset_bundles_files
# ----- To-Talkyard Javascript
to-talkyard: to-talkyard/dist/to-talkyard/src/to-talkyard.js
to-talkyard/dist/to-talkyard/src/to-talkyard.js: $(shell find to-talkyard/src/)
@echo "Building To-Talkyard ..."
@cd to-talkyard ;\
set -x ;\
yarn ;\
yarn build
@echo "... Done building To-Talkyard."
# ----- Clean (wip)
clean_bundles:
@echo Delting script and style bundles:
s/d-gulp clean
clean: clean_bundles
@# target/ sometimes includes files compilation-created and owned by root.
@echo Delting Scala things and other things:
@$(call ask_for_root_password)
sudo rm -fr target/
rm -fr project/target/
rm -fr project/project/
rm -fr logs/
rm -f ensime-langserver.log
rm -f chromedriver.log
pristine: clean
@echo
@echo "If you want to, also delete Docker volumes, your local config,"
@echo "the SBT and Node.js cache, and IDE project files,"
@echo "by copy-pasting (some of) this:"
@echo
@echo " sudo rm -rf volumes/"
@echo
@echo " rm -fr conf/my.conf"
@echo
@echo " rm -fr .idea"
@echo " rm -fr .ensime"
@echo " rm -fr .ensime_cache/"
@echo
@echo " rm -fr node_modules/"
@echo " rm -fr modules/*/node_modules/"
@echo
@echo " rm -fr images/app/typesafe-activator"
@echo
@echo " No, old, now in vendors/jars/:"
@echo " rm -fr ~/.ivy2"
@echo " rm -fr ~/.sbt"
@echo
@echo
# ----- Development
build:
@echo "Build what, dev or prod images? Do one of these:"
@echo " make dev-images"
@echo " make prod-images"
# Copy to inside the Docker build context, so Docker can access it. [ACTVTRJAR]
# Use rsync so will update any old but different files with the same name.
_copy_typesafe_activator:
@rsync --delete --recursive vendors/jars/typesafe-activator images/app/
# (About prod_asset_bundles: What was the reason the prod bundles are needed here?
# It's that the app server wants minified translation files? — see play-cli below)
dev-images: prod_asset_bundles _copy_typesafe_activator
s/d build
# Starts an SBT shell where you can run unit tests by typing 'test'. These test require
# the minified asset bundles, to run (because the app server loads and execs React Javascript
# server side.)
play-cli: prod_asset_bundles _copy_typesafe_activator dead-app
s/d-cli
db-cli:
@# Find out which database is currently being used, by looking at my.conf.
@# Because I sometimes connect as the wrong user, and feel confused for quite a while.
@def_user=`sed -nr 's/^talkyard.postgresql.user="([a-zA-Z0-9\._-]+)".*/\1/p' conf/my.conf` ;\
def_user="$${def_user:-talkyard}" ;\
read -p "Connect to the PostgreSQL database as which user? [$$def_user] " db_user ;\
db_user="$${db_user:-$$def_user}" ;\
s/d-psql "$$db_user" "$$db_user"
up: prod_asset_bundles _copy_typesafe_activator
s/d up -d
@echo
@echo "Started. Now, tailing logs..."
@echo
@s/d-logsf0
log: tail
logs: tail
tails: tail
tail:
s/d-logsf0
restart: prod_asset_bundles
s/d-restart
restart-web:
s/d kill web ; s/d start web ; s/d-logsf0
recreate-web:
s/d kill web ; s/d rm -f web ; s/d up -d web ; s/d-logsf0
rebuild-restart-web:
s/d kill web ; s/d rm -f web ; s/d build web ; s/d up -d web ; s/d-logsf0
rebuild-gulp:
s/d kill gulp ; s/d rm -f gulp ; s/d build gulp
rebuild-restart-gulp: rebuild-gulp
s/d up -d gulp ; s/d-logsf0 gulp
restart-gulp:
s/d kill gulp ; s/d start gulp ; s/d-logsf0
restart-app: prod_asset_bundles
s/d kill app ; s/d start app ; s/d-logsf0
recreate-app: _copy_typesafe_activator prod_asset_bundles
s/d kill app ; s/d rm -f app ; s/d up -d app ; s/d-logsf0
rebuild-app: _copy_typesafe_activator prod_asset_bundles
s/d kill app ; s/d rm -f app ; s/d build app
rebuild-restart-app: rebuild-app
s/d up -d app ; s/d-logsf0
dead-app:
s/d kill web app
restart-web-app: prod_asset_bundles
s/d-restart-web-app
down: dead
s/d down
dead:
@# Kill the ones who are slow to stop.
s/d kill app search gulp ; s/d stop
# Prod images
# ========================================
# Any old lingering prod build project, causes netw pool ip addr overlap error.
_kill_old_prod_build_project:
s/d -pedt kill web app search cache rdb ;\
s/d -pedt down
prod-images: _kill_old_prod_build_project _copy_typesafe_activator
@# This cleans and builds prod_asset_bundles. [PRODBNDLS]
s/build-prod-images.sh
tag-and-push-latest-images: \
tag-latest-images push-tagged-images _print_push_git_tag_command
tag-latest-images:
@$(call die_unless_tag_specified, Tag with)
@$(call ask_for_root_password)
set -e ;\
REPO=$(DOCKER_REPOSITORY) ;\
sudo docker tag $$REPO/talkyard-app $$REPO/talkyard-app:$(tag) ;\
sudo docker tag $$REPO/talkyard-web $$REPO/talkyard-web:$(tag) ;\
sudo docker tag $$REPO/talkyard-rdb $$REPO/talkyard-rdb:$(tag) ;\
sudo docker tag $$REPO/talkyard-cache $$REPO/talkyard-cache:$(tag) ;\
sudo docker tag $$REPO/talkyard-search $$REPO/talkyard-search:$(tag) ;\
sudo docker tag $$REPO/talkyard-certgen $$REPO/talkyard-certgen:$(tag)
@echo
push-tagged-images:
@$(call die_unless_tag_specified, Push)
@$(call ask_for_root_password)
set -e ;\
REPO=$(DOCKER_REPOSITORY) ;\
sudo docker push $$REPO/talkyard-app:$(tag) ;\
sudo docker push $$REPO/talkyard-web:$(tag) ;\
sudo docker push $$REPO/talkyard-rdb:$(tag) ;\
sudo docker push $$REPO/talkyard-cache:$(tag) ;\
sudo docker push $$REPO/talkyard-search:$(tag) ;\
sudo docker push $$REPO/talkyard-certgen:$(tag)
@echo
_print_push_git_tag_command:
@echo "Next:"
@echo ""
@echo " make push-tag-to-git tag=$(tag)"
@echo ""
push-tag-to-git:
@$(call die_unless_tag_specified, Push) ;\
@echo
@echo "Publishing version tag $(tag) to GitHub..."
@set -e ;\
cd modules/ed-versions/ ;\
git fetch ;\
git checkout master ;\
git merge --ff-only origin/master ;\
echo $(tag) >> version-tags.log ;\
git add version-tags.log ;\
git commit -m "Add $(tag)." ;\
git push origin master
@echo ""
@echo "Tagging the current Git revision with $(tag) ..."
@git tag $(tag)
@git push origin $(tag)
@echo ""
@echo "Done. Now, bump the version number:"
@echo ""
@echo " s/bump-versions.sh"
@echo ""
define die_unless_tag_specified
if [ -z "$(tag)" ]; then \
echo ;\
echo "Error: $(1) which Docker image tag? Specify tag=... please." ;\
echo ;\
exit 1 ;\
fi
endef
# ----- Maybe read (again)?
#https://gist.github.com/mpneuried/0594963ad38e68917ef189b4e6a269db
# DOCKER_REPO=...
# http://datakurre.pandala.org/2016/04/evolution-of-our-makefile-for-docker.html
# capture test exit status code: ... see blog post
# https://serversforhackers.com/c/dckr-dev-workflow — log messages
# maybe read:
# http://aegis.sourceforge.net/auug97.pdf
# has read:
# https://serversforhackers.com/c/dckr-dev-workflow
# probably well constructed:
# https://github.com/PistonDevelopers/rust-empty/blob/master/Makefile
# https://github.com/git/git/blob/master/Makefile
# Bazel? No? Then everyone incl I need to spend time learning how it works:
# https://github.com/bazelbuild/rules_k8s and need to install Java.
# looks nice:
# https://github.com/casey/just
# vim: list ts=4 sw=4 tw=0 fo=r