-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
220 lines (162 loc) · 5.51 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
# Project-specific configuration
EXECUTABLES = lein docker npm lftp
PORTS=15432 16379 15433 1221 16380 16381 8350 8351 8352 8353
TOOL_VERSIONS := node:8.11 npm:6 lein:2.9
VIRKAILIJA_CONFIG ?= ../ataru-secrets/virkailija-local-dev.edn
HAKIJA_CONFIG ?= ../ataru-secrets/hakija-local-dev.edn
VIRKAILIJA_RELOADED ?= false
HAKIJA_RELOADED ?= false
FIGWHEEL=ataru-figwheel
CSS_COMPILER=ataru-css-compilation
HAKIJA_BACKEND=ataru-hakija-backend-8351
VIRKAILIJA_BACKEND=ataru-virkailija-backend-8350
HAKIJA_CYPRESS_BACKEND=ataru-hakija-cypress-backend-8353
VIRKAILIJA_CYPRESS_BACKEND=ataru-virkailija-cypress-backend-8352
DEV_SERVICES = $(FIGWHEEL) $(CSS_COMPILER) $(HAKIJA_BACKEND) $(VIRKAILIJA_BACKEND)
CYPRESS_SERVICES = $(FIGWHEEL) $(CSS_COMPILER) $(HAKIJA_CYPRESS_BACKEND) $(VIRKAILIJA_CYPRESS_BACKEND)
DOCKER_CONTAINERS_DEV = ataru-dev-db ataru-dev-redis ataru-test-db ataru-test-ftpd ataru-test-redis
DOCKER_CONTAINERS_CYPRESS = ataru-cypress-test-db ataru-test-ftpd ataru-test-redis ataru-cypress-test-redis ataru-cypress-http-proxy
# General options
PM2=npx pm2 --no-autorestart
START_ONLY=start pm2.config.js --only
STOP_ONLY=stop pm2.config.js --only
DOCKER_SUDO ?=
DOCKER=$(if $(DOCKER_SUDO),sudo )docker
DOCKER_COMPOSE=COMPOSE_PARALLEL_LIMIT=8 $(if $(DOCKER_SUDO),sudo )docker compose
NODE_MODULES=node_modules
# ----------------
# Check that all necessary tools are in path and have new enough versions
# ----------------
check-tools:
$(info Checking commands in path: $(EXECUTABLES) ...)
$(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),$(info .. $(exec) found),$(error No $(exec) in PATH)))
$(info Checking tool versions ...)
@$(foreach TOOL_VERSION, $(TOOL_VERSIONS), \
$(eval TOOL = $(word 1,$(subst :, ,$(TOOL_VERSION)))) \
$(eval VERSION = $(word 2,$(subst :, ,$(TOOL_VERSION)))) \
\
./bin/check-tool-version.sh $(TOOL) $(VERSION) || exit 1; )
# ----------------
# Docker build
# ----------------
build-docker-images: check-tools generate-nginx-config
$(DOCKER_COMPOSE) build
generate-nginx-config:
@./bin/generate-nginx-conf.sh
# ----------------
# Npm installation
# ----------------
$(NODE_MODULES): package.json package-lock.json
npm ci
touch $(NODE_MODULES)
# ----------------
# Start apps
# ----------------
start-docker-all: build-docker-images
$(DOCKER_COMPOSE) up -d
start-docker: build-docker-images
$(DOCKER_COMPOSE) up -d $(DOCKER_CONTAINERS_DEV)
start-docker-cypress: build-docker-images
$(DOCKER_COMPOSE) up -d $(DOCKER_CONTAINERS_CYPRESS)
start-pm2-all: $(NODE_MODULES) start-docker-all run-fake-deps-server
$(PM2) start pm2.config.js
start-pm2: $(NODE_MODULES) start-docker
$(foreach service, $(DEV_SERVICES), \
$(PM2) $(START_ONLY) $(service) || exit 1;)
start-pm2-cypress: $(NODE_MODULES) start-docker-cypress run-fake-deps-server
$(foreach service, $(CYPRESS_SERVICES), \
$(PM2) $(START_ONLY) $(service) || exit 1;)
start-watch: $(NODE_MODULES)
$(PM2) $(START_ONLY) $(FIGWHEEL)
$(PM2) $(START_ONLY) $(CSS_COMPILER)
start-hakija: start-watch start-docker
$(PM2) $(START_ONLY) $(HAKIJA_BACKEND)
start-virkailija: start-watch start-docker
$(PM2) $(START_ONLY) $(VIRKAILIJA_BACKEND)
# ----------------
# Stop apps
# ----------------
stop-pm2: $(NODE_MODULES)
$(PM2) stop pm2.config.js
stop-watch:
$(PM2) $(STOP_ONLY) $(FIGWHEEL)
$(PM2) $(STOP_ONLY) $(CSS_COMPILER)
stop-docker:
$(DOCKER_COMPOSE) kill
stop-hakija:
$(PM2) $(STOP_ONLY) $(HAKIJA_BACKEND)
stop-virkailija:
$(PM2) $(STOP_ONLY) $(VIRKAILIJA_BACKEND)
# ----------------
# Restart apps
# ----------------
restart-hakija: start-hakija
restart-virkailija: start-virkailija
restart-docker: stop-docker start-docker
restart-watch: start-watch
# ----------------
# Clean commands
# ----------------
clean-docker:
$(DOCKER_COMPOSE) stop
$(DOCKER_COMPOSE) rm
$(DOCKER) system prune -f
clean-lein:
lein clean
# Fake dependencies for tests
run-fake-deps-server:
./bin/fake-deps-server.sh start
stop-fake-deps-server:
./bin/fake-deps-server.sh stop
# ----------------
# Database initialization
# ----------------
init-test-db: run-fake-deps-server
lein with-profile test run -m ataru.db.flyway-migration/migrate "use dummy-audit-logger!"
nuke-test-db:
lein with-profile test run -m ataru.fixtures.db.unit-test-db/clear-database
load-test-fixture: nuke-test-db init-test-db
lein with-profile test run -m ataru.fixtures.db.browser-test-db/init-db-fixture
# ----------------
# Top-level commands (all apps)
# ----------------
start: start-pm2-all
start-dev: start-pm2
start-cypress: start-pm2-cypress
stop: stop-pm2 stop-docker stop-fake-deps-server
restart: stop-pm2 start-pm2
clean: nuke-test-db stop clean-lein clean-docker
rm -rf node_modules
rm *.log
status: $(NODE_MODULES)
docker ps
$(PM2) status
log: $(NODE_MODULES)
$(PM2) logs --timestamp
# Alias for log
logs: log
lint: $(NODE_MODULES)
npx eslint .
check-ports:
@for PORT in $(PORTS); do sudo lsof -i :$$PORT -sTCP:LISTEN; done || exit 0
help:
@cat Makefile.md
# ----------------
# Test db management
# ----------------
compile-test-code:
./bin/compile-less.sh
lein with-profile test cljsbuild once virkailija-min hakija-min
test-clojurescript: $(NODE_MODULES)
lein with-profile test doo chrome test once
test-browser: $(NODE_MODULES) compile-test-code run-fake-deps-server
lein with-profile test spec -t ui
test-clojure: nuke-test-db init-test-db
lein with-profile test spec -t ~ui
test: start-docker test-clojurescript test-clojure test-browser
# ----------------
# Kill PM2 and all apps managed by it (= everything)
# ----------------
kill: stop-pm2 stop-docker
$(PM2) kill