-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
100 lines (75 loc) · 5 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
#!/usr/bin/make
# Makefile readme (ru): <http://linux.yaroslavl.ru/docs/prog/gnu_make_3-79_russian_manual.html>
# Makefile readme (en): <https://www.gnu.org/software/make/manual/html_node/index.html#SEC_Contents>
SHELL = /bin/sh
php_container_name := php
docker_bin := $(shell command -v docker 2> /dev/null)
docker_compose_bin := $(shell command -v docker-compose 2> /dev/null)
docker_compose_yml := docker/docker-compose.yml
user_id := $(shell id -u)
.PHONY : help pull build push login test clean \
app-pull app app-push\
sources-pull sources sources-push\
nginx-pull nginx nginx-push\
up down restart shell install
.DEFAULT_GOAL := help
# --- [ Development tasks ] -------------------------------------------------------------------------------------------
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
build: check-environment ## Build containers
$(docker_compose_bin) --file "$(docker_compose_yml)" pull
$(docker_bin) pull ghcr.io/rehearsalsbooking/backend/php-base:latest
$(docker_compose_bin) --file "$(docker_compose_yml)" build
require: check-environment ## Build containers
$(docker_compose_bin) --file "$(docker_compose_yml)" run -e XDEBUG_MODE=off "$(php_container_name)" composer require $(filter-out $@,$(MAKECMDGOALS))
install: check-environment ## Install dependencies
$(docker_compose_bin) --file "$(docker_compose_yml)" run -e XDEBUG_MODE=off "$(php_container_name)" composer install
update: check-environment ## Update dependencies
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -e XDEBUG_MODE=off "$(php_container_name)" composer update
infection: check-environment ## Run infection
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -e XDEBUG_MODE=coverage "$(php_container_name)" vendor/bin/infection
test: check-environment ## Execute tests
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -e XDEBUG_MODE=off "$(php_container_name)" /bin/bash -c "php artisan test --parallel"
check-ci: check-environment composer-validate phpstan composer-require-check composer-unused ## Execute tests in ci
$(docker_compose_bin) --file "$(docker_compose_yml)" run -e XDEBUG_MODE=coverage --rm "$(php_container_name)" /bin/bash -c "php artisan test --parallel --coverage-clover=/shared/coverage.xml"
phpstan: check-environment ## Run phpstan
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -e XDEBUG_MODE=off "$(php_container_name)" php -d memory_limit=4G vendor/bin/phpstan analyse
composer-validate: ## Validate composer file
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -e XDEBUG_MODE=off "$(php_container_name)" composer validate --strict
composer-require-check: ## Check soft dependencies
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -e XDEBUG_MODE=off "$(php_container_name)" composer-require-checker check --config-file=composer-require-checker.json
composer-unused: ## Check soft dependencies
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -e XDEBUG_MODE=off "$(php_container_name)" vendor/bin/composer-unused --excludePackage=sentry/sentry-laravel
check: check-environment composer-validate test phpstan composer-require-check composer-unused ## Run tests and code analysis
shell: check-environment ## Run shell environment in container
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -u $(user_id) "$(php_container_name)" /bin/bash
shell-root: check-environment ## Run shell environment in container
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm "$(php_container_name)" /bin/bash
docs: check-environment ## Generate docs for models
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -u $(user_id) "$(php_container_name)" /bin/bash -c "php artisan migrate:fresh"
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -u $(user_id) "$(php_container_name)" /bin/bash -c "php /app/artisan ide-helper:models -W"
tinker: check-environment ## Run tinker inside container
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm -u $(user_id) "$(php_container_name)" /bin/bash -c "php artisan tinker"
seed: check-environment ## Seeds db with dummy data
$(docker_compose_bin) --file "$(docker_compose_yml)" run --rm "$(php_container_name)" /bin/bash -c "php artisan migrate:fresh --seed"
stop-all: ## Stop all containers
$(docker_compose_bin) --file "$(docker_compose_yml)" down
stop-db: ## Stop db container
$(docker_bin) stop db-backend-rehearsals
$(docker_bin) rm db-backend-rehearsals
$(docker_bin) rm docker_db_1
# Check whether the environment file exists
check-environment:
ifeq ("$(wildcard .env)","")
- @echo Copying ".env.example";
- cp .env.example .env
endif
# Prompt to continue
prompt-continue:
@while [ -z "$$CONTINUE" ]; do \
read -r -p "Would you like to continue? [y]" CONTINUE; \
done ; \
if [ ! $$CONTINUE == "y" ]; then \
echo "Exiting." ; \
exit 1 ; \
fi