-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
327 lines (267 loc) · 12 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
# detect compose version
ifeq ($(OS),Windows_NT)
DOCKER_COMPOSE=docker compose
else
ifneq ($(shell docker compose version 2>/dev/null),)
DOCKER_COMPOSE=docker compose
else
DOCKER_COMPOSE=docker-compose
endif
endif
# pull up dev environment from scratch
dev: env-file-dev composer-install npm-install use-dev-file cache-clear permissions key-generate sail-up-deattached npm-run-dev-deattached wait-mysql db-regenerate
#pull up prd environment from scratch (please use make env-file-prd and edit your .env file, then run this!)
prd-locl: composer-install npm-install npm-build-prd use-prd-locl-file key-generate prd-up-locl
#pull up prd environment from scratch (please use make env-file-prd and edit your .env file, then run this!)
prd: use-prd-file key-generate prd-up
# Make .env
env-file-dev:
cp .env.dev.example .env
# Make .env
env-file-prd:
cp .env.prd.example .env
# Install PHP Dependencies via Composer usage make composer-command command="insert command"
composer-command:
docker run --rm --name compose-maintainence --interactive \
--volume $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/app \
--user $(shell id -u):$(shell id -g) \
composer $(command)
# Install PHP Dependencies via Composer
composer-install:
docker run --rm --name compose-maintainence --interactive \
--volume $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/app \
--user $(shell id -u):$(shell id -g) \
composer install --ignore-platform-reqs --no-scripts
# require PHP Dependencies via Composer usage make composer-require module=modulename
composer-require:
docker run --rm --name compose-maintainence --interactive \
--volume $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/app \
--user $(shell id -u):$(shell id -g) composer require $(module) --ignore-platform-reqs --no-scripts
# remove PHP Dependencies via Composer usage make composer-remove module=modulename
composer-remove:
docker run --rm --name compose-maintainence --interactive \
--volume $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/app \
--user $(shell id -u):$(shell id -g) composer remove $(module)
# check for outdated PHP Dependencies via Composer
composer-outdated:
docker run --rm --name compose-maintainence --interactive \
--volume $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/app \
--user $(shell id -u):$(shell id -g) composer outdated
# check for outdated PHP Dependencies via Composer
composer-update:
docker run --rm --name compose-maintainence --interactive \
--volume $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/app \
--user $(shell id -u):$(shell id -g) composer update --ignore-platform-reqs --no-scripts
# link dev no Proxy Compose file
use-dev-file:
[ -f docker-compose.yml ] && rm -rf docker-compose.yml ; true
docker run --rm --name devfile --interactive \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/app \
--user $(shell id -u):$(shell id -g) php:8-fpm-alpine /bin/sh -c "cd /app && php artisan sail:install --with mysql,redis,meilisearch,selenium"
# link prd no Proxy Compose file
use-prd-file:
[ -f docker-compose.yml ] && rm -rf docker-compose.yml ; true
ln -s docker-compose_prd.yml docker-compose.yml
# link prd locl no Proxy Compose file
use-prd-locl-file:
[ -f docker-compose.yml ] && rm -rf docker-compose.yml ; true
ln -s docker-compose_prd_locl.yml docker-compose.yml
# Permissions - docker Dev
permissions:
chown -R 1000:1000 storage bootstrap/cache
chown -R 1000:1000 .env
chgrp -R 1000 storage bootstrap/cache
chmod -R ug+rwx storage bootstrap/cache
# Permissions custom - usage make permissions-custom user=username group=groupname
permissions-custom:
chown -R $(user):$(group) storage bootstrap/cache
chgrp -R $(group) storage bootstrap/cache
chmod -R ug+rwx storage bootstrap/cache
# clear cache
cache-clear:
docker run --rm --name compkeygen --interactive \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/app \
--user $(shell id -u):$(shell id -g) php:8-fpm-alpine /bin/sh -c "cd /app && php artisan cache:clear && rm -rf bootstrap/cache/*.php"
#sail shell
sail-shell:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail shell
#sail up
sail-up:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail up
#sail down
sail-down:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail down
#sail up deattached
sail-up-deattached:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail up -d
#sail ps
sail-ps:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail ps
#sail logs
sail-logs:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail logs
#sail logs
sail-logs-follow:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail logs -f
#sail command - usage make sail-command command="artisan migrate"
sail-command:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail $(command)
#sail migrate
sail-migrate:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail artisan migrate
#sail artisan test
test:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail artisan test
#sail artisan test - usage make test-specific test="ExampleTest"
test-specific:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail artisan test --filter $(test)
#sail artisan test coverage
test-coverage:
$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/vendor/laravel/sail/bin/sail artisan test --coverage
#test coverage docker
test-coverage-docker:
docker run --rm --name compkeygen --interactive \
-e DB_CONNECTION="sqlite" -e DB_DATABASE="db/database.sqlite" \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/app \
--user $(shell id -u):$(shell id -g) jitesoft/phpunit:latest /bin/sh -c "cd /app && mkdir -p db && touch db/database.sqlite && php artisan test --coverage; rm -rf db"
prd-up-locl:
$(DOCKER_COMPOSE) up -d --build
prd-up:
$(DOCKER_COMPOSE) up -d
# Install JS Dependencies via NPM "make npm-install module=modulename" or "make npm-install"
npm-install:
docker run --rm --name js-maintainence --interactive \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
-w /usr/src/app \
node:latest /bin/bash -ci "npm install $(module) --no-audit"
npm-run-prd:
docker run --rm --name js-run-prd --interactive \
--network host \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
-w /usr/src/app \
node:latest /bin/bash -ci "npm run production"
npm-stop-prd:
docker stop js-run-prd || true
npm-build-prd:
docker run --rm --name js-run-prd --interactive \
--network host \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
-w /usr/src/app \
node:latest /bin/bash -ci "npm run build"
npm-run-prd-deattached:
docker run --rm -d --name js-run-prd --interactive \
--network host \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
-w /usr/src/app \
node:latest /bin/bash -ci "npm run production"
npm-run-dev:
docker run --rm --name js-run-dev --interactive \
--network host \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
-w /usr/src/app \
node:latest /bin/bash -ci "npm run dev"
npm-stop-dev:
docker stop js-run-dev || true
npm-run-dev-deattached:
docker run --rm -d --name js-run-dev --interactive \
--network host \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
-w /usr/src/app \
node:latest /bin/bash -ci "npm run dev"
# List outdated npm dependencies
npm-outdated:
docker run --rm --name js-maintainence-dev --interactive \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
-w /usr/src/app \
node:latest /bin/bash -ci "npm outdated"
# update outdated npm dependencies usage either "make npm-update module=modulename" or "make npm-update"
npm-update:
docker run --rm --name js-maintainence-dev --interactive \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
-w /usr/src/app \
node:latest /bin/bash -ci "npm update $(module)"
# update outdated npm dependencies and save usage either "make npm-update module=modulename" or "make npm-update"
npm-update-save:
docker run --rm --name js-maintainence-dev --interactive \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
-w /usr/src/app \
node:latest /bin/bash -ci "npm update $(module) --save"
# rollback all migrations (DELETES EVERYTHING!!!) and migrating and seeding database
db-regenerate:
./vendor/laravel/sail/bin/sail artisan migrate:reset \
&& ./vendor/laravel/sail/bin/sail artisan migrate \
&& ./vendor/laravel/sail/bin/sail artisan db:seed
# execute mysql command usage make database-command command=sqlcommandhere
db-command:
echo "use pull-journal-central; $(command)" | $(DOCKER_COMPOSE) exec -T mysql mysql -u pull-journal-centraluser -p'password'
# Purge Containers
purge-containers: npm-stop-dev npm-stop-prd
$(DOCKER_COMPOSE) down || true
$(DOCKER_COMPOSE) rm || true
docker volume rm pull-journal-central_sail-meilisearch || true
docker volume rm pull-journal-central_sail-mysql || true
docker volume rm pull-journal-central_sail-redis || true
# Purge Caches
purge-cache:
docker run --rm --name purgecache --interactive \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/src \
$(user) php:8-fpm-alpine /bin/sh -c " \
rm -rf /src/storage/framework/cache/* && \
rm -rf /src/storage/framework/views/* && \
rm -rf /src/storage/framework/sessions/* && \
rm -rf /src/bootstrap/cache/* && \
rm -rf /src/storage/debugbar/* "
# Purge Files
purge-files:
docker run --rm --name purgefiles --interactive \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/src \
$(user) php:8-fpm-alpine /bin/sh -c " \
rm -rf /src/vendor/ ; \
rm -rf /src/node_modules/ ; \
rm -rf /src/public/css/* ; \
rm -rf /src/storage/logs/* ; \
rm -rf /src/public/storage || true"
###############
# DANGER ZONE #
###############
# Clean ALL! DANGEROUS!
purge-all:
echo 'This is dangerous!'
echo 'This will totally remove all data and information stored in your app!'
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
make purge-all-force
purge-all-force: purge-containers purge-cache purge-files
show-laravellog-prd:
$(DOCKER_COMPOSE) exec -T pull-journal-central /bin/sh -c "cat storage/logs/laravel.log"
follow-laravellog-prd:
$(DOCKER_COMPOSE) exec -T pull-journal-central /bin/sh -c "tail -f storage/logs/laravel.log"
#generate key:
key-generate:
docker run --rm --name compkeygen --interactive \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/app \
--user $(shell id -u):$(shell id -g) php:8-fpm-alpine /bin/sh -c "cd /app && php artisan key:generate"
get-wait:
ifneq ("$(wildcard $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/docker/resources/wait)","")
echo "wait exists"
else
docker run --rm --name mysqlwaiter --interactive --network="pull-journal-central_sail" \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
$(user) php:8-fpm-alpine /bin/sh -c " \
wget -O /usr/src/app/docker/resources/wait https://github.com/ufoscout/docker-compose-wait/releases/latest/download/wait && \
chmod +x /usr/src/app/docker/resources/wait"
endif
# Wait for mysql to initialize
wait-mysql: get-wait
docker run --rm --name mysqlwaiter --interactive --network="pull-journal-central_sail" \
-e WAIT_HOSTS="pull-journal-central-mysql-1:3306" \
-v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))):/usr/src/app \
$(user) php:8-fpm-alpine /bin/sh -c " \
/usr/src/app/docker/resources/wait &&\
sleep 45"
# Build docs container
docs-build:
docker pull sphinxdoc/sphinx:latest
docker build -t pull-journal-central_docs docs
# Make Documentation
docs-html:
docker run --rm -v $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/docs:/docs pull-journal-central_docs make html