forked from Akkadius/akk-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
292 lines (232 loc) · 9.8 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
#----------------------
# Parse makefile arguments
#----------------------
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(RUN_ARGS):;@:)
#----------------------
# Silence GNU Make
#----------------------
ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif
#----------------------
# Load .env file
#----------------------
ifneq ("$(wildcard .env)","")
include .env
export
else
endif
#----------------------
# docker-sync context
#----------------------
DOCKER_COMPOSE_CONTEXT=
ifeq ("$(DOCKER_FS_SYNC_MODE)", "sync")
DOCKER_COMPOSE_CONTEXT = -f docker-compose.yml -f docker-compose-dev.yml
endif
#----------------------
# Terminal
#----------------------
GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
#------------------------------------------------------------------
# - Add the following 'help' target to your Makefile
# - Add help text after each target name starting with '\#\#'
# - A category can be added with @category
#------------------------------------------------------------------
HELP_FUN = \
%help; \
while(<>) { \
push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
print "-----------------------------------------\n"; \
print "| Welcome to EQEmu Docker!\n"; \
print "-----------------------------------------\n"; \
print "| usage: make [command]\n"; \
print "-----------------------------------------\n\n"; \
for (sort keys %help) { \
print "${WHITE}$$_:${RESET \
}\n"; \
for (@{$$help{$$_}}) { \
$$sep = " " x (32 - length $$_->[0]); \
print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
}; \
print "\n"; \
}
help: ##@other Show this help.
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
IN_PORT_RANGE_HIGH=${PORT_RANGE_HIGH}
ifneq ($(port-range-high),)
IN_PORT_RANGE_HIGH=$(port-range-high)
endif
IN_IP_ADDRESS=${IP_ADDRESS}
ifneq ($(ip-address),)
IN_IP_ADDRESS=$(ip-address)
endif
#----------------------
# env
#----------------------
set-vars: ##@env Sets var port-range-high=[] ip-address=[]
@assets/scripts/env-set-var.pl IP_ADDRESS $(IN_IP_ADDRESS)
@assets/scripts/env-set-var.pl PORT_RANGE_HIGH $(IN_PORT_RANGE_HIGH)
#----------------------
# Init / Install
#----------------------
install: ##@init Install full application port-range-high=[] ip-address=[]
docker-compose pull
@assets/scripts/env-set-var.pl IP_ADDRESS $(IN_IP_ADDRESS)
@assets/scripts/env-set-var.pl PORT_RANGE_HIGH $(IN_PORT_RANGE_HIGH)
docker-compose build mariadb
make up detached
@assets/scripts/env-set-var.pl
docker-compose exec mariadb bash -c 'while ! mysqladmin status -uroot -p${MARIADB_ROOT_PASSWORD} -h "localhost" --silent; do sleep .5; done;'
make init-strip-mysql-remote-root
docker-compose exec eqemu-server bash -c "make install"
docker-compose exec -T eqemu-server bash -c "make update-admin-panel"
COMPOSE_HTTP_TIMEOUT=1000 docker-compose down
COMPOSE_HTTP_TIMEOUT=1000 docker-compose up -d
init-strip-mysql-remote-root: ##@init Strips MySQL remote root user
docker-compose exec mariadb bash -c "mysql -uroot -p${MARIADB_ROOT_PASSWORD} -h localhost -e \"delete from mysql.user where User = 'root' and Host = '%'; FLUSH PRIVILEGES\""
init-reset-env: ##@init Resets .env
make env-transplant
make env-scramble-secrets
init-peq-editor: ##@init Initializes PEQ editor
docker-compose build peq-editor && docker-compose up -d peq-editor
docker-compose exec peq-editor bash -c "git clone https://github.com/ProjectEQ/peqphpeditor.git /var/www/html && \
cd /var/www/html/ && cp config.php.dist config.php && \
chown www-data:www-data /var/www/html -R"
docker-compose exec eqemu-server bash -c "make init-peq-editor"
#----------------------
# Image Management
#----------------------
image-build-all: ##@image-build Build all images
make image-eqemu-server-build
make image-peq-editor-build
make image-backup-cron-build
image-push-all: ##@image-build Push all images
make image-eqemu-server-push
make image-peq-editor-push
make image-backup-cron-push
image-build-push-all: ##@image-build Build and push all images
make image-build-all
make image-push-all
# eqemu-server
image-eqemu-server-build: ##@image-build Builds image
docker build containers/eqemu-server -t akkadius/eqemu-server:latest
docker build containers/eqemu-server -t akkadius/eqemu-server:v11
image-eqemu-server-push: ##@image-build Publishes image
docker push akkadius/eqemu-server:latest
docker push akkadius/eqemu-server:v11
# peq-editor
image-peq-editor-build: ##@image-build Builds image
docker build containers/peq-editor -t akkadius/peq-editor:latest
image-peq-editor-push: ##@image-build Publishes image
docker push akkadius/peq-editor:latest
# backup-cron
image-backup-cron-build: ##@image-build Builds image
docker build containers/backup-cron -t akkadius/eqemu-backup-cron:latest
image-backup-cron-push: ##@image-build Publishes image
docker push akkadius/eqemu-backup-cron:latest
#----------------------
# Workflow
#----------------------
bash: ##@workflow Bash into eqemu-server
docker-compose exec eqemu-server bash
mc: ##@workflow Jump into the MySQL container console
docker-compose exec mariadb bash -c "mysql -uroot -p${MARIADB_ROOT_PASSWORD} -h localhost ${MARIADB_DATABASE}"
MYSQL_BACKUP_NAME=${MARIADB_DATABASE}-$(shell date +"%m-%d-%Y")
mysql-backup: ##@workflow Jump into the MySQL container console
docker-compose exec -T mariadb bash -c "mysqldump --lock-tables=false -uroot -p${MARIADB_ROOT_PASSWORD} -h localhost ${MARIADB_DATABASE} > /var/lib/mysql/$(MYSQL_BACKUP_NAME).sql"
mkdir -p backup/database/
mv ./data/mariadb/$(MYSQL_BACKUP_NAME).sql .
tar -zcvf backup/database/$(MYSQL_BACKUP_NAME).tar.gz $(MYSQL_BACKUP_NAME).sql
rm $(MYSQL_BACKUP_NAME).sql
mysql-list-users: ##@workflow Lists MySQL users
docker-compose exec mariadb bash -c "mysql -uroot -p${MARIADB_ROOT_PASSWORD} -h localhost -e 'select user, password, host from mysql.user;'"
watch-processes: ##@workflow Watch processes
docker-compose exec eqemu-server bash -c "watch -n 1 'ps auxf'"
#----------------------
# Docker
#----------------------
up: ##@docker Bring up eqemu-server and database
COMPOSE_HTTP_TIMEOUT=1000 docker-compose up -d eqemu-server mariadb
up-all: ##@docker Bring up the whole environment
ifeq ("$(DOCKER_FS_SYNC_MODE)", "sync")
docker-sync start
endif
docker-compose $(DOCKER_COMPOSE_CONTEXT) up -d
ifeq (,$(findstring detached,$(RUN_ARGS)))
docker-compose logs --tail 100 -f
endif
down: ##@docker Down all containers
COMPOSE_HTTP_TIMEOUT=1000 docker-compose down
ifeq ("$(DOCKER_FS_SYNC_MODE)", "sync")
docker-sync stop
endif
restart: ##@docker Restart containers
make down
make up detached
#----------------------
# env
#----------------------
env-transplant: ##@env Merges values from .env.example into .env (.env is delegate)
@assets/scripts/env-transplant.pl
env-scramble-secrets: ##@env Scrambles secrets
@assets/scripts/env-scramble-secrets.pl $(RUN_ARGS)
env-set-zone-port-range-high: ##@env Set zone port range high value
docker-compose $(DOCKER_COMPOSE_CONTEXT) up -d eqemu-server
@assets/scripts/env-set-var.pl PORT_RANGE_HIGH $(RUN_ARGS)
docker-compose exec eqemu-server bash -c "cat ~/server/eqemu_config.json | jq '.server.zones.ports.high = "${PORT_RANGE_HIGH}"' | tee ~/server/eqemu_config.json"
docker-compose $(DOCKER_COMPOSE_CONTEXT) up -d --force-recreate eqemu-server
#----------------------
# Install
#----------------------
info: ##@info Print install info
@echo "##################################"
@echo "# Server Info"
@echo "##################################"
@echo '# $(shell docker-compose exec eqemu-server bash -c "cat ~/server/eqemu_config.json | jq '.server.world.longname' | tr -d '\"'")'
@echo "##################################"
@echo "# Passwords"
@echo "##################################"
@cat .env | grep PASSWORD
@echo "##################################"
@echo "# IP"
@echo "##################################"
@cat .env | grep IP
@echo "##################################"
@echo "# Quests FTP | ${IP_ADDRESS}:21 | quests / ${FTP_QUESTS_PASSWORD}"
@echo "##################################"
@echo "# Web Interfaces"
@echo "##################################"
@echo "# PEQ Editor | http://${IP_ADDRESS}:8081 | admin / ${PEQ_EDITOR_PASSWORD}"
@echo "# PhpMyAdmin | http://${IP_ADDRESS}:8082 | admin / ${PHPMYADMIN_PASSWORD}"
@echo "# EQEmu Admin | http://${IP_ADDRESS}:3000 | admin / $(shell docker-compose exec -T eqemu-server bash -c "cat ~/server/eqemu_config.json | jq '.[\"web-admin\"].application.admin.password'")"
@echo "##################################"
#----------------------
# dev
#----------------------
fw: ##@dev Runs web-admin frontend dev server (alias)
docker-compose exec eqemu-server bash -c "cd ~/server/eqemu-web-admin/frontend && npm run serve"
bw: ##@dev Runs web-admin backend dev server (alias)
docker-compose exec eqemu-server bash -c "cd ~/server/eqemu-web-admin && npm run watch"
#----------------------
# backup
#----------------------
backup-dropbox-init: ##@backup Initializes Dropbox backups
docker-compose up -d backup-cron
docker-compose exec backup-cron dropbox_uploader.sh
backup-dropbox-list: ##@backup Lists files from Dropbox backups
docker-compose up -d backup-cron
docker-compose exec backup-cron dropbox_uploader.sh list
backup-dropbox-database: ##@backup Database backup upload to Dropbox
docker-compose exec backup-cron ./backup/backup-database.sh
backup-dropbox-quests: ##@backup Quests backup upload to Dropbox
docker-compose exec backup-cron ./backup/backup-quests.sh
backup-dropbox-deployment: ##@backup Deployment backup upload to Dropbox
docker-compose exec backup-cron ./backup/backup-deployment.sh
backup-dropbox-all: ##@backup Backup all assets to Dropbox
make backup-dropbox-database
make backup-dropbox-quests
make backup-dropbox-deployment