-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
350 lines (265 loc) · 5.55 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
HOSTS_DIR=hosts
OPENRESTY_DIR=openresty
REDIS_DIR=redis
POSTGRES_DIR=postgres
GITLAB_DIR=gitlab
REDMINE_DIR=redmine
MONGO_DIR=mongodb
BACKUP_DIR=../backups
.PHONY: \
help \
all \
ips \
env \
deploy \
build \
run \
stop \
ps \
postgres \
postgres-build \
postgres-run \
postgres-logs \
postgres-rm \
postgres-debug \
redis \
redis-build \
redis-run \
redis-logs \
redis-rm \
redis-debug \
openresty \
openresty-build \
openresty-run \
openresty-logs \
openresty-rm \
openresty-debug \
gitlab \
gitlab-build \
gitlab-run \
gitlab-logs \
gitlab-rm \
gitlab-debug \
mongo \
mongo-build \
mongo-run \
mongo-logs \
mongo-rm \
mongo-debug \
redmine \
redmine-build \
redmine-run \
redmine-logs \
redmine-rm \
redmine-debug \
hosts \
hosts-build \
hosts-run
# general
all: help
deploy:
@${MAKE} \
env \
ips \
build \
run
env:
@./bin/create_env.sh
ips:
@./bin/create_ip_env.sh
build:
@${MAKE} \
redis-build \
postgres-build \
gitlab-build \
redmine-build \
openresty-build
run:
@${MAKE} \
redis-run \
postgres-run \
ips \
gitlab-run \
redmine-run \
ips \
openresty-run
clean:
@echo "removing configuration files:"
@echo "$$(ls -l ./**/ENV.sh)"
@rm -f ./**/ENV.sh
ps:
@docker ps
stop:
@${MAKE} -j5 \
postgres-stop \
redis-stop \
openresty-stop \
gitlab-stop \
redmine-stop
backup: gitlab-backup redmine-backup
echo "creating backup"
mkdir -p ${BACKUP_DIR}
echo "start copying files"
cp -rf ./* ${BACKUP_DIR}
echo "finished copying files"
echo "committing changes"
cd ${BACKUP_DIR}; \
git init && \
git add -A ./* && \
git commit -m "backup $$(date +\%Y-\%m-\%d-\%H:\%M:\%S)" ./*
echo "backup finished"
${MAKE} ips openresty
init:
@./bin/init.sh all
init_submodules:
@./bin/init.sh init_submodules
crontab:
@./bin/create_crontab.sh
update_submodules:
@./bin/init.sh update_submodules
# POSTGRES tasks
postgres: postgres-build postgres-run postgres-logs
postgres-build:
@cd ${POSTGRES_DIR}; ./cli.sh build
postgres-run:
@cd ${POSTGRES_DIR}; ./cli.sh run
postgres-logs:
@cd ${POSTGRES_DIR}; ./cli.sh logs
postgres-debug:
@cd ${POSTGRES_DIR}; ./cli.sh debug
postgres-rm:
@cd ${POSTGRES_DIR}; ./cli.sh remove
postgres-stop:
@cd ${POSTGRES_DIR}; ./cli.sh stop
# REDIS tasks
redis: redis-build redis-run redis-logs
redis-build:
@cd ${REDIS_DIR}; ./cli.sh build
redis-run:
@cd ${REDIS_DIR}; ./cli.sh run
redis-logs:
@cd ${REDIS_DIR}; ./cli.sh logs
redis-debug:
@cd ${REDIS_DIR}; ./cli.sh debug
redis-rm:
@cd ${REDIS_DIR}; ./cli.sh remove
redis-stop:
@cd ${REDIS_DIR}; ./cli.sh stop
# GITLAB tasks
gitlab: gitlab-run gitlab-logs
gitlab-run:
@cd ${GITLAB_DIR}; ./cli.sh run
gitlab-build:
@cd ${GITLAB_DIR}; ./cli.sh build
gitlab-debug:
@cd ${GITLAB_DIR}; ./cli.sh debug
gitlab-logs:
@cd ${GITLAB_DIR}; ./cli.sh logs
gitlab-rm:
@cd ${GITLAB_DIR}; ./cli.sh remove
gitlab-stop:
@cd ${GITLAB_DIR}; ./cli.sh stop
gitlab-backup:
@cd ${GITLAB_DIR}; ./cli.sh backup
# OPENRESTY tasks
openresty: openresty-build openresty-run openresty-logs
openresty-build:
@cd ${OPENRESTY_DIR}; ./cli.sh build
openresty-run:
@cd ${OPENRESTY_DIR}; ./cli.sh run
openresty-logs:
cd openresty; ./cli.sh logs
openresty-debug:
@cd ${OPENRESTY_DIR}; ./cli.sh debug
openresty-rm:
@cd ${OPENRESTY_DIR}; ./cli.sh remove
openresty-clean:
@cd ${OPENRESTY_DIR}; ./cli.sh clean
openresty-stop:
@cd ${OPENRESTY_DIR}; ./cli.sh stop
# REDMINE tasks
redmine: redmine-build redmine-run redmine-logs
redmine-run:
@cd ${REDMINE_DIR}; ./cli.sh run
redmine-logs:
@cd ${REDMINE_DIR}; ./cli.sh logs
redmine-build:
@cd ${REDMINE_DIR}; ./cli.sh build
redmine-debug:
@cd ${REDMINE_DIR}; ./cli.sh debug
redmine-rm:
@cd ${REDMINE_DIR}; ./cli.sh remove
redmine-stop:
@cd ${REDMINE_DIR}; ./cli.sh stop
redmine-backup:
@cd ${REDMINE_DIR}; ./cli.sh backup
# MONGODB tasks
mongo: mongo-build mongo-run mongo-logs
mongo-run:
@cd ${MONGO_DIR}; ./cli.sh run
mongo-logs:
@cd ${MONGO_DIR}; ./cli.sh logs
mongo-build:
@cd ${MONGO_DIR}; ./cli.sh build
mongo-debug:
@cd ${MONGO_DIR}; ./cli.sh debug
mongo-rm:
@cd ${MONGO_DIR}; ./cli.sh remove
mongo-stop:
@cd ${MONGO_DIR}; ./cli.sh stop
# host tasks
hosts:
@echo "building hosts"
@for dir in $$(ls ${HOSTS_DIR}); do \
host_dir=${HOSTS_DIR}/$$dir; \
if [ -d $$host_dir ]; then \
echo "building host $$dir"; \
cd $$host_dir; \
${MAKE} build; \
else \
echo "not a host directory $$host_dir"; \
fi; \
done;
hosts-status:
@echo "getting host status"
@for dir in $$(ls ${HOSTS_DIR}); do \
echo "host: $$dir git status"; \
cd ${HOSTS_DIR}/$$dir; \
git status; \
done;
hosts-update:
@echo "updating hosts"
@for dir in $$(ls ${HOSTS_DIR}); do \
echo "host: $$dir git pull"; \
cd ${HOSTS_DIR}/$$dir; \
git pull; \
echo "host: $$dir update done"; \
done;
hosts-install:
@echo "installing host dependencies"
@for dir in $$(ls ${HOSTS_DIR}); do \
echo "host: $$dir install dependencies"; \
cd ${HOSTS_DIR}/$$dir; \
npm install; \
echo "host: $$dir dependencies installed"; \
done;
# help output
help:
@echo "\
Usage \n\
make TASK\n\
deploy - runs all build tasks in a row, \n\
build-all - builds all containers \n\
run-all - runs all containers \n\
\n\
postgres - build and run the postgres container \n\
redis - build and run the redis container \n\
openresty - build and run the openresty container \n\
gitlab - build and run gitlab \n\
soon: redmine - build and run redmine \n\
\n\
each of the tasks has a -build and a -run subtask: \n\
postgres-build, redis-run. \n\
\n\
help - this help text \n\
"