-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile
257 lines (225 loc) ยท 10 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
## 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)
## Stop all containers
stop:
echo "$(EMOJI_stop) Shutting down"
docker-compose stop
sleep 0.4
docker-compose down --remove-orphans
## Removes all containers and volumes
destroy: stop
echo "$(EMOJI_litter) Removing the project"
docker-compose down -v --remove-orphans
git clean -dfx
make .link-compose-file
## Starts docker-compose up -d
start:
echo "$(EMOJI_up) Starting the docker project"
docker-compose up -d --build
make .fix-mount-perms
make urls
## 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) --no-tablespaces --add-drop-database --create-options --extended-insert --no-autocommit --quick --default-character-set=utf8mb4 $(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)'
## Starts composer-install
composer-install:
echo "$(EMOJI_package) Installing composer dependencies"
docker-compose exec php composer install
## Create necessary directories
.create-dirs:
echo "$(EMOJI_dividers) Creating required directories"
mkdir -p $(TYPO3_CACHE_DIR)
mkdir -p $(SQLDUMPSDIR)
mkdir -p $(WEBROOT)/$(TYPO3_CACHE_DIR)
## 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); \
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/${HOST}.key ]]; then mkcert -cert-file $(HOME)/.dinghy/certs/${HOST}.crt -key-file $(HOME)/.dinghy/certs/${HOST}.key ${HOST}; fi;
if [[ ! -f $(HOME)/.dinghy/certs/${MAIL}.key ]]; then mkcert -cert-file $(HOME)/.dinghy/certs/${MAIL}.crt -key-file $(HOME)/.dinghy/certs/${MAIL}.key ${MAIL}; fi;
## 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
## Install Frontend Build Tool Chain dependencies
npm-install:
echo "$(EMOJI_explodinghead) Installing Frontend Build Toolchain (this might take a while)"
docker-compose exec -u node -w /home/node/app/Resources/Private/ node npm ci
## Start watch on node-container
npm-watch:
docker-compose exec -u node -w /home/node/app/Resources/Private/ node npm run watch:all
## Stop the node container
npm-stop:
docker-compose stop node
## Initialize the docker setup
.init-docker: .create-dirs .create-certificate
echo "$(EMOJI_rocket) Initializing docker environment"
docker-compose pull
docker-compose up -d --build
docker-compose exec -u root php chown -R app:app /app/$(WEBROOT)/$(TYPO3_CACHE_DIR)/;
## Copies the TYPO3 site configuration
.typo3-add-site:
echo "$(EMOJI_triangular_flag) Copying the TYPO3 site configuration"
mkdir -p config/sites/main/
cp -f .project/TYPO3/host1.yaml config/sites/main/config.yaml
mkdir -p config/sites/second/
cp -f .project/TYPO3/host2.yaml config/sites/second/config.yaml
## Copies the Additional/DockerConfiguration.php to the correct directory
.typo3-add-dockerconfig:
echo "$(EMOJI_plug) Copying the docker specific configuration for TYPO3"
mkdir -p ./config/system
cp -f .project/TYPO3/additional.php ./config/system/additional.php
## Runs the TYPO3 Database Compare
typo3-comparedb:
echo "$(EMOJI_leftright) Running database:updateschema"
docker-compose exec php ./.Build/bin/typo3 database:updateschema
## Starts the TYPO3 setup process
.typo3-setupinstall:
echo "$(EMOJI_upright) Running install:setup"
docker-compose exec php ./.Build/bin/typo3 install:setup
## Clears TYPO3 caches via typo3-console
typo3-clearcache:
echo "$(EMOJI_broom) Clearing TYPO3 caches"
docker-compose exec php ./.Build/bin/typo3 cache:flush
## Checkout LFS files
lfs-fetch:
echo "$(EMOJI_milky_way) Fetching git LFS content"
git lfs fetch
git lfs checkout
## Provision fileadmin with necessary files
.provision-fileadmin:
echo "$(EMOJI_package) Provision fileadmin with necessary files from git lfs"
cd .Build/public; \
tar xvfz ../../.project/data/fileadmin.tar.gz
## To start an existing project incl. rsync from fileadmin, uploads and database dump
install-project: lfs-fetch .link-compose-file destroy .add-hosts-entry .init-docker .fix-mount-perms composer-install .typo3-add-site .typo3-add-dockerconfig .provision-fileadmin mysql-restore typo3-comparedb typo3-clearcache .typo3-setupinstall
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:
PROJECT=$$(echo "$${PWD##*/}" | tr -d '.'); \
SERVICES=$$(docker-compose ps --services | grep '$(SERVICELIST)'); \
LONGEST=$$(($$(echo -e "$$SERVICES\nFrontend:" | wc -L 2> /dev/null || echo 15)+2)); \
echo "$(EMOJI_telescope) Project URLs:"; \
echo ''; \
printf " %-$${LONGEST}s %s\n" "Frontend:" "https://$(HOST)/"; \
printf " %-$${LONGEST}s %s\n" "Frontend2:" "https://$(HOST2)/"; \
printf " %-$${LONGEST}s %s\n" "Backend:" "https://$(HOST)/typo3/"; \
printf " %-$${LONGEST}s %s\n" "Mail:" "https://$(MAIL)/"; \
## 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 $(HOST) | grep 127.0.0.1 > /dev/null; echo $$?)" -eq 0 ]; then sudo bash -c 'echo "127.0.0.1 $(HOST)" >> /etc/hosts; echo "Entry was added"'; else echo 'Entry already exists'; fi;\
if [ ! "$$($$SERVICES $(HOST2) | grep 127.0.0.1 > /dev/null; echo $$?)" -eq 0 ]; then sudo bash -c 'echo "127.0.0.1 $(HOST2)" >> /etc/hosts; echo "Entry was added"'; else echo 'Entry already exists'; fi;\
if [ ! "$$($$SERVICES $(MAIL) | grep 127.0.0.1 > /dev/null; echo $$?)" -eq 0 ]; then sudo bash -c 'echo "127.0.0.1 $(MAIL)" >> /etc/hosts; echo "Entry was added"'; else echo 'Entry already exists'; fi;
## Log into the PHP container
login-php:
echo "$(EMOJI_elephant) Logging into the PHP container"
docker-compose exec php bash
## Log into the mysql container
login-mysql:
echo "$(EMOJI_dolphin) Logging into MySQL Container"
docker-compose exec mysql bash
## Set correct onwership of mounts. Docker creates mounts owned by root:root.
.fix-mount-perms:
ifeq ($(shell uname -s), Darwin)
echo "$(EMOJI_rocket) Fixing docker mount permissions"
docker-compose exec -u root php chown -R app:app /app/$(TYPO3_CACHE_DIR)/;
endif
include .env
# SETTINGS
TARGET_MAX_CHAR_NUM := 25
MAKEFLAGS += --silent
SHELL := /bin/bash
VERSION := 1.0.0
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
BLUE := $(shell tput -Txterm setaf 4)
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_milky_way := "๐"
EMOJI_triangular_flag := "๐ฉ"