|
| 1 | +DC=docker-compose |
| 2 | +CONTAINER=php |
| 3 | +DATABASE_CONTAINER=database |
| 4 | +EXEC=$(DC) exec $(CONTAINER) |
| 5 | +PHP = php |
| 6 | +CON = $(PHP) bin/console |
| 7 | +AWK := $(shell command -v awk 2> /dev/null) |
| 8 | + |
| 9 | +.DEFAULT_GOAL := help |
| 10 | +.PHONY: help |
| 11 | + |
| 12 | +help: ## Show this help |
| 13 | +ifndef AWK |
| 14 | + @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' |
| 15 | +else |
| 16 | + @grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' |
| 17 | +endif |
| 18 | + |
| 19 | +## |
| 20 | +## Project setup |
| 21 | +##--------------------------------------------------------------------------- |
| 22 | +.PHONY: install update vendor-install vendor-update |
| 23 | +.PRECIOUS: .env docker-compose.override.yml |
| 24 | + |
| 25 | +install: ## Process all step in order to setup the projects |
| 26 | +install: up vendor-install db-reset |
| 27 | + |
| 28 | +update: ## Update the project |
| 29 | +update: up vendor-install db-migrate |
| 30 | + |
| 31 | +vendor-install: |
| 32 | + $(EXEC) composer install --no-suggest --no-progress |
| 33 | + |
| 34 | +vendor-update: |
| 35 | + $(EXEC) composer update |
| 36 | + |
| 37 | +## |
| 38 | +## Database |
| 39 | +##--------------------------------------------------------------------------- |
| 40 | +.PHONY: db-reset db-create db-drop db-make-migration db-migrate db-schema-validate db-schema-drop db-schema-update db-fixtures db-test |
| 41 | + |
| 42 | +db-reset: ## Reset database |
| 43 | +db-reset: db-drop db-create db-migrate |
| 44 | + |
| 45 | +db-create: ## Create database |
| 46 | + $(EXEC) $(CON) doctrine:database:create --if-not-exists |
| 47 | + |
| 48 | +db-drop: ## Drop database |
| 49 | + $(EXEC) $(CON) doctrine:database:drop --force --if-exists |
| 50 | + |
| 51 | +db-gen-migration: ## Drop database |
| 52 | + $(EXEC) $(CON) doctrine:migration:diff |
| 53 | + |
| 54 | +db-make-migration: ## Migrate database schema to the latest available version |
| 55 | + $(EXEC) $(CON) make:migration |
| 56 | + |
| 57 | +db-migrate: ## Migrate database schema to the latest available version |
| 58 | + $(EXEC) $(CON) doctrine:migrations:migrate -n |
| 59 | + |
| 60 | +db-schema-validate: ## Validate the mapping files |
| 61 | + $(EXEC) $(CON) doctrine:schema:validate |
| 62 | + |
| 63 | +db-schema-drop: ## Executes (or dumps) the SQL needed to drop the current database schema |
| 64 | + $(EXEC) $(CON) doctrine:schema:drop --force |
| 65 | + |
| 66 | +db-schema-update: ## Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata |
| 67 | + $(EXEC) $(CON) doctrine:schema:update --force |
| 68 | + |
| 69 | +db-fixtures: ## Reset the database fixtures |
| 70 | + $(EXEC) $(CON) hautelook:fixtures:load --purge-with-truncate -q |
| 71 | + |
| 72 | +## |
| 73 | +## TESTS |
| 74 | +## |
| 75 | + |
| 76 | +unit-tests: ## Run functional tests |
| 77 | + $(EXEC) bin/phpunit |
| 78 | + |
| 79 | +unit-tests-coverage: ## Run functional tests |
| 80 | + $(EXEC) bin/phpunit --coverage-html public/coverage |
| 81 | + |
| 82 | +## |
| 83 | +## Tools |
| 84 | +##--------------------------------------------------------------------------- |
| 85 | + |
| 86 | +cc: ## Clear and warm up the cache in dev env |
| 87 | +cc: |
| 88 | + $(EXEC) $(CON) cache:clear --no-warmup |
| 89 | + $(EXEC) $(CON) cache:warmup |
| 90 | +.PHONY: cc |
| 91 | + |
| 92 | +## |
| 93 | +## Docker |
| 94 | +##--------------------------------------------------------------------------- |
| 95 | +.PHONY: docker-files up down clear perm bash mysql-bash cs-fix-dry cs-fix |
| 96 | +.PRECIOUS: .env docker-compose.override.yml |
| 97 | + |
| 98 | +docker-files: .env docker-compose.override.yml |
| 99 | + |
| 100 | +# .env: .env.dist |
| 101 | +# @if [ -f .env ]; \ |
| 102 | +# then\ |
| 103 | +# echo '\033[1;41m/!\ The .env.dist file has changed. Please check your .env file (this message will not be displayed again).\033[0m';\ |
| 104 | +# touch .env;\ |
| 105 | +# exit 1;\ |
| 106 | +# else\ |
| 107 | +# echo cp .env.dist .env;\ |
| 108 | +# cp .env.dist .env;\ |
| 109 | +# fi |
| 110 | + |
| 111 | +docker-compose.override.yml: docker-compose.yml |
| 112 | + @if [ -f docker-compose.override.yml ]; \ |
| 113 | + then\ |
| 114 | + echo '\033[1;41m/!\ The docker-compose.yml file has changed. Please check your docker-compose.override.yml file (this message will not be displayed again).\033[0m';\ |
| 115 | + touch docker-compose.override.yml;\ |
| 116 | + exit 1;\ |
| 117 | + fi |
| 118 | + |
| 119 | +up: ## Mount the containers |
| 120 | +up: docker-files |
| 121 | + $(DC) up -d |
| 122 | + |
| 123 | +clear: ## Remove everything: the cache, the logs, the sessions |
| 124 | +clear: clear-files down |
| 125 | + |
| 126 | +clear-files: docker-files perm |
| 127 | + -$(EXEC) rm -rf var/cache/* |
| 128 | + -$(EXEC) rm -rf var/sessions/* |
| 129 | + -$(EXEC) rm -rf var/logs/* |
| 130 | + |
| 131 | +down: ## Stops, remove the containers and their volumes |
| 132 | +down: docker-files |
| 133 | + $(DC) down -v --remove-orphans |
| 134 | + |
| 135 | +perm: docker-files |
| 136 | + -$(EXEC) chmod -R u+rwX,go+rX,go-w var |
| 137 | + |
| 138 | +bash: ## Access the api container via shell |
| 139 | + $(DC) exec $(CONTAINER) sh |
| 140 | + |
| 141 | + |
| 142 | +jwt: docker-files perm |
| 143 | + -$(EXEC) mkdir -p config/jwt |
| 144 | + -$(EXEC) php -r "require'vendor/autoload.php';file_put_contents('passphrase.txt',\Symfony\Component\Yaml\Yaml::parse(file_get_contents('config/packages/lexik_jwt_authentication.yaml'))['lexik_jwt_authentication']['pass_phrase']);" |
| 145 | + -$(EXEC) openssl genpkey -out ./config/jwt/private.pem -aes256 -pass file:passphrase.txt -algorithm rsa -pkeyopt rsa_keygen_bits:4096 |
| 146 | + -$(EXEC) openssl pkey -in ./config/jwt/private.pem -passin file:passphrase.txt -out config/jwt/public.pem -pubout |
| 147 | + -$(EXEC) rm -f passphrase.txt |
| 148 | + -$(EXEC) chown -R www-data:www-data ./config/jwt |
| 149 | + |
| 150 | +build: docker-files |
| 151 | + -$(EXEC) rm -rf config/jwt/* |
| 152 | + -$(DC) build |
| 153 | + -make jwt |
| 154 | + -$(EXEC) chmod -R 777 ./var/* |
| 155 | + |
| 156 | +build-no-chache: docker-files |
| 157 | + -$(EXEC) rm -rf config/jwt/* |
| 158 | + -$(DC) build --no-cache |
| 159 | + -make jwt |
| 160 | + -$(EXEC) chmod -R 777 ./var/* |
| 161 | + -docker-compose up -d --force-recreate |
| 162 | + -make db-drop |
| 163 | + -make db-create |
| 164 | + -make db-migrate |
| 165 | + |
| 166 | + |
| 167 | +mysql-bash: ## Access the database container via shell |
| 168 | + $(DC) exec $(DATABASE_CONTAINER) bash |
| 169 | + |
| 170 | +cs-fix-dry: ## Runs the CS fixer in "dry-run" mode to fix the project coding style |
| 171 | +cs-fix-dry: docker-files vendor |
| 172 | + $(EXEC) vendor/bin/php-cs-fixer fix src -vvv --config=.php_cs --cache-file=.php_cs.cache --dry-run |
| 173 | + |
| 174 | +cs-fix: ## Runs the CS fixer to fix the project coding style |
| 175 | +cs-fix: docker-files vendor |
| 176 | + $(EXEC) vendor/bin/php-cs-fixer fix src -vvv --config=.php_cs --cache-file=.php_cs.cache |
0 commit comments