forked from TYPO3-Caretaker/caretaker_instance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
ยท325 lines (282 loc) ยท 12.9 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
## Show this help
help:
echo "$(EMOJI_interrobang) Makefile version $(VERSION) help "
echo ''
echo 'About this help:'
echo ' Commands are ${BLUE}blue${RESET}'
echo ' Targets are ${YELLOW}yellow${RESET}'
echo ' Descriptions are ${GREEN}green${RESET}'
echo ''
echo 'Usage:'
echo ' ${BLUE}make${RESET} ${YELLOW}<target>${RESET}'
echo ''
echo 'Targets:'
awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")+1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-${TARGET_MAX_CHAR_NUM}s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
## Creates a backup of the database
.mysql-dump:
echo "$(EMOJI_floppy_disk) Dumping the database"
mkdir -p $(SQLDUMPSDIR)
docker-compose exec -u 1000:1000 mysql bash -c "mysqldump -u$(MYSQL_USER) -p$(MYSQL_PASSWORD) --add-drop-database --create-options --extended-insert --no-autocommit --quick --default-character-set=utf8 $(MYSQL_DATABASE) | gzip > /$(SQLDUMPSDIR)/$(SQLDUMPFILE)"
## Wait for the mysql container to be fully provisioned
.mysql-wait:
echo "$(EMOJI_ping_pong) Checking DB up and running"
while ! docker-compose exec mysql mysql -u$(MYSQL_USER) -p$(MYSQL_PASSWORD) $(MYSQL_DATABASE) -e "SELECT 1;" &> /dev/null; do \
echo "$(EMOJI_face_with_rolling_eyes) Waiting for database ..."; \
sleep 1; \
done;
## Restores the database from the backup file defined in .env
mysql-restore: .mysql-wait
echo "$(EMOJI_robot) Restoring the database"
docker-compose exec mysql bash -c 'DUMPFILE="/$(SQLDUMPSDIR)/$(SQLDUMPFILE)"; if [[ "$${DUMPFILE##*.}" == "sql" ]]; then cat $$DUMPFILE; else zcat $$DUMPFILE; fi | mysql --default-character-set=utf8 -u$(MYSQL_USER) -p$(MYSQL_PASSWORD) $(MYSQL_DATABASE)'
docker-compose exec mysql bash -c 'cat /$(SQLDUMPSDIR)/local_setup.sql | mysql --default-character-set=utf8 -u$(MYSQL_USER) -p$(MYSQL_PASSWORD) $(MYSQL_DATABASE)'
## Synchronize fileadmin with newer files from the backup server
.rsync-fileadmin:
echo "$(EMOJI_receive) Synchronizing fileadmin"
rsync -azl --info=progress2 --exclude '*.zip' --exclude '*.ZIP' --exclude '_processed_' --max-size=2M -e ssh $(SYNCSERVER):$(SYNCFOLDER)/fileadmin/ $(WEBROOT)/fileadmin/
## Synchronize uploads with newer files from the backup server
.rsync-uploads:
echo "$(EMOJI_receive) Synchronizing uploads"
rsync -azl --info=progress2 --exclude '*.zip' --exclude '*.ZIP' --exclude '_processed_' --max-size=2M -e ssh $(SYNCSERVER):$(SYNCFOLDER)/uploads/ $(WEBROOT)/uploads/
## Update the database dump file (required for mysql-restore)
.rsync-database:
echo "$(EMOJI_receive) Downloading newer database dump"
mkdir -p $(SQLDUMPSDIR)
rsync -azL --info=progress2 -e ssh $(SYNCSERVER):$(SYNCFOLDER)/$(SQLDUMPFILE) $(SQLDUMPSDIR)/$(SQLDUMPFILE)
## Stop all containers
stop:
echo "$(EMOJI_stop) Shutting down"
docker-compose stop
sleep 0.4
ifeq ($(shell uname -s), Darwin)
sleep 2
endif
docker-compose down --remove-orphans
## Removes all containers and volumes
destroy: stop
echo "$(EMOJI_litter) Removing the project"
docker-compose down -v --remove-orphans
## Starts docker-compose up -d
start: .docker-pull .docker-start
make urls
## Choose the right docker-compose file for your environment
.link-compose-file:
echo "$(EMOJI_triangular_ruler) Linking the OS specific compose file"
ifeq ($(shell uname -s), Darwin)
ln -snf .project/docker/docker-compose.darwin.yml docker-compose.yml
else
ln -snf .project/docker/docker-compose.unix.yml docker-compose.yml
endif
## Starts composer-install
composer-install:
echo "$(EMOJI_package) Installing composer dependencies"
docker-compose exec php composer install
## Starts phive install
phive-install:
echo "$(EMOJI_wrapped_gift) Installing phars with phive"
[ -h docker-compose.yml ] || make .link-compose-file
CMD="phive install --trust-gpg-keys 31C7E470E2138192,0F9684B8B16B7AB0,60B7CDE72C913795"; [ -f /.dockerenv ] && $$CMD || docker-compose run -w /app php $$CMD
## Create necessary directories
.create-dirs:
echo "$(EMOJI_dividers) Creating required directories"
mkdir -p $$HOME/.phive
mkdir -p .Build/$(TYPO3_CACHE_DIR)
mkdir -p $(SQLDUMPSDIR)
mkdir -p build/prototype/HTML-Prototype
## Starts composer-install for production
.composer-install-production:
echo "$(EMOJI_package) Installing composer dependencies (without dev)"
docker-compose exec php composer install --no-dev -ao
## Install mkcert on this computer, skips installation if already present
.install-mkcert:
if [[ "$$OSTYPE" == "linux-gnu" ]]; then \
if [[ "$$(command -v certutil > /dev/null; echo $$?)" -ne 0 ]]; then sudo apt install libnss3-tools; fi; \
if [[ "$$(command -v mkcert > /dev/null; echo $$?)" -ne 0 ]]; then sudo curl -L https://github.com/FiloSottile/mkcert/releases/download/v1.4.1/mkcert-v1.4.1-linux-amd64 -o /usr/local/bin/mkcert; sudo chmod +x /usr/local/bin/mkcert; fi; \
elif [[ "$$OSTYPE" == "darwin"* ]]; then \
BREW_LIST=$$(brew ls --formula); \
if [[ ! $$BREW_LIST == *"mkcert"* ]]; then brew install mkcert; fi; \
if [[ ! $$BREW_LIST == *"nss"* ]]; then brew install nss; fi; \
fi;
mkcert -install > /dev/null
## Create SSL certificates for dinghy and starting project
.create-certificate: .install-mkcert
echo "$(EMOJI_secure) Creating SSL certificates for dinghy http proxy"
mkdir -p $(HOME)/.dinghy/certs/
PROJECT=$$(echo "$${PWD##*/}" | tr -d '.'); \
if [[ ! -f $(HOME)/.dinghy/certs/$$PROJECT.docker.key ]]; then mkcert -cert-file $(HOME)/.dinghy/certs/$$PROJECT.docker.crt -key-file $(HOME)/.dinghy/certs/$$PROJECT.docker.key "*.$$PROJECT.docker"; fi;
if [[ ! -f $(HOME)/.dinghy/certs/${WEB_HOST}.key ]]; then mkcert -cert-file $(HOME)/.dinghy/certs/${WEB_HOST}.crt -key-file $(HOME)/.dinghy/certs/${WEB_HOST}.key ${WEB_HOST}; fi;
if [[ ! -f $(HOME)/.dinghy/certs/${MAIL_HOST}.key ]]; then mkcert -cert-file $(HOME)/.dinghy/certs/${MAIL_HOST}.crt -key-file $(HOME)/.dinghy/certs/${MAIL_HOST}.key ${MAIL_HOST}; fi;
if [[ ! -f $(HOME)/.dinghy/certs/${NODE_HOST}.key ]]; then mkcert -cert-file $(HOME)/.dinghy/certs/${NODE_HOST}.crt -key-file $(HOME)/.dinghy/certs/${NODE_HOST}.key ${NODE_HOST}; fi;
## Try to login to the docker registry. Will not ask for credentials if valid login is already persisted. Skipped if no registry is defined.
.docker-login:
[ -z "${DOCKER_REGISTRY}" ] || ( \
echo "$(EMOJI_eyes) Logging in to gitlab.in2code.de:5050"; \
docker login gitlab.in2code.de:5050 \
)
## Update all images related to this project
.docker-pull:
echo "$(EMOJI_fishing_pole) Updating all docker images for this project"
docker-compose pull
docker-compose build --pull
## Start the project
.docker-start:
echo "$(EMOJI_musical_score) Starting the docker compose project"
docker-compose up -d
## Set correct onwership of mounts. Docker creates mounts owned by root:root.
.fix-mount-perms:
echo "$(EMOJI_rocket) Fixing docker mount permissions"
docker-compose exec -u root php chown -R app:app /app/.Build/$(TYPO3_CACHE_DIR)/;
## Copies the Additional/DockerConfiguration.php to the correct directory
.typo3-add-dockerconfig:
echo "$(EMOJI_plug) Copying the docker specific configuration for TYPO3"
mkdir -p $(WEBROOT)/typo3conf/AdditionalConfiguration
ln -snf ../../../../.project/TYPO3/DockerConfiguration.php $(WEBROOT)/typo3conf/AdditionalConfiguration/DockerConfiguration.php
## Starts the TYPO3 Databasecompare
typo3-comparedb:
echo "$(EMOJI_leftright) Running database:updateschema"
docker-compose exec php ./.Build/vendor/bin/typo3cms database:updateschema
## Starts the TYPO3 setup process
.typo3-setupinstall:
echo "$(EMOJI_upright) Running install:setup"
docker-compose exec php ./.Build/vendor/bin/typo3cms install:setup
## Clears TYPO3 caches via typo3-console
typo3-clearcache:
echo "$(EMOJI_broom) Clearing TYPO3 caches"
docker-compose exec php ./.Build/vendor/bin/typo3cms cache:flush
## To start an existing project incl. rsync from fileadmin, uploads and database dump
install-project: .link-compose-file stop .add-hosts-entry .create-dirs .create-certificate .docker-login .docker-pull .docker-start .fix-mount-perms composer-install .typo3-add-dockerconfig typo3-comparedb .print-online
## To start a new project
new-project: .link-compose-file destroy .add-hosts-entry .create-dirs .create-certificate .docker-login .docker-pull .docker-start .fix-mount-perms composer-install phive-install npm-install .typo3-add-dockerconfig .typo3-setupinstall typo3-comparedb .setup-git-hooks .print-online
## Outputs the success message that the project is online
.print-online:
echo "---------------------"
echo ""
echo "The project is online $(EMOJI_thumbsup)"
echo ""
echo 'Stop the project with "make stop"'
echo ""
echo "---------------------"
make urls
## Print Project URIs
urls:
echo "$(EMOJI_telescope) Project URLs:";
echo '';
printf " %-10s %s\n" "Frontend:" "https://$(WEB_HOST)/";
printf " %-10s %s\n" "Backend:" "https://$(WEB_HOST)/typo3/";
printf " %-10s %s\n" "Mail:" "https://$(MAIL_HOST)/";
printf " %-10s %s\n" "Node:" "https://$(NODE_HOST)/";
## Create the hosts entry for the custom project URL (non-dinghy convention)
.add-hosts-entry:
echo "$(EMOJI_monkey) Creating Hosts Entry (if not set yet)"
SERVICES=$$(command -v getent > /dev/null && echo "getent ahostsv4" || echo "dscacheutil -q host -a name"); \
if [ ! "$$($$SERVICES $(WEB_HOST) | grep 127.0.0.1 > /dev/null; echo $$?)" -eq 0 ]; then sudo bash -c 'echo "127.0.0.1 $(WEB_HOST) $(MAIL_HOST) $(NODE_HOST)" >> /etc/hosts; echo "Entry was added"'; else echo 'Entry already exists'; fi;
## Log into the PHP container
login-php:
echo "$(EMOJI_elephant) Logging in into the PHP container"
docker-compose exec php bash
## Log into the mysql container
login-mysql:
echo "$(EMOJI_dolphin) Logging in into MySQL container"
docker-compose exec mysql bash
## Log into the node container
login-node:
echo "$(EMOJI_package) Logging in into Node container"
docker-compose exec -unode node bash
## Sets up pre-commit hook
.setup-git-hooks:
echo "$(EMOJI_nutandbolt) Setting up git pre-commit hook"
git config core.hooksPath .project/githooks
chmod ug+x .project/githooks/*
## Run all QA tasks
qa: qa-php
## Run all PHP specific QA tasks
qa-php: qa-phpcs qa-phpmd
## Run the PHP Code Sniffer QA tasks
qa-phpcs:
[ -h .project/phars/phpcs ] || make phive-install
[ -h docker-compose.yml ] || make .link-compose-file
CMD=".project/phars/phpcs"; [ -f /.dockerenv ] && $$CMD || docker-compose run -w /app php $$CMD
## Run the PHP Mess Detector QA tasks
qa-phpmd:
[ -h .project/phars/phpmd ] || make phive-install
[ -h docker-compose.yml ] || make .link-compose-file
CMD=".project/phars/phpmd app/packages/ ansi .phpmd.xml"; [ -f /.dockerenv ] && $$CMD || docker-compose run -w /app php $$CMD
qa-typoscriptlint:
[ -h .project/phars/typoscript-lint ] || make phive-install
[ -h docker-compose.yml ] || make .link-compose-file
CMD=".project/phars/typoscript-lint "; [ -f /.dockerenv ] && $$CMD || docker-compose run -w /app php $$CMD
## Fix all phpcs issues which can be fixed automatically
fix-phpcbf:
[ -h .project/phars/phpcbf ] || make phive-install
[ -h docker-compose.yml ] || make .link-compose-file
CMD=".project/phars/phpcbf"; [ -f /.dockerenv ] && $$CMD || docker-compose run -w /app php $$CMD
include .env
# SETTINGS
TARGET_MAX_CHAR_NUM := 25
MAKEFLAGS += --silent
SHELL := /bin/bash
VERSION := 1.0.0
# COLORS
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
BLUE := $(shell tput -Txterm setaf 4)
MAGENTA := $(shell tput -Txterm setaf 5)
CYAN := $(shell tput -Txterm setaf 6)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
# EMOJIS (some are padded right with whitespace for text alignment)
EMOJI_litter := "๐ฎ๏ธ"
EMOJI_interrobang := "โ๏ธ "
EMOJI_floppy_disk := "๐พ๏ธ"
EMOJI_dividers := "๐๏ธ "
EMOJI_up := "๐๏ธ"
EMOJI_receive := "๐ฅ๏ธ"
EMOJI_robot := "๐ค๏ธ"
EMOJI_stop := "๐๏ธ"
EMOJI_package := "๐ฆ๏ธ"
EMOJI_secure := "๐๏ธ"
EMOJI_explodinghead := "๐คฏ๏ธ"
EMOJI_rocket := "๐๏ธ"
EMOJI_plug := "๐๏ธ"
EMOJI_leftright := "โ๏ธ "
EMOJI_upright := "โ๏ธ "
EMOJI_thumbsup := "๐๏ธ"
EMOJI_telescope := "๐ญ๏ธ"
EMOJI_monkey := "๐๏ธ"
EMOJI_elephant := "๐๏ธ"
EMOJI_dolphin := "๐ฌ๏ธ"
EMOJI_helicopter := "๐๏ธ"
EMOJI_broom := "๐งน"
EMOJI_nutandbolt := "๐ฉ"
EMOJI_crystal_ball := "๐ฎ"
EMOJI_triangular_ruler := "๐"
EMOJI_ping_pong := "๐"
EMOJI_face_with_rolling_eyes := "๐"
EMOJI_eyes := "๐"
EMOJI_fire := "๐ฅ"
EMOJI_runningshirt := "๐ฝ"
EMOJI_evergreen_tree := "๐ฒ"
EMOJI_luggage := "๐งณ"
EMOJI_fishing_pole := "๐ฃ"
EMOJI_musical_score := "๐ผ"
EMOJI_nerd_face := "๐ค"
EMOJI_digit_zero := "0๏ธ"
EMOJI_digit_one := "1๏ธ"
EMOJI_digit_two := "2๏ธ"
EMOJI_digit_three := "3๏ธ"
EMOJI_digit_four := "4๏ธ"
EMOJI_digit_seven := "7๏ธ"
EMOJI_pig_nose := "๐ฝ"
EMOJI_customs := "๐"
EMOJI_hot_face := "๐ฅต"
EMOJI_cold_face := "๐ฅถ"
EMOJI_hourglass_not_done := "โณ"
EMOJI_wrvendor/bin/ed_gift := "๐"