-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
126 lines (89 loc) · 5.98 KB
/
Copy pathMakefile
File metadata and controls
126 lines (89 loc) · 5.98 KB
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
# Executables (local)
DOCKER_COMP = docker compose
# Container repo
BUILD_REPO = benoitvignal/narvik-back
# Docker containers
PHP_CONT = $(DOCKER_COMP) exec php
DB_CONT = $(DOCKER_COMP) exec database
# Executables
PHP = $(PHP_CONT) php
COMPOSER = $(PHP_CONT) composer
SYMFONY = $(PHP) bin/console
# Misc
.DEFAULT_GOAL = help
.PHONY : help build up start down logs sh composer vendor sf cc rector rector-dry-run db-dump db-restore db-migrate code-quality
# Capture the first argument as `file`
file=$(word 2,$(MAKECMDGOALS))
## —— 🎵 🐳 The Symfony Docker Makefile 🐳 🎵 ——————————————————————————————————
help: ## Outputs this help screen
@grep -E '(^[a-zA-Z0-9\./_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
## —— Docker 🐳 ————————————————————————————————————————————————————————————————
build: ## Builds the Docker images
@$(DOCKER_COMP) build --pull --no-cache
build-cloud-local:
@docker buildx build . --builder cloud-benoitvignal-narvik-cloud --pull --no-cache -t narvik-php --target frankenphp_dev
build-prod:
@docker build --pull --no-cache -t $(BUILD_REPO):latest -t $(BUILD_REPO):`cat composer.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+' -o` -t $(BUILD_REPO):`cat composer.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+\.[0-9]\+' -o` -t $(BUILD_REPO):`cat composer.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o` --target frankenphp_prod .
build-cloud-prod:
@docker buildx build . --builder cloud-benoitvignal-narvik-cloud --pull --no-cache -t $(BUILD_REPO):latest -t $(BUILD_REPO):`cat composer.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+' -o` -t $(BUILD_REPO):`cat composer.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o | grep '^[0-9]\+\.[0-9]\+' -o` -t $(BUILD_REPO):`cat composer.json | grep version | grep '\([0-9]\+\.\?\)\{3\}' -o` --target frankenphp_prod
up: ## Start the docker hub in detached mode (no logs)
@$(DOCKER_COMP) up --detach
up-prod: ## Start the docker in prod mode, be sure to have remove docker images if you run them in dev before
IMAGES_PREFIX=prod- $(DOCKER_COMP) --env-file .env.prod.local -f compose.yaml -f compose.prod.yaml up --detach
start: build up ## Build and start the containers
start-prod: build-prod up-prod ## Build and start the containers in prod environment
down: ## Stop the docker hub
@$(DOCKER_COMP) down --remove-orphans
stop: down
restart: stop up
logs: ## Show live logs
@$(DOCKER_COMP) logs --tail=0 --follow
sh: ## Connect to the PHP FPM container
@$(PHP_CONT) bash
## —— Composer 🧙 ——————————————————————————————————————————————————————————————
composer: ## Run composer, pass the parameter "c=" to run a given command, example: make composer c='req symfony/orm-pack'
@$(eval c ?=)
@$(COMPOSER) $(c)
vendor: ## Install vendors according to the current composer.lock file
vendor: c=install --prefer-dist --no-scripts --no-interaction
vendor: composer
vendor-prod: ## Install vendors according to the current composer.lock file
vendor-prod: c=install --prefer-dist --no-dev --no-scripts --no-interaction
vendor-prod: composer
## —— Symfony 🎵 ———————————————————————————————————————————————————————————————
sf: ## List all Symfony commands or pass the parameter "c=" to run a given command, example: make sf c=about
@$(eval c ?=)
@$(SYMFONY) $(c)
cc: c=c:c ## Clear the cache
cc: sf
cc-test: ## Clear the test cache
@$(MAKE) --no-print-directory sf c='c:c --env=test'
cc-prod: ## Clear the prod cache
@$(MAKE) --no-print-directory sf c='c:c --env=prod'
reload-fixture: ## Reload the database based on the default fixtures
@$(COMPOSER) reload-fixture
test: ## Run the test suit on the app, add f=<filepath> to run the tests only in that specific file
@$(eval f ?=)
@if [ -z "$(f)" ]; then\
echo "\033[42m Running test globally \033[m";\
fi
@$(COMPOSER) test $(f)
test-with-coverage: ## Run the test suit on the app with coverage report
@$(COMPOSER) test-with-coverage
## —— Database 📦 ——————————————————————————————————————————————————————————————
db-dump: ## Dump the current database
@$(DB_CONT) sh -c 'pg_dumpall -c -U $$POSTGRES_USER | gzip' > ./dump/dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz
db-restore: ## Restore a database dump. The file must be called './dump/dump.sql.gz'
docker compose exec database sh -c 'psql -d $$POSTGRES_DB -U $$POSTGRES_USER -c "DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;"'
gunzip < ./dump/dump.sql.gz | docker compose exec -T database sh -c 'psql -d $$POSTGRES_DB -U $$POSTGRES_USER'
db-make-migration: ## Generate Doctrine migration based on current database diff with Entities
@$(PHP_CONT) bin/console make:migration
db-migrate: ## Run pending Doctrine migrations
@$(PHP_CONT) bin/console doctrine:migrations:migrate --no-interaction
## —— Code quality 🚀 ————————————————————————————————————————————————————————————————
rector: ## Run rector to fix code issues
@$(PHP_CONT) ./vendor/bin/rector process
rector-dry-run: ## Run rector in dry-run mode to see what would be changed
@$(PHP_CONT) ./vendor/bin/rector process --dry-run
code-quality: rector ## Run all code quality checks (mirrors CI)
$(PHP_CONT) ./vendor/bin/composer-dependency-analyser --config composer-dependency-analyser.php