-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
378 lines (302 loc) · 11.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
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
-include .env
# BuildKit enables higher performance docker builds and caching possibility
# to decrease build times and increase productivity for free.
# https://docs.docker.com/compose/environment-variables/envvars/
export DOCKER_BUILDKIT ?= 1
# Docker binary to use, when executing docker tasks
DOCKER ?= docker
# Binary to use, when executing docker-compose tasks
DOCKER_COMPOSE ?= $(DOCKER) compose
# Support image with all needed binaries, like envsubst, mkcert, wait4x
SUPPORT_IMAGE ?= wayofdev/build-deps:alpine-latest
APP_RUNNER ?= $(DOCKER_COMPOSE) run --rm --no-deps app
APP_COMPOSER ?= $(APP_RUNNER) composer
APP_EXEC ?= $(DOCKER_COMPOSE) exec app
BUILDER_PARAMS ?= docker run --rm -i \
--env-file ./.env \
--env APP_NAME=$(APP_NAME) \
--env SHARED_SERVICES_NAMESPACE=$(SHARED_SERVICES_NAMESPACE) \
--env COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \
--env COMPOSER_AUTH="$(COMPOSER_AUTH)"
BUILDER ?= $(BUILDER_PARAMS) $(SUPPORT_IMAGE)
BUILDER_WIRED ?= $(BUILDER_PARAMS) --network project.$(COMPOSE_PROJECT_NAME) $(SUPPORT_IMAGE)
# Shorthand wait4x command, executed through build-deps
WAITER ?= $(BUILDER_WIRED) wait4x
# Shorthand envsubst command, executed through build-deps
ENVSUBST ?= $(BUILDER) envsubst
# Yamllint docker image
YAML_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(PWD):/data \
cytopia/yamllint:latest \
-c ./.github/.yamllint.yaml \
-f colored .
ACTION_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(shell pwd):/repo \
--workdir /repo \
rhysd/actionlint:latest \
-color
MARKDOWN_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(shell pwd):/app \
--workdir /app \
davidanson/markdownlint-cli2-rules:latest \
--config ".github/.markdownlint.json"
PHIVE_RUNNER ?= $(DOCKER_COMPOSE) run --rm --no-deps app
EXPORT_VARS = '\
$${APP_NAME} \
$${COMPOSE_PROJECT_NAME} \
$${SHARED_SERVICES_NAMESPACE} \
$${COMPOSER_AUTH}'
#
# Self documenting Makefile code
# ------------------------------------------------------------------------------------
ifneq ($(TERM),)
BLACK := $(shell tput setaf 0)
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
YELLOW := $(shell tput setaf 3)
LIGHTPURPLE := $(shell tput setaf 4)
PURPLE := $(shell tput setaf 5)
BLUE := $(shell tput setaf 6)
WHITE := $(shell tput setaf 7)
RST := $(shell tput sgr0)
else
BLACK := ""
RED := ""
GREEN := ""
YELLOW := ""
LIGHTPURPLE := ""
PURPLE := ""
BLUE := ""
WHITE := ""
RST := ""
endif
MAKE_LOGFILE = /tmp/wayofdev-laravel-starter-tpl.log
MAKE_CMD_COLOR := $(BLUE)
default: all
help: ## Show this menu
@echo 'Management commands for project:'
@echo 'Usage:'
@echo ' ${MAKE_CMD_COLOR}make${RST} Prepares and spins up project with default settings'
@grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf " ${MAKE_CMD_COLOR}make %-21s${RST} %s\n", $$1, $$2}'
@echo
@echo ' 📑 Logs are stored in $(MAKE_LOGFILE)'
@echo
@echo ' 📦 Project laravel-starter-tpl (https://github.com/wayofdev/laravel-starter-tpl)'
@echo ' 🤠 Author Andrij Orlenko (https://github.com/lotyp)'
@echo ' 🏢 ${YELLOW}Org wayofdev (https://github.com/wayofdev)${RST}'
@echo
.PHONY: help
.EXPORT_ALL_VARIABLES:
#
# Default action
# Defines default command when `make` is executed without additional parameters
# ------------------------------------------------------------------------------------
all: hooks install key prepare up
.PHONY: all
#
# System Actions
# ------------------------------------------------------------------------------------
override-create: ## Generate override file from dist
cp -v docker-compose.override.yaml.dist docker-compose.override.yaml
.PHONY: override-create
env: ## Generate .env file from example, use `make env force=true`, to force re-create file
ifeq ($(FORCE),true)
@echo "${YELLOW}Force re-creating .env file from example...${RST}"
$(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
else ifneq ("$(wildcard ./.env)","")
@echo ""
@echo "${YELLOW}The .env file already exists! Use FORCE=true to re-create.${RST}"
else
@echo "Creating .env file from example"
$(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
endif
.PHONY: env
key: ## Runs artisan command to create app encryption key
$(APP_RUNNER) php artisan key:generate
.PHONY: key
prepare:
mkdir -p app/.build/php-cs-fixer
.PHONY: prepare
#
# Docker Actions
# ------------------------------------------------------------------------------------
up: # Creates and starts containers, defined in docker-compose and override file
$(DOCKER_COMPOSE) up --remove-orphans -d
@sleep 1
$(DOCKER_COMPOSE) exec app wait4x postgresql 'postgres://${DB_USERNAME}:${DB_PASSWORD}@database:5432/${DB_DATABASE}?sslmode=disable' -t 1m
.PHONY: up
down: # Stops and removes containers of this project
$(DOCKER_COMPOSE) down --remove-orphans
.PHONY: down
purge: ## Stops and removes containers, volumes, networks and images
$(DOCKER_COMPOSE) down --remove-orphans --volumes
$(DOCKER) network prune --force
$(DOCKER) volume prune --force
$(DOCKER) image prune --force
.PHONY: purge
restart: down up ## Runs down and up commands
.PHONY: restart
clean: ## Stops and removes containers of this project together with volumes
$(DOCKER_COMPOSE) rm --force --stop --volumes
.PHONY: clean
ps: ## List running project containers
$(DOCKER_COMPOSE) ps
.PHONY: ps
logs: ## Show project docker logs with follow up mode enabled
$(DOCKER_COMPOSE) logs -f
.PHONY: logs
pull: ## Pull and update docker images in this project
$(DOCKER_COMPOSE) pull
.PHONY: pull
ssh: ## Login inside running docker container
$(APP_EXEC) sh
.PHONY: ssh
#
# Composer Commands
# ------------------------------------------------------------------------------------
install: ## Install composer dependencies
$(APP_COMPOSER) install
.PHONY: install
update: ## Update composer dependencies
$(APP_COMPOSER) update $(package)
.PHONY: update
du: ## Dump composer autoload
$(APP_COMPOSER) dump-autoload
.PHONY: du
show: ## Shows information about installed composer packages
$(APP_COMPOSER) show
.PHONY: show
phive: ## Installs dependencies with phive
$(APP_RUNNER) /usr/local/bin/phive install --trust-gpg-keys 0xC00543248C87FB13,0x033E5F8D801A2F8D,0x47436587D82C4A39
.PHONY: phive
#
# Code Quality, Git, Linting
# ------------------------------------------------------------------------------------
hooks: ## Install git hooks from pre-commit-config
pre-commit install
pre-commit install --hook-type commit-msg
pre-commit autoupdate
.PHONY: hooks
lint: lint-yaml lint-actions lint-md lint-php lint-stan lint-composer lint-audit ## Runs all linting commands
.PHONY: lint
lint-yaml: ## Lints yaml files inside project
@$(YAML_LINT_RUNNER) | tee -a $(MAKE_LOGFILE)
.PHONY: lint-yaml
lint-actions: ## Lint all github actions
@$(ACTION_LINT_RUNNER) | tee -a $(MAKE_LOGFILE)
.PHONY: lint-actions
lint-md: ## Lint all markdown files using markdownlint-cli2
@$(MARKDOWN_LINT_RUNNER) --fix "**/*.md" "!CHANGELOG.md" "!app/vendor" "!app/node_modules" | tee -a $(MAKE_LOGFILE)
.PHONY: lint-md
lint-md-dry: ## Lint all markdown files using markdownlint-cli2 in dry-run mode
@$(MARKDOWN_LINT_RUNNER) "**/*.md" "!CHANGELOG.md" "!app/vendor" "!app/node_modules" | tee -a $(MAKE_LOGFILE)
.PHONY: lint-md-dry
lint-php: ## Lints php files inside project using php-cs-fixer
$(APP_COMPOSER) cs:fix
.PHONY: lint-php
lint-diff: ## Shows diff of php-cs-fixer
$(APP_COMPOSER) cs:diff
.PHONY: lint-diff
lint-stan:
$(APP_COMPOSER) stan
.PHONY: lint-stan
lint-stan-ci: ## Runs phpstan – static analysis tool with github output (CI mode)
$(APP_COMPOSER) stan:ci
.PHONY: lint-stan-ci
lint-stan-baseline: ## Runs phpstan to update its baseline
$(APP_COMPOSER) stan:baseline
.PHONY: lint-stan-baseline
lint-psalm: ## Runs vimeo/psalm – static analysis tool
$(APP_COMPOSER) psalm
.PHONY: lint-psalm
lint-psalm-ci: ## Runs vimeo/psalm – static analysis tool with github output (CI mode)
$(APP_COMPOSER) psalm:ci
.PHONY: lint-psalm-ci
lint-psalm-baseline: ## Runs vimeo/psalm to update its baseline
$(APP_COMPOSER) psalm:baseline
.PHONY: lint-psalm-baseline
lint-deps: ## Runs composer-require-checker – checks for dependencies that are not used
$(APP_RUNNER) .phive/composer-require-checker check \
--config-file=/app/composer-require-checker.json \
--verbose
.PHONY: lint-deps
lint-deptrac: ## Runs deptrac – static analysis tool
$(APP_RUNNER) .phive/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache
.PHONY: lint-deptrac
lint-deptrac-ci: ## Runs deptrac – static analysis tool with github output (CI mode)
$(APP_RUNNER) .phive/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter github-actions
.PHONY: lint-deptrac-ci
lint-deptrac-gv: ## Runs deptrac – static analysis tool and generates graphviz image
$(APP_RUNNER) .phive/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter graphviz-image --output /assets/deptrac.svg
.PHONY: lint-deptrac-gv
lint-composer: ## Normalize composer.json and composer.lock files
$(APP_RUNNER) .phive/composer-normalize normalize
.PHONY: lint-composer
lint-audit: ## Runs security checks for composer dependencies
$(APP_COMPOSER) audit --ansi
.PHONY: lint-security
validate-composer: ## Validates composer.json and composer.lock files
$(APP_COMPOSER) validate --ansi --strict
.PHONY: validate-composer
refactor: ## Runs rector – code refactoring tool
$(APP_COMPOSER) refactor
.PHONY: refactor
refactor-ci: ## Runs rector – code refactoring tool with github output (CI mode)
$(APP_COMPOSER) refactor:ci
.PHONY: refactor-ci
#
# Testing
# ------------------------------------------------------------------------------------
infect: ## Runs mutation tests with infection/infection
$(APP_COMPOSER) infect
.PHONY: infect
infect-ci: ## Runs infection – mutation testing framework with github output (CI mode)
$(APP_COMPOSER) infect:ci
.PHONY: lint-infect-ci
test: ## Run project Functional tests using pest
$(APP_COMPOSER) test
.PHONY: test
test-arch: ## Run project architecture tests using pest
$(APP_COMPOSER) test:arch
.PHONY: test-arch
test-all: test test-arch ## Run all project tests
.PHONY: test-all
test-cc: ## Run project php-unit and pest tests in coverage mode and build report
$(APP_COMPOSER) test:cc
.PHONY: test-cc
test-pgsql: ## Run project tests with postgresql
$(APP_COMPOSER) test:pgsql
.PHONY: test-pgsql
api-docs-public: ## Generate openapi docs specification file for public api
$(APP_EXEC) php artisan open-docs:generate public
.PHONY: api-docs-public
api-docs-admin: ## Generate openapi docs specification file for admin api
$(APP_EXEC) php artisan open-docs:generate admin
.PHONY: api-docs-admin
#
# Database Commands
# ------------------------------------------------------------------------------------
db-wipe: ## Wipe database
$(APP_EXEC) php artisan db:wipe
.PHONY: db-wipe
db-refresh: ## Delete migration files, wipe database, create new migrations, run them and seed database
$(APP_EXEC) php artisan migrate:fresh
.PHONY: db-refresh
db-migrate: ## Run all pending migrations
$(APP_EXEC) php artisan migrate
.PHONY: db-migrate
#
# Deployer Commands
# ------------------------------------------------------------------------------------
dep-staging:
$(APP_EXEC) vendor/bin/dep deploy staging
.PHONY: dep-staging
dep-prod:
$(APP_EXEC) vendor/bin/dep deploy prod
.PHONY: dep-prod
ssh-staging:
$(APP_EXEC) vendor/bin/dep ssh staging
.PHONY: ssh-staging
ssh-prod:
$(APP_EXEC) vendor/bin/dep ssh prod
.PHONY: ssh-prod