-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathMakefile
876 lines (809 loc) · 30.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
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
ifndef APPLICATION_CONFIG
# Determine which .env file to use
ifneq ("$(wildcard .env.local)", "")
include .env.local
else
include .env
endif
endif
ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif
# Define used JWT keys paths and passphrase
JWT_PUBLIC_KEY=$$(echo | jq -r .JWT_PUBLIC_KEY ${APPLICATION_CONFIG})
JWT_SECRET_KEY=$$(echo | jq -r .JWT_SECRET_KEY ${APPLICATION_CONFIG})
JWT_PASSPHRASE=$$(echo | jq -r .JWT_PASSPHRASE ${APPLICATION_CONFIG})
ifdef GITHUB_WORKFLOW
INSIDE_DOCKER_CONTAINER = 1
else ifneq ("$(wildcard /.dockerenv)", "")
INSIDE_DOCKER_CONTAINER = 1
else
INSIDE_DOCKER_CONTAINER = 0
endif
# Global variables that we're using
HOST_UID := $(shell id -u)
HOST_GID := $(shell id -g)
CONSOLE := $(shell which bin/console)
OPENSSL_BIN := $(shell which openssl)
PHPDBG := $(shell which phpdbg)
COMPOSER_BIN := $(shell which composer)
DOCKER := $(shell which docker)
CONTAINER_PREFIX := 'symfony-backend' # Check your `compose.yaml` file `container_name` property for this one
CONTAINER_COUNT := 5 # Check your `compose.yaml` file service count for this one
ifdef DOCKER
RUNNING_SOME_CONTAINERS := $(shell docker ps -f name=$(CONTAINER_PREFIX) | grep -c $(CONTAINER_PREFIX))
TEMP := $(shell docker ps -f name=$(CONTAINER_PREFIX) | grep -c $(CONTAINER_PREFIX) | grep $(CONTAINER_COUNT))
else
RUNNING_SOME_CONTAINERS := 0;
TEMP := 0
endif
ifeq ($(INSIDE_DOCKER_CONTAINER)$(TEMP), $(addprefix 0, $(CONTAINER_COUNT)))
RUNNING_ALL_CONTAINERS = 1
else
RUNNING_ALL_CONTAINERS = 0;
endif
ERROR_DOCKER = @printf "\033[31mSeems like that all necessary Docker containers are not running atm.\nCheck logs for detailed information about the reason of this\033[39m\n"
NOTICE_HOST = @printf "\033[33mRunning command from host machine by using 'docker compose exec' command\033[39m\n"
WARNING_HOST = @printf "\033[31mThis command cannot be run inside docker container!\033[39m\n"
WARNING_DOCKER = @printf "\033[31mThis command must be run inside specified docker container and it's not\nrunning atm. Use \`make start\` and/or \`make daemon\` command to get\nnecessary container(s) running and after that run this command again.\033[39m\n"
WARNING_DOCKER_RUNNING = @printf "\033[31mDocker is already running - you cannot execute this command multiple times\033[39m\n"
ALL_DONE = @printf $(_TITLE) "All done" "Have a nice day"
_WARNING := "\033[33m[%s]\033[0m %s\n" # Yellow text for "printf"
_TITLE := "\033[32m[%s]\033[0m %s\n" # Green text for "printf"
_ERROR := "\033[31m[%s]\033[0m %s\n" # Red text for "printf"
info_msg := Message
info:
$(info_msg)
.DEFAULT_GOAL := help
help:
@echo "\033[34mList of available commands:\033[39m"
@grep -E '^[a-zA-Z-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "[32m%-27s[0m %s\n", $$1, $$2}'
configuration: ## Prints out application current configuration
configuration: info_msg := @printf $(_TITLE) "OK" "Application configuration:"
configuration: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@echo | jq -r . ${APPLICATION_CONFIG}
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make configuration
$(ALL_DONE)
endif
cache-clear: ## Clears the cache
cache-clear: info_msg := @printf $(_TITLE) "OK" "Clearing application cache"
cache-clear: info
ifdef CONSOLE
@bin/console cache:clear --no-warmup
$(ALL_DONE)
else
@rm -rf var/cache/*
endif
cache-warmup: cache-clear ## Warms up an empty cache
cache-warmup: info_msg := @printf $(_TITLE) "OK" "Warming up cache"
cache-warmup: info
ifdef CONSOLE
@bin/console cache:warmup
$(ALL_DONE)
else
@printf "Cannot warm up the cache (needs symfony/console).\n"
endif
generate-jwt-keys: ## Generates JWT auth keys
generate-jwt-keys: info_msg := @printf $(_TITLE) "OK" "Generating JWT authentication keys"
generate-jwt-keys: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@echo "\033[32mGenerating RSA keys for JWT\033[39m"
@mkdir -p config/jwt
@rm -f ${JWT_SECRET_KEY}
@rm -f ${JWT_PUBLIC_KEY}
@openssl genrsa -passout pass:${JWT_PASSPHRASE} -out ${JWT_SECRET_KEY} -aes256 4096
@openssl rsa -passin pass:${JWT_PASSPHRASE} -pubout -in ${JWT_SECRET_KEY} -out ${JWT_PUBLIC_KEY}
@chmod 644 ${JWT_SECRET_KEY}
@chmod 644 ${JWT_PUBLIC_KEY}
@echo "\033[32mRSA key pair successfully generated\033[39m"
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make generate-jwt-keys
$(ALL_DONE)
endif
run-tests: ## Runs all tests via phpunit (Uses phpdbg if that is installed)
ifndef PHPDBG
@${MAKE} run-tests-php
else
@${MAKE} run-tests-phpdbg
endif
run-tests-fastest: ## Runs all test via fastest (Uses phpdbg if that is installed)
ifndef PHPDBG
@${MAKE} run-tests-fastest-php
else
@${MAKE} run-tests-fastest-phpdbg
endif
run-tests-php: ## Runs all tests via phpunit (pure PHP)
run-tests-php: info_msg := @printf $(_TITLE) "OK" "Running tests via phpunit (pure PHP)"
run-tests-php: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php ./vendor/bin/phpunit --version
@rm -rf build/logs
@mkdir -p build/logs
@rm -rf ./var/cache/test*
@bin/console cache:warmup --env=test
@./vendor/bin/phpunit --coverage-clover build/logs/clover.xml --log-junit build/logs/junit.xml
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make run-tests-php
$(ALL_DONE)
endif
run-tests-phpdbg: ## Runs all tests via phpunit (phpdbg)
run-tests-phpdbg: info_msg := @printf $(_TITLE) "OK" "Running test with PhpUnit in single thread (phpdbg)"
run-tests-phpdbg: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php ./vendor/bin/phpunit --version
@rm -rf build/logs
@mkdir -p build/logs
@rm -rf ./var/cache/test*
@bin/console cache:warmup --env=test
@phpdbg -qrr ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml --log-junit build/logs/junit.xml
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make run-tests-phpdbg
$(ALL_DONE)
endif
run-tests-fastest-php: ## Runs all test via fastest (pure PHP)
run-tests-fastest-php: info_msg := @printf $(_TITLE) "OK" "Running tests with liuggio/fastest + PhpUnit in multiple threads (pure PHP)"
run-tests-fastest-php: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@rm -rf build/fastest
@mkdir -p build/fastest
@rm -rf ./var/cache/test*
@bin/console cache:warmup --env=test
@find tests/ -name "*Test.php" | php ./vendor/bin/fastest -v -p 8 -o -b "php ./tests/bootstrap_fastest.php" "php ./vendor/bin/phpunit {} -c phpunit.fastest.xml --coverage-php build/fastest/{n}.cov --log-junit build/fastest/{n}.xml";
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make run-tests-fastest-php
$(ALL_DONE)
endif
run-tests-fastest-phpdbg: ## Runs all test via fastest (phpdbg)
run-tests-fastest-phpdbg: info_msg := @printf $(_TITLE) "OK" "Running tests with liuggio/fastest + PhpUnit in multiple threads (phpdbg)"
run-tests-fastest-phpdbg: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@rm -rf build/fastest
@mkdir -p build/fastest
@rm -rf ./var/cache/test*
@bin/console cache:warmup --env=test
@find tests/ -name "*Test.php" | php ./vendor/bin/fastest -v -p 8 -o -b "php ./tests/bootstrap_fastest.php" "phpdbg -qrr -d memory_limit=4096M ./vendor/bin/phpunit {} -c phpunit.fastest.xml --coverage-php build/fastest/{n}.cov --log-junit build/fastest/{n}.xml";
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make run-tests-fastest-phpdbg
$(ALL_DONE)
endif
report-fastest: ## Creates clover and JUnit xml from fastest run
report-fastest: info_msg := @printf $(_TITLE) "OK" "Creating clover and JUnit xml from fastest run"
report-fastest: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@rm -rf build/logs
@mkdir -p build/logs
@./vendor/bin/phpcov merge ./build/fastest/ --clover=./build/logs/clover.xml --html ./build/report/
@php merge-phpunit-xml.php ./build/fastest/ ./build/logs/junit.xml
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make report-fastest
$(ALL_DONE)
endif
infection: ## Runs Infection to codebase
infection: info_msg := @printf $(_TITLE) "OK" "Running Infection to codebase (pure PHP)"
infection: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@mkdir -p build/infection
@bin/console cache:clear --env=test
@./vendor/bin/infection --threads=8 --only-covered --show-mutations --test-framework-options="--testsuite=Functional,Integration,Unit"
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make infection
$(ALL_DONE)
endif
phpmetrics: ## Generates PhpMetrics static analysis
phpmetrics: info_msg := @printf $(_TITLE) "OK" "Generating PhpMetrics static analysis"
phpmetrics: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@mkdir -p build/phpmetrics
@if [ ! -f build/logs/junit.xml ] ; then \
printf $(_WARNING) "Warning" "clover.xml not found, need to run tests before this..." ; \
make -s run-tests; \
printf $(_TITLE) "OK" "Generating PhpMetrics static analysis" ; \
fi;
@php ./vendor/bin/phpmetrics --version
@./vendor/bin/phpmetrics --junit=build/logs/junit.xml --report-html=build/phpmetrics .
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make phpmetrics
endif
phpcs: ## Runs PHP CodeSniffer
phpcs: info_msg := @printf $(_TITLE) "OK" "Running PHP CodeSniffer"
phpcs: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php ./vendor/bin/phpcs --version
@php ./vendor/bin/phpcs --standard=PSR2 --colors -p src tests
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make phpcs
$(ALL_DONE)
endif
ecs: ## Runs The Easiest Way to Use Any Coding Standard
ecs: info_msg := @printf $(_TITLE) "OK" "Running EasyCodingStandard"
ecs: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php ./vendor/bin/ecs --version
@php ./vendor/bin/ecs --clear-cache check src tests
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make ecs
$(ALL_DONE)
endif
ecs-fix: ## Runs The Easiest Way to Use Any Coding Standard to fix issues
ecs-fix: info_msg := @printf $(_TITLE) "OK" "Running EasyCodingStandard with --fix option"
ecs-fix: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php ./vendor/bin/ecs --version
@php ./vendor/bin/ecs --clear-cache --fix check src tests
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make ecs-fix
$(ALL_DONE)
endif
phpinsights: ## Runs PHP Insights
phpinsights: info_msg := @printf $(_TITLE) "OK" "Running PHP Insights"
phpinsights: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php -d error_reporting=0 ./vendor/bin/phpinsights analyse --no-interaction --min-quality=95 --min-complexity=85 --min-architecture=100 --min-style=100
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make phpinsights
$(ALL_DONE)
endif
phplint: ## Runs PHPLint
phplint: info_msg := @printf $(_TITLE) "OK" "Running PHPLint"
phplint: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php ./vendor/bin/phplint --no-cache
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make phplint
$(ALL_DONE)
endif
php-parallel-lint: ## Lint PHP files with `php-parallel-lint`
php-parallel-lint: info_msg := @printf $(_TITLE) "OK" "php-parallel-lint"
php-parallel-lint: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@./vendor/bin/parallel-lint --exclude .git --exclude app --exclude tools --exclude var --exclude vendor --colors --show-deprecated --blame .
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make php-parallel-lint
$(ALL_DONE)
endif
psalm: ## Runs Psalm static analysis tool
psalm: info_msg := @printf $(_TITLE) "OK" "Running Psalm - A static analysis tool for PHP"
psalm: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@mkdir -p build
@@bin/console cache:clear
@php ./vendor/bin/psalm --version
@php ./vendor/bin/psalm --no-cache --report=./build/psalm.json
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make psalm
$(ALL_DONE)
endif
psalm-shepherd: ## Runs Psalm static analysis tool + report results to shepherd
psalm-shepherd: info_msg := @printf $(_TITLE) "OK" "Running Psalm - A static analysis tool for PHP"
psalm-shepherd: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@mkdir -p build
@@bin/console cache:clear
@php ./vendor/bin/psalm --version
@php ./vendor/bin/psalm --no-cache --shepherd --show-info=true --report=./build/psalm.json
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make psalm-shepherd
$(ALL_DONE)
endif
psalm-github: ## Runs Psalm static analysis tool (GitHub)
psalm-github: info_msg := @printf $(_TITLE) "OK" "Running Psalm - A static analysis tool for PHP"
psalm-github: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@mkdir -p build
@@bin/console cache:clear
@php ./vendor/bin/psalm --version
@php ./vendor/bin/psalm --no-cache --shepherd --show-info=true --report=./build/psalm.json --output-format=github
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make psalm-github
$(ALL_DONE)
endif
phpstan: ## Runs PHPStan static analysis tool
phpstan: info_msg := @printf $(_TITLE) "OK" "Running PHPStan - PHP Static Analysis Tool"
phpstan: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@@bin/console cache:clear
@./vendor/bin/phpstan --version
@./vendor/bin/phpstan -v
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make phpstan
$(ALL_DONE)
endif
phpstan-github: ## Runs PHPStan static analysis tool (GitHub)
phpstan-github: info_msg := @printf $(_TITLE) "OK" "Running PHPStan - PHP Static Analysis Tool"
phpstan-github: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@@bin/console cache:clear
@./vendor/bin/phpstan --version
@./vendor/bin/phpstan -v --error-format=github
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make phpstan
$(ALL_DONE)
endif
lint-configuration: ## Lint current defined `application.json` that it contains valid JSON
lint-configuration: info_msg := @printf $(_TITLE) "OK" "Linting application current configuration"
lint-configuration: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php -r "if (!json_decode(file_get_contents('${APPLICATION_CONFIG}'))) { echo \"\033[31mInvalid JSON in configuration file '${APPLICATION_CONFIG}'\033[39m\n\"; exit(1); } else { echo \"\033[32mNo errors in configuration file '${APPLICATION_CONFIG}'\033[39m\n\"; }"
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make lint-configuration
$(ALL_DONE)
endif
lint-yaml: ## Lint config YAML files
lint-yaml: info_msg := @printf $(_TITLE) "OK" "Linting YAML config files"
lint-yaml: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@@bin/console lint:yaml config --parse-tags
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make lint-yaml
$(ALL_DONE)
endif
clear: ## Clean vendor and tool dependencies
clear: info_msg := @printf $(_TITLE) "OK" "Clearing vendor dependencies"
clear: info
@rm -rf vendor
@${MAKE} clear-tools
clear-tools: ## Clears all tools dependencies
clear-tools: info_msg := @printf $(_TITLE) "OK" "Clearing tools dependencies"
clear-tools: info
@find -type d -name vendor | grep tools | xargs rm -rf
@printf $(_TITLE) "OK" "remember to restart your containers after this"
$(ALL_DONE)
check-dependencies-latest: ## Checks if any vendor dependency can be updated (latest versions)
check-dependencies-latest: info_msg := @printf $(_TITLE) "OK" "Checking vendor dependencies (latest)"
check-dependencies-latest: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@bin/console check-dependencies
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make check-dependencies-latest
$(ALL_DONE)
endif
check-dependencies-minor: ## Checks if any vendor dependency can be updated (only minor versions)
check-dependencies-minor: info_msg := @printf $(_TITLE) "OK" "Checking vendor dependencies (minor)"
check-dependencies-minor: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@bin/console check-dependencies --minor
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make check-dependencies-minor
$(ALL_DONE)
endif
check-dependencies-patch: ## Checks if any vendor dependency can be updated (only patch versions)
check-dependencies-patch: info_msg := @printf $(_TITLE) "OK" "Checking vendor dependencies (patch)"
check-dependencies-patch: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@bin/console check-dependencies --patch
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make check-dependencies-patch
$(ALL_DONE)
endif
check-licenses: ## Check vendor licenses
check-licenses: info_msg := @printf $(_TITLE) "OK" "Checking vendor licenses"
check-licenses: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@composer license | awk '{ print $$3 }' | sort | uniq -c | sort -rn
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make check-licenses
$(ALL_DONE)
endif
update: ## Update composer dependencies
update: info_msg := @printf $(_TITLE) "OK" "Updating composer dependencies"
update: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php -d memory_limit=-1 /usr/bin/composer update --with-all-dependencies --optimize-autoloader
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make update
$(ALL_DONE)
endif
update-tools: ## Update composer tools dependencies
update-tools: info_msg := @printf $(_TITLE) "OK" "Updating composer tools dependencies"
update-tools: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php -d memory_limit=-1 $(COMPOSER_BIN) bin all update --no-progress --optimize-autoloader
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make update-tools
$(ALL_DONE)
endif
install-tools: ## Install composer tools dependencies
install-tools: info_msg := @printf $(_TITLE) "OK" "Installing composer tools dependencies"
install-tools: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php -d memory_limit=-1 $(COMPOSER_BIN) bin all install --no-progress --optimize-autoloader
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make install-tools
$(ALL_DONE)
endif
bash: ## Get bash inside PHP container
bash: info_msg := @printf $(_TITLE) "OK" "Opening bash shell to PHP container"
bash: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php bash
endif
fish: ## Get fish inside PHP container
fish: info_msg := @printf $(_TITLE) "OK" "Opening fish shell to PHP container"
fish: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php fish
endif
logs: ## Show logs from all containers
logs: info_msg := @printf $(_TITLE) "OK" "Showing logs from all the containers"
logs: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose logs --follow php nginx mariadb
endif
daemon: ## Start application in development mode in background
daemon: info_msg := @printf $(_TITLE) "OK" "Starting application in development mode in background"
daemon: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else ifneq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER_RUNNING)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose up --detach
@printf $(_TITLE) "OK" "Containers are running background, check logs for detailed information!"
endif
daemon-build: ## Build containers and start application in development mode in background
daemon-build: info_msg := @printf $(_TITLE) "OK" "Building containers and starting application in development mode in background"
daemon-build: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else ifneq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER_RUNNING)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose up --build --detach
@printf $(_TITLE) "OK" "Containers are built and those are running background, check logs for detailed information!"
endif
stop: ## Stop application containers
stop: info_msg := @printf $(_TITLE) "OK" "Stopping application containers"
stop: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose down
$(ALL_DONE)
endif
start: ## Start application in development mode + watch output
start: info_msg := @printf $(_TITLE) "OK" "Starting application in development mode"
start: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else ifneq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER_RUNNING)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose up
$(ALL_DONE)
endif
start-build: ## Build containers and start application in development mode + watch output
start-build: info_msg := @printf $(_TITLE) "OK" "Building containers and starting application in development mode"
start-build: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else ifneq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER_RUNNING)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose up --build
$(ALL_DONE)
endif
local-configuration: ## Create local configuration files
local-configuration: info_msg := @printf $(_TITLE) "OK" "Creating local configuration"
local-configuration: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@cp /app/.env /app/.env.local
@cp /app/secrets/application.json /app/secrets/application.local.json
@sed -i "s/application\.json/application\.local\.json/g" .env.local
@printf $(_TITLE) "OK" "Local configuration created, just edit your new \`secrets/application.local.json\` file for your needs"
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make local-configuration
$(ALL_DONE)
endif
composer-normalize: ## Normalizes `composer.json` file content
composer-normalize: info_msg := @printf $(_TITLE) "OK" "Normalizing `composer.json` file contents"
composer-normalize: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@composer normalize
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make composer-normalize
$(ALL_DONE)
endif
composer-validate: ## Validate `composer.json` file content
composer-validate: info_msg := @printf $(_TITLE) "OK" "Validating `composer.json` file contents"
composer-validate: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@composer validate --no-check-version && ([ $$? -eq 0 ] && echo "\033[32mGood news, your \`composer.json\` file is valid\033[39m")
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make composer-validate
$(ALL_DONE)
endif
composer-require-checker: ## Check the defined dependencies against your code
composer-require-checker: info_msg := @printf $(_TITLE) "OK" "Checking defined dependecies against project code"
composer-require-checker: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@XDEBUG_MODE=off php /app/vendor/bin/composer-require-checker
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make composer-require-checker
$(ALL_DONE)
endif
composer-unused: ## Show unused packages by scanning and comparing package namespaces against your source
composer-unused: info_msg := @printf $(_TITLE) "OK" "Checking unused packages"
composer-unused: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@XDEBUG_MODE=off php /app/vendor/bin/composer-unused
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make composer-unused
$(ALL_DONE)
endif
phploc: ## Runs `phploc` and create json output
phploc: info_msg := @printf $(_TITLE) "OK" "Running PHPLOC"
phploc: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@php ./vendor/bin/phploc --log-json=./build/phploc.json ./src
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make phploc
$(ALL_DONE)
endif
check-security: ## Checks that application doesn't have installed dependencies with known security vulnerabilities
check-security: info_msg := @printf $(_TITLE) "OK" "Checking installed packages for known security vulnerabilities"
check-security: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@composer update --dry-run --no-plugins roave/security-advisories
@if which local-php-security-checker; then local-php-security-checker --update-cache && local-php-security-checker; fi
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make check-security
$(ALL_DONE)
endif
docker-prune: info_msg := @printf $(_ERROR) "Caution !!!" "Killing all running containers and pruning all docker stuff"
docker-prune: info
docker-prune: ## Kill all running containers and prune all docker stuff
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else
@echo -n "\033[31mAre you sure that you want to kill ALL running containers and prune ALL docker data? [y/N]\033[39m\n " && read ans && if [ $${ans:-'N'} = 'y' ]; then \
printf $(_TITLE) "OK" "Continuing with full system prune"; \
docker kill $$(docker ps -q) 2> /dev/null && docker system prune --all --volumes --force; \
printf $(_TITLE) "All done" "Have a nice day"; \
fi
endif
docker-kill-containers: ## Kill all running docker containers
docker-kill-containers: info_msg := @printf $(_TITLE) "OK" "Killing running docker containers"
docker-kill-containers: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker kill $$(docker ps -q)
$(ALL_DONE)
endif
docker-remove-containers: ## Remove all docker containers
docker-remove-containers: info_msg := @printf $(_TITLE) "OK" "Removing docker containers"
docker-remove-containers: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker rm $$(docker ps -a -q)
$(ALL_DONE)
endif
docker-remove-images: ## Remove all docker images
docker-remove-images: info_msg := @printf $(_TITLE) "OK" "Removing docker images"
docker-remove-images: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
$(WARNING_HOST)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker rmi $$(docker images -q)
$(ALL_DONE)
endif
generate-ssl-cert: ## Generate self signed SSL certificates
ifeq ($(INSIDE_DOCKER), 1)
$(WARNING_HOST)
else
@echo "\033[32mGenerating self signed SSL certificates\033[39m"
@cd docker/nginx/ssl && ./create-keys.sh
endif
project-stats: ## Create simple project stats
project-stats: info_msg := @printf $(_TITLE) "OK" "Creating simple project stats"
project-stats: info
ifeq ($(INSIDE_DOCKER_CONTAINER), 1)
@./scripts/project-stats.sh
else ifeq ($(RUNNING_SOME_CONTAINERS), 0)
$(WARNING_DOCKER)
else ifneq ($(RUNNING_ALL_CONTAINERS), 1)
$(ERROR_DOCKER)
else
$(NOTICE_HOST)
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker compose exec php make project-stats
$(ALL_DONE)
endif