-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
169 lines (136 loc) · 5.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
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
#
# For more information on some of the magic targets, variables and flags used, see:
# - [1] https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
# - [2] https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
# - [3] https://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html
# - [4] https://www.gnu.org/software/make/manual/html_node/Options-Summary.html
# - [5] https://www.gnu.org/software/make/manual/html_node/Special-Variables.html
# - [6] https://www.gnu.org/software/make/manual/html_node/Choosing-the-Shell.html
#
# Ensure (intermediate) targets are deleted when an error occurred executing a recipe, see [1]
.DELETE_ON_ERROR:
# Enable a second expansion of the prerequisites, see [2]
.SECONDEXPANSION:
# Disable built-in implicit rules and variables, see [3, 4]
.SUFFIXES:
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
# Disable printing of directory changes, see [4]
MAKEFLAGS += --no-print-directory
# Warn about undefined variables -- useful during development of makefiles, see [4]
MAKEFLAGS += --warn-undefined-variables
# Show an auto-generated help if no target is provided, see [5]
.DEFAULT_GOAL := help
# Default shell, see [6]
SHELL := /bin/bash
help:
@echo
@printf " %10s | %s\n" Target Description
@echo " ----------------------------"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%10s\033[0m | %s\n", $$1, $$2}'
@echo
#
# PROJECT TARGETS
#
# To learn more about automatic variables that can be used in target recipes, see:
# https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
#
PROJECT := phpbin
# Environment variable(s) for Symfony
export APP_ENV ?= dev
# Docker permissions (for Linux)
export DOCKER_UID ?= $(shell id -u)
export DOCKER_GID ?= $(shell id -g)
export DOCKER_USER ?= $(DOCKER_UID):$(DOCKER_GID)
#
# Docker-Compose Services & Containers
#
.PHONY: build
build: ## build containers
docker-compose --file docker-compose.yaml --file docker-compose.traefik.yaml --project-name $(PROJECT) \
build --pull
.PHONY: fg
fg: ## launch the docker-compose setup (foreground)
docker-compose --file docker-compose.yaml --file docker-compose.traefik.yaml --project-name $(PROJECT) \
up --remove-orphans
.PHONY: up
up: ## launch the docker-compose setup (background)
docker-compose --file docker-compose.yaml --file docker-compose.traefik.yaml --project-name $(PROJECT) \
up --remove-orphans --detach
.PHONY: down
down: ## terminate the docker-compose setup
-docker-compose --file docker-compose.yaml --file docker-compose.traefik.yaml --project-name $(PROJECT) \
down --remove-orphans
.PHONY: logs
logs: ## show logs
docker-compose --file docker-compose.yaml --file docker-compose.traefik.yaml --project-name $(PROJECT) \
logs
.PHONY: tail
tail: ## tail logs
docker-compose --file docker-compose.yaml --file docker-compose.traefik.yaml --project-name $(PROJECT) \
logs --follow
.PHONY: shell
shell: ## spawn a shell inside a new php-fpm container
docker-compose --project-name $(PROJECT) \
run --rm -e APP_ENV --user $(DOCKER_USER) --no-deps composer \
sh
.PHONY: enter
enter: ## spawn a shell inside a running php-fpm container
docker-compose --project-name $(PROJECT) \
exec -e APP_ENV --user $(DOCKER_USER) fpm \
sh
#
# Application related targets
#
.PHONY: install
install: composer.json
install: ## install dependencies (composer)
docker-compose --project-name $(PROJECT) \
run --rm -e APP_ENV --user $(DOCKER_USER) --no-deps composer \
composer install --no-interaction --no-progress --prefer-dist
.PHONY: update
update: composer.lock
update: ## update dependencies (composer)
docker-compose --project-name $(PROJECT) \
run --rm -e APP_ENV --user $(DOCKER_USER) --no-deps composer \
composer update --no-interaction --no-progress --prefer-dist
.PHONY: phpunit
phpunit: vendor/bin/phpunit
phpunit: export APP_ENV := test
phpunit: ## run phpunit test suite
docker-compose --project-name $(PROJECT) \
run --rm -e APP_ENV --user $(DOCKER_USER) --no-deps fpm \
bin/console cache:warmup
docker-compose --project-name $(PROJECT) \
run --rm -e APP_ENV --user $(DOCKER_USER) fpm \
vendor/bin/phpunit --colors=always --stderr --coverage-text --coverage-clover clover.xml
.PHONY: phpcsfixer
phpcsfixer: tools/php-cs-fixer/vendor/bin/php-cs-fixer
phpcsfixer: ## run php-cs-fixer
docker-compose --project-name $(PROJECT) \
run --rm -e APP_ENV -e PHP_CS_FIXER_IGNORE_ENV=true --user $(DOCKER_USER) --no-deps fpm \
tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --allow-risky=yes --diff
.PHONY: phpstan
phpstan: vendor/bin/phpstan
phpstan: export APP_ENV := dev
phpstan: ## run phpstan
docker-compose --project-name $(PROJECT) \
run --rm -e APP_ENV --user $(DOCKER_USER) --no-deps fpm \
vendor/bin/phpstan
#
# Path targets
#
composer.lock: composer.json
docker-compose --project-name $(PROJECT) \
run --rm -e APP_ENV --user $(DOCKER_USER) --no-deps composer \
composer update --no-interaction --no-progress --prefer-dist
vendor:
docker-compose --project-name $(PROJECT) \
run --rm -e APP_ENV --user $(DOCKER_USER) --no-deps composer \
composer install --no-interaction --no-progress --prefer-dist
vendor/bin/phpunit: vendor
vendor/bin/phpstan: vendor
tools/php-cs-fixer/vendor/bin/php-cs-fixer:
docker-compose --project-name $(PROJECT) \
run --rm -e APP_ENV --user $(DOCKER_USER) --no-deps composer \
composer --working-dir=tools/phpcsfixer install --no-interaction --no-progress --prefer-dist