forked from Grafikart/Grafikart.fr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
134 lines (110 loc) · 4.26 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
isDocker := $(shell docker info > /dev/null 2>&1 && echo 1)
domain := "grafikart.fr"
server := "grafikart"
user := $(shell id -u)
group := $(shell id -g)
ifeq ($(isDocker), 1)
dc := USER_ID=$(user) GROUP_ID=$(group) docker-compose
dcimport := USER_ID=$(user) GROUP_ID=$(group) docker-compose -f docker-compose.import.yml
dcimport := USER_ID=$(user) GROUP_ID=$(group) docker-compose -f docker-compose.import.yml
de := docker-compose exec
dr := $(dc) run --rm
sy := $(de) php bin/console
drtest := $(dc) -f docker-compose.test.yml run --rm
node := $(dr) node
php := $(dr) --no-deps php
else
sy := php bin/console
node :=
php :=
endif
.DEFAULT_GOAL := help
.PHONY: help
help: ## Affiche cette aide
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: deploy
deploy: ## Déploie une nouvelle version du site
ssh -A $(server) 'cd $(domain) && git pull origin master && make install'
.PHONY: sync
sync: ## Récupère les données depuis le serveur
rsync -avz --ignore-existing --progress --exclude=avatars grafikart:/home/grafikart/grafikart.fr/public/uploads/ ./public/uploads/
.PHONY: install
install: vendor/autoload.php public/assets/manifest.json ## Installe les différentes dépendances
APP_ENV=prod APP_DEBUG=0 $(php) composer install --no-dev --optimize-autoloader
make migrate
APP_ENV=prod APP_DEBUG=0 $(sy) cache:clear
$(sy) cache:pool:clear cache.global_clearer
$(sy) messenger:stop-workers
sudo service php7.4-fpm reload
.PHONY: build-docker
build-docker:
$(dc) pull --ignore-pull-failures
$(dc) build php
$(dc) build messenger
$(dc) build node
.PHONY: dev
dev: vendor/autoload.php node_modules/time ## Lance le serveur de développement
$(dc) up
.PHONY: dump
dump: var/dump ## Génère un dump SQL
$(de) db sh -c 'PGPASSWORD="grafikart" pg_dump grafikart -U grafikart > /var/www/var/dump/dump.sql'
.PHONY: dumpimport
dumpimport: var/dump ## Import un dump SQL
$(de) db sh -c 'psql grafikart < /var/www/var/dump/dump.sql'
.PHONY: seed
seed: vendor/autoload.php ## Génère des données dans la base de données (docker-compose up doit être lancé)
$(sy) doctrine:migrations:migrate -q
$(sy) doctrine:schema:validate -q
$(sy) app:seed -q
.PHONY: migration
migration: vendor/autoload.php ## Génère les migrations
$(sy) make:migration
.PHONY: migrate
migrate: vendor/autoload.php ## Migre la base de données (docker-compose up doit être lancé)
$(sy) doctrine:migrations:migrate -q
.PHONY: rollback
rollback:
$(sy) doctrine:migration:migrate prev
.PHONY: test
test: vendor/autoload.php node_modules/time ## Execute les tests
$(drtest) phptest bin/console doctrine:schema:validate --skip-sync
$(drtest) phptest vendor/bin/phpunit
$(node) yarn run test
.PHONY: tt
tt: vendor/autoload.php ## Lance le watcher phpunit
$(drtest) phptest bin/console cache:clear --env=test
$(drtest) phptest vendor/bin/phpunit-watcher watch --filter="nothing"
.PHONY: lint
lint: vendor/autoload.php ## Analyse le code
docker run -v $(PWD):/app -w /app -t --rm php:7.4-cli-alpine php -d memory_limit=-1 bin/console lint:container
docker run -v $(PWD):/app -w /app -t --rm php:7.4-cli-alpine php -d memory_limit=-1 ./vendor/bin/phpstan analyse
.PHONY: format
format: ## Formate le code
npx prettier-standard --lint --changed "assets/**/*.{js,css,jsx}"
docker run -v $(PWD):/app -w /app -t --rm php:7.4-cli-alpine php -d memory_limit=-1 ./vendor/bin/phpcbf
docker run -v $(PWD):/app -w /app -t --rm php:7.4-cli-alpine php -d memory_limit=-1 ./vendor/bin/php-cs-fixer fix
.PHONY: doc
doc: ## Génère le sommaire de la documentation
npx doctoc ./README.md
# -----------------------------------
# Déploiement
# -----------------------------------
.PHONY: provision
provision: ## Configure la machine distante
ansible-playbook --vault-password-file .vault_pass -i tools/ansible/hosts.yml tools/ansible/install.yml
# -----------------------------------
# Dépendances
# -----------------------------------
vendor/autoload.php: composer.lock
$(php) composer install
touch vendor/autoload.php
node_modules/time: yarn.lock
$(node) yarn
touch node_modules/time
public/assets: node_modules/time
$(node) yarn run build
var/dump:
mkdir var/dump
public/assets/manifest.json: package.json
$(node) yarn
$(node) yarn run build