-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
352 lines (323 loc) · 10.3 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
#@author Fred Brooker <git@gscloud.cz>
include .env
STATIC_IMAGE_BACKUP ?= gscloudcz/backup-static-site:latest
STATIC_IMAGE_RESTORE ?= gscloudcz/restore-static-site:latest
STATIC_IMAGE_SUSPEND ?= gscloudcz/suspend-static-site:latest
run ?=
db_status != docker inspect --format '{{json .State.Running}}' ${WORDPRESS_DB_CONTAINER_NAME} 2>/dev/null | grep true
wp_status != docker inspect --format '{{json .State.Running}}' ${WORDPRESS_CONTAINER_NAME} 2>/dev/null | grep true
pma_status != docker inspect --format '{{json .State.Running}}' ${PMA_CONTAINER_NAME} 2>/dev/null | grep true
wpdb_status := $(wp_status)$(db_status)
wpdbok = truetrue
ifneq ($(strip $(wp_status)),)
wpdot=🟢
else
wpdot=🔴
endif
ifneq ($(strip $(db_status)),)
dbdot=🟢
else
dbdot=🔴
endif
ifneq ($(strip $(pma_status)),)
pmadot=🟢
else
pmadot=🔴
endif
all: info
info:
@echo "\n\e[1;32mWP in Docker 👾\e[0m v1.9 2024-11-21\n"
@echo "\e[0;1m📦️ WP\e[0m \t$(wpdot) \e[0;4m${WORDPRESS_CONTAINER_NAME}\e[0m \tport: ${WORDPRESS_PORT} \t🚀 http://localhost:${WORDPRESS_PORT}"
@echo "\e[0;1m📦️ DB\e[0m \t$(dbdot) \e[0;4m${WORDPRESS_DB_CONTAINER_NAME}\e[0m \tport: ${WORDPRESS_DB_PORT}"
ifneq ($(strip $(PMA_PORT)),)
@echo "\e[0;1m📦️ PMA\e[0m \t$(pmadot) \e[0;4m${PMA_CONTAINER_NAME}\e[0m \tport: ${PMA_PORT} \t🚀 http://localhost:${PMA_PORT}"
endif
ifneq ($(strip $(CMD_EXTRAS)),)
@echo "\e[1;33mCMD_EXTRAS\e[0m\e[0;33m is set to run after installation.\e[0m"
endif
ifneq ($(strip $(INSTALL_EXTRAS)),)
@echo "\e[1;33mINSTALL_EXTRAS\e[0m\e[0;33m is set to run after installation.\e[0m"
endif
@echo ""
@echo "- \e[0;1m install\e[0m - install containers"
@echo "- \e[0;1m start\e[0m - start containers"
@echo "- \e[0;1m stop\e[0m - stop containers"
@echo "- \e[0;1m suspend\e[0m - suspend site (run a static web instead)"
@echo "- \e[0;1m unsuspend\e[0m - unsuspend site"
@echo "- \e[0;1m test\e[0m - test containers"
@echo "- \e[0;1m fix\e[0m - fix web container permissions"
@echo "- \e[0;1m update\e[0m - update themes and plugins via wp binary"
@echo "- \e[0;1m kill\e[0m - kill containers"
@echo "- \e[0;1m remove\e[0m - remove containers"
@echo "- \e[0;1m cronrunall\e[0m - run all cron hooks"
@echo "- \e[0;1m cronrundue\e[0m - run all cron hooks due right now"
@echo "- \e[0;1m backup\e[0m - backup containers"
@echo "- \e[0;1m restore\e[0m - restore containers"
@echo "- \e[0;1m exec\e[0m - run shell inside container"
@echo "- \e[0;1m exec run='<command>'\e[0m - run <command> inside container"
@echo "- \e[0;1m debug\e[0m - install and run in the foreground"
@echo "- \e[0;1m config\e[0m - display Docker compose configuration"
@echo "- \e[0;1m lock\e[0m - lock installation for writing"
@echo "- \e[0;1m unlock\e[0m - unlock installation for writing"
@echo "- \e[0;1m logs\e[0m - display logs"
@echo "- \e[0;1m purge\e[0m - delete persistent data ❗️"
@echo "- \e[0;1m docs\e[0m - transpile documentation into PDF"
@echo ""
docs:
@bash ./bin/create_pdf.sh
debug:
@docker compose up
install: remove
@date
@echo "installing containers"
@docker compose up -d
ifneq ($(strip $(CMD_EXTRAS)),)
@-docker cp ./cmd_extras.sh ${WORDPRESS_CONTAINER_NAME}:/
@-docker exec ${WORDPRESS_CONTAINER_NAME} /cmd_extras.sh
@-docker restart ${WORDPRESS_CONTAINER_NAME}
endif
ifneq ($(strip $(INSTALL_EXTRAS)),)
@echo "sleeping 3 s"
@sleep 3
@bash ./install_extras.sh
endif
@echo "\n\e[0;1m📦️ WP\e[0m: 🚀 http://localhost:${WORDPRESS_PORT}"
ifneq ($(strip $(PMA_PORT)),)
@echo "\e[0;1m📦️ PMA\e[0m: 🚀 http://localhost:${PMA_PORT}"
endif
@date
start:
@echo "starting containers"
ifneq ($(strip $(ENABLE_STATIC_PAGES)),)
@-docker rm ${WORDPRESS_CONTAINER_NAME}_static --force 2>/dev/null
endif
@docker start ${WORDPRESS_DB_CONTAINER_NAME}
@docker start ${WORDPRESS_CONTAINER_NAME}
ifneq ($(strip $(PMA_PORT)),)
@docker start ${PMA_CONTAINER_NAME}
endif
stop:
@echo "stopping containers"
@-docker stop ${WORDPRESS_CONTAINER_NAME}
@-docker stop ${WORDPRESS_DB_CONTAINER_NAME}
ifneq ($(strip $(PMA_PORT)),)
@-docker stop ${PMA_CONTAINER_NAME}
endif
ifneq ($(strip $(ENABLE_STATIC_PAGES)),)
@-docker rm ${WORDPRESS_CONTAINER_NAME}_static --force 2>/dev/null
endif
kill:
@echo "😵"
@docker compose kill
remove:
@echo "removing containers"
@docker compose stop
@-docker rm ${WORDPRESS_CONTAINER_NAME} --force 2>/dev/null
@-docker rm ${WORDPRESS_DB_CONTAINER_NAME} --force 2>/dev/null
ifneq ($(strip $(PMA_PORT)),)
@-docker rm ${PMA_CONTAINER_NAME} --force 2>/dev/null
endif
ifneq ($(strip $(ENABLE_STATIC_PAGES)),)
@-docker rm ${WORDPRESS_CONTAINER_NAME}_static --force 2>/dev/null
endif
suspend: remove
ifneq ($(strip $(ENABLE_STATIC_PAGES)),)
@-docker rm ${WORDPRESS_CONTAINER_NAME}_static --force 2>/dev/null
@echo "⛔️ running suspend site"
@docker run -d --rm -p ${WORDPRESS_PORT}:3000 --name ${WORDPRESS_CONTAINER_NAME}_suspended ${STATIC_IMAGE_SUSPEND}
else
@echo "ℹ️ static sites are disabled in .env"
endif
unsuspend:
ifneq ($(strip $(ENABLE_STATIC_PAGES)),)
@echo "⛔️ removing suspend site"
@-docker rm ${WORDPRESS_CONTAINER_NAME}_suspended --force 2>/dev/null
@-make install
else
@echo "ℹ️ static sites are disabled in .env"
endif
config:
@docker compose config
exec:
ifneq ($(strip $(run)),)
@docker exec ${WORDPRESS_CONTAINER_NAME} $(run)
else
@docker exec -it ${WORDPRESS_CONTAINER_NAME} bash
endif
fix:
ifneq ($(shell id -u),0)
@echo "root permission required"
endif
@sudo rm -f www/.maintenance
@-sudo chown -R www-data:www-data www/.htaccess www/*.html www/*.php
@-sudo chown -R www-data:www-data www/wp-admin
@-sudo chown -R www-data:www-data www/wp-content
@-sudo chown -R www-data:www-data www/wp-includes
@-sudo chmod 0775 www/wp-content/uploads 2>/dev/null
@echo "content permissions fixed"
lock:
ifneq ($(shell id -u),0)
@echo "root permission required"
endif
@echo "WP locked"
@sudo find www/ -type d -print -exec chmod 555 {} \;
@sudo find www/ -type f -print -exec chmod 444 {} \;
unlock:
ifneq ($(shell id -u),0)
@echo "root permission required"
endif
@echo "WP unlocked"
@sudo find www/ -type d -print -exec chmod 755 {} \;
@sudo find www/ -type f -print -exec chmod 644 {} \;
update:
ifneq ($(shell id -u),0)
@echo "root permission required"
endif
@sudo rm -f www/.maintenance
@-sudo chown -R www-data:www-data www/.htaccess www/*.html www/*.php
@-sudo chown -R www-data:www-data www/wp-admin
@-sudo chown -R www-data:www-data www/wp-content
@-sudo chown -R www-data:www-data www/wp-includes
@-sudo chmod 0775 www/wp-content/uploads 2>/dev/null
@echo "content permissions fixed"
@-docker exec ${WORDPRESS_CONTAINER_NAME} wp plugin update --all
@-docker exec ${WORDPRESS_CONTAINER_NAME} wp theme update --all
@-sudo chown -R www-data:www-data www/.htaccess www/*.html www/*.php
@-sudo chown -R www-data:www-data www/wp-admin
@-sudo chown -R www-data:www-data www/wp-content
@-sudo chown -R www-data:www-data www/wp-includes
@-sudo chmod 0775 www/wp-content/uploads 2>/dev/null
@sudo rm -f www/.maintenance
@echo "content permissions fixed"
cronrundue:
@sudo rm -f www/.maintenance
@-docker exec ${WORDPRESS_CONTAINER_NAME} wp cron event run --due-now
@sudo rm -f www/.maintenance
cronrunall:
@sudo rm -f www/.maintenance
@-docker exec ${WORDPRESS_CONTAINER_NAME} wp cron event run --all
@sudo rm -f www/.maintenance
logs:
@docker logs -f ${WORDPRESS_CONTAINER_NAME}
backup: start
ifneq ($(shell id -u),0)
@echo "root permission required"
@sudo echo ""
endif
@date
@rm -rf bak
@mkdir bak
@echo "exporting database"
@-docker exec ${WORDPRESS_DB_CONTAINER_NAME} mariadb-dump -uroot -p${MYSQL_ROOT_PASSWORD} --all-databases > bak/mariadb.sql
@-docker stop ${WORDPRESS_CONTAINER_NAME}
@-docker stop ${WORDPRESS_DB_CONTAINER_NAME}
ifneq ($(strip $(PMA_PORT)),)
@-docker stop ${PMA_CONTAINER_NAME}
endif
ifneq ($(strip $(ENABLE_STATIC_PAGES)),)
@echo "running static site"
@-docker run -d --rm -p ${WORDPRESS_PORT}:3000 --name ${WORDPRESS_CONTAINER_NAME}_static ${STATIC_IMAGE_BACKUP}
endif
ifneq ($(shell id -u),0)
@echo "root permission required"
endif
@sudo tar czf bak/db.tgz db
@sudo tar czf bak/www.tgz www
@cp Makefile bak/
@cp .env bak/
@cp apache/* bak/
@cp docker-compose.yml bak/
ifneq ($(strip $(CMD_EXTRAS)),)
@cp cmd_extras.sh bak/
endif
ifneq ($(strip $(INSTALL_EXTRAS)),)
@cp install_extras.sh bak/
endif
ifneq ($(strip $(ENABLE_STATIC_PAGES)),)
@echo "closing static site"
@-docker rm ${WORDPRESS_CONTAINER_NAME}_static --force 2>/dev/null
endif
@-make install
@date
restore: remove
ifneq ($(shell id -u),0)
@echo "root permission required"
@sudo echo ""
endif
@date
ifneq ($(strip $(ENABLE_STATIC_PAGES)),)
@echo "running static site"
@-docker run -d --rm -p ${WORDPRESS_PORT}:3000 --name ${WORDPRESS_CONTAINER_NAME}_static ${STATIC_IMAGE_RESTORE}
endif
ifneq ($(shell id -u),0)
@echo "root permission required"
endif
@sudo rm -rf db www
ifneq ($(wildcard ./bak/.),)
@echo "backup location: bak"
ifneq ($(wildcard bak/db.tgz),)
@-sudo tar xzf bak/db.tgz 2>/dev/null
else
@echo "❗️ missing database archive"
exit 1
endif
ifneq ($(wildcard bak/www.tgz),)
@-sudo tar xzf bak/www.tgz 2>/dev/null
else
@echo "❗️ missing WP archive"
exit 1
endif
else
@echo "backup location: ."
ifneq ($(wildcard db.tgz),)
@-sudo tar xzf db.tgz 2>/dev/null
else
@echo "❗️ missing database archive"
exit 1
endif
ifneq ($(wildcard www.tgz),)
@-sudo tar xzf www.tgz 2>/dev/null
else
@echo "❗️ missing WP archive"
exit 1
endif
endif
ifneq ($(strip $(CMD_EXTRAS)),)
@cp bak/cmd_extras.sh . 2>/dev/null
endif
ifneq ($(strip $(INSTALL_EXTRAS)),)
@cp bak/install_extras.sh . 2>/dev/null
endif
ifneq ($(strip $(ENABLE_STATIC_PAGES)),)
@echo "closing static site"
@-docker rm ${WORDPRESS_CONTAINER_NAME}_static --force 2>/dev/null
endif
@-make install
@date
purge: remove
@-docker rm ${WORDPRESS_CONTAINER_NAME}_static --force 2>/dev/null
@-docker rm ${WORDPRESS_DB_CONTAINER_NAME}_static --force 2>/dev/null
@echo "💀 deleting permanent storage"
ifneq ($(shell id -u),0)
@echo "root permission required"
endif
sudo rm -rf db www
test:
ifneq ($(strip $(ENABLE_STATIC_PAGES)),)
@-docker rm ${WORDPRESS_CONTAINER_NAME}_static --force 2>/dev/null
endif
ifneq ($(strip $(wp_status)),)
@echo "🟢 WP is up"
else
@echo "🔴 WP is down"
endif
ifneq ($(strip $(db_status)),)
@echo "🟢 DB is up"
else
@echo "🔴 DB is down"
endif
ifneq ($(wpdb_status), $(wpdbok))
@exit 255
else
@exit 0
endif