forked from eventoL/eventoL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
301 lines (218 loc) · 13.1 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
THIS_FILE := $(lastword $(MAKEFILE_LIST))
SHELL := /bin/bash
.PHONY: help backend-collectstatic backend-compile-translations backend-install-dev backend-install backend-lint backend-lint-with-report backend-makemigrations backend-make-translations backend-migrate backend-test frontend-build frontend-build-dev frontend-install-dependencies frontend-lint-fix frontend-lint frontend-lint-with-report frontend-sasslint-fix frontend-sasslint frontend-sasslint-with-report frontend-test install-node-in-python-image install-yarn-in-python-image travis-after travis-before travis-install-dependencies travis-script
.DEFAULT: help
.EXPORT_ALL_VARIABLES:
NODE_VERSION = 10.x
YARN_VERSION = 1.13.0
PSQL_DBNAME = eventol
PSQL_PASSWORD = secret
PSQL_USER = eventol
PSQL_VERSION = 9.6
PATH = $(shell printenv PATH):~/.yarn/bin:$(HOME)/.yarn/bin:$(HOME)/.config/yarn/global/node_modules/.bin
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
DOCKER_COMPOSE := cd deploy/docker && docker-compose
DOCKER_COMPOSE_PROD := $(DOCKER_COMPOSE) -f docker-compose.prod.yml
## Install dependencies
install-node-in-python-image: ## Install node in python image
curl -sL https://deb.nodesource.com/setup_$$NODE_VERSION | bash -
apt install -y nodejs
install-yarn-in-python-image: ## Install yarn and node in python image if node is not installed
if which node > /dev/null; then \
node -v; \
echo "node is installed, skipping..."; \
else \
curl -sL https://deb.nodesource.com/setup_$$NODE_VERSION | bash -; \
apt install -y nodejs; \
fi
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version $$YARN_VERSION
## Backend tasks
backend-install: ## Install python production dependencies
pip install -U pip wheel
pip install -r requirements.txt
backend-install-dev: backend-install ## Install python development dependencies
pip install -r requirements-dev.txt
backend-test: ## Run backend test with coverage
cd eventol && py.test --cov-report xml --cov-report term-missing --cov-report html --cov --cov-branch -n auto
backend-makemigrations: ## Run backend make migrations from manager app
cd eventol && python manage.py makemigrations manager
backend-migrate: ## Run backend migrate database
cd eventol && python manage.py migrate
backend-collectstatic: ## Run backend collect static files
cd eventol && python manage.py collectstatic --noinput
backend-createsuperuser: ## Run backend create super user
cd eventol && python manage.py createsuperuser
backend-lint: ## Run backend linter
pylint --output-format=colorized eventol/eventol eventol/manager
backend-lint-with-report: ## Run backend linter and generate report
pylint --output-format=colorized --reports yes eventol/eventol eventol/manager
backend-make-translations: ## Update translations files (update .po files)
cd eventol && python manage.py makemessages -a -d djangojs --no-location -i node_modules -i venv -i coverage -e js,jsx
cd eventol && python manage.py makemessages -a -d django --no-location -i node_modules -i venv -i coverage
backend-compile-translations: ## Compile translations files (update .mo files)
cd eventol && python manage.py compilemessages
backend-runserver: ## Runserver for development environment
cd eventol && python manage.py runserver 0.0.0.0:8000
## Frontend tasks
frontend-start-dev: ## Start frontend for development environment
cd eventol/front && yarn start
frontend-install-dependencies: ## Install frontend dev dependencies
cd eventol/front && yarn install
frontend-build: ## Build frontend code for production environment
cd eventol/front && yarn build
frontend-build-dev: ## Build frontend code for development environment
cd eventol/front && yarn build:dev
frontend-test: ## Run frontend test
cd eventol/front && yarn test
frontend-lint: ## Run frontend linter
cd eventol/front && yarn eslint
frontend-lint-fix: ## Run frontend linter and autofix errors
cd eventol/front && yarn eslint:fix
frontend-lint-with-report: ## Run frontend linter and generate report
cd eventol/front && yarn eslint:report
frontend-sasslint: ## Run sass linter
cd eventol/front && yarn sasslint
frontend-sasslint-fix: ## Run sass linter and autofix errors
cd eventol/front && yarn sasslint:fix
frontend-sasslint-with-report: ## Run sass linter and generate report
cd eventol/front && yarn sasslint:report
## Travis CI
travis-install-dependencies: ## Install coverage and coveralls dependencies
pip install coverage coveralls
travis-before: ## Travis before commands
docker run --name eventol-postgres -e POSTGRES_PASSWORD=$$PSQL_PASSWORD -e POSTGRES_USER=$$PSQL_USER -e POSTGRES_DB=$$PSQL_DBNAME -p $$PSQL_PORT:5432 -d postgres:$$PSQL_VERSION
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
@$(MAKE) -f $(THIS_FILE) install-yarn-in-python-image
travis-script: frontend-install-dependencies frontend-build ## Travis script for run tests (python and react)
mkdir -p eventol/static
@$(MAKE) -f $(THIS_FILE) backend-makemigrations
@$(MAKE) -f $(THIS_FILE) backend-migrate
@$(MAKE) -f $(THIS_FILE) backend-collectstatic
@$(MAKE) -f $(THIS_FILE) backend-test
@$(MAKE) -f $(THIS_FILE) frontend-test
travis-after: ## Travis after script for success case
cd eventol && coverage report
cd eventol && coveralls
mv cc-test-reporter eventol/cc-test-reporter
cd eventol && ./cc-test-reporter format-coverage -d -t coverage.py -o coverage/python.json --add-prefix eventol
cd eventol && ./cc-test-reporter format-coverage ./front/coverage/lcov.info -d -t lcov -o ./coverage/javascript.json --add-prefix eventol
cd eventol && ./cc-test-reporter sum-coverage --output coverage/codeclimate.json -d -p 2 coverage/python.json coverage/javascript.json
cd eventol && ./cc-test-reporter upload-coverage -d
## Gitlab
gitlab-python-testing: install-yarn-in-python-image frontend-install-dependencies frontend-build backend-install-dev backend-test ## Gitlab command for python-testing job
gitlab-python-lint: backend-install-dev backend-lint-with-report ## Gitlab command for python-lint job
gitlab-react-testing: frontend-install-dependencies frontend-test ## Gitlab command for react-testing job
gitlab-react-lint: frontend-install-dependencies frontend-lint ## Gitlab command for react-lint job
gitlab-react-lint-with-report: frontend-install-dependencies frontend-lint-with-report ## Gitlab command for react-lint-report job
gitlab-react-sasslint: frontend-install-dependencies frontend-sasslint ## Gitlab command for react-sasslint job
gitlab-react-sasslint-with-report: frontend-install-dependencies frontend-sasslint-with-report ## Gitlab command for react-sasslint-report job
gitlab-autodeploy: ## Gitlab autodeploy command to remote server
sshpass -e ssh -p$(SSH_PORT) -o stricthostkeychecking=no -x $(SSH_USER)@$(SSH_HOST) $(SSH_SCRIPT)
gitlab-registry-login: ## Gitlab login docker to registry
docker login -u gitlab-ci-token -p $(CI_BUILD_TOKEN) $(CI_REGISTRY)
gitlab-build-and-push: ## Gitlab pull, build and push docker image
docker pull $(IMAGE_NAME) || true
docker build --cache-from $(IMAGE_NAME) -t $(IMAGE_NAME) .
docker push $(IMAGE_NAME)
gitlab-update-image: gitlab-registry-login gitlab-build-and-push ## Gitlab update docker image in gitlab registry
# EventoL*
pull: ## Pull docker images for production environment
$(DOCKER_COMPOSE_PROD) pull
pull-dev: ## Pull docker images for development environment
$(DOCKER_COMPOSE) pull
status: ## Status for production environment
$(DOCKER_COMPOSE_PROD) ps
status-dev: ## Status for development environment
$(DOCKER_COMPOSE) ps
build-local: ## Build eventol latest image locally
docker build --force-rm --tag=eventol/eventol:latest .
build: ## Build docker images for production environment
$(DOCKER_COMPOSE_PROD) build --force-rm
build-dev: ## Build docker images for development environment
$(DOCKER_COMPOSE) build --force-rm
deploy: pull build ## Deploy eventol with production environment
$(DOCKER_COMPOSE_PROD) up -d --remove-orphans
deploy-dev: pull-dev build-dev ## Deploy eventol with development environment
$(DOCKER_COMPOSE) up -d --remove-orphans
logs: ## Show docker-compose logs of production environment
$(DOCKER_COMPOSE_PROD) logs
logs-dev: ## Show docker-compose logs of development environment
$(DOCKER_COMPOSE) logs
logs-follow: ## Show and follow docker-compose logs of production environment
$(DOCKER_COMPOSE_PROD) logs -f
logs-follow-dev: ## Show and follow docker-compose logs of development environment
$(DOCKER_COMPOSE) logs -f
restart: ## Restart eventol in production environment
$(DOCKER_COMPOSE_PROD) restart
restart-dev: ## Restart eventol in development environment
$(DOCKER_COMPOSE) restart
stop: ## Stop eventol in production environment
$(DOCKER_COMPOSE_PROD) stop
stop-dev: ## Stop eventol in development environment
$(DOCKER_COMPOSE) stop
undeploy: stop ## Remove eventol in production environment
$(DOCKER_COMPOSE_PROD) down --remove-orphans
undeploy-dev: stop-dev ## Remove eventol in development environment
$(DOCKER_COMPOSE) down --remove-orphans
undeploy-full: stop ## Remove eventol and data in production environment
$(DOCKER_COMPOSE_PROD) down --remove-orphans --volumes
undeploy-full-dev: stop-dev ## Remove eventol and data in development environment
$(DOCKER_COMPOSE) down --remove-orphans --volumes
update: undeploy deploy ## Update eventol in production environment
update-dev: undeploy-dev deploy-dev ## Update eventol in development environment
# EventoL commands from docker-compose
docker-backend-test: ## Run backend test with coverage in docker-compose
$(DOCKER_COMPOSE) exec -T worker make backend-test
docker-backend-makemigrations: ## Run backend make migrations from manager app in docker-compose
$(DOCKER_COMPOSE) exec -T worker make backend-makemigrations
docker-backend-migrate: ## Run backend migrate database in docker-compose
$(DOCKER_COMPOSE_PROD) exec -T worker make backend-migrate
docker-backend-collectstatic: ## Run backend collect static files in docker-compose
$(DOCKER_COMPOSE_PROD) exec -T worker make backend-collectstatic
docker-backend-createsuperuser: ## Run backend create super user in docker-compose
$(DOCKER_COMPOSE_PROD) exec -T worker make backend-createsuperuser
docker-backend-lint: ## Run backend linter in docker-compose
$(DOCKER_COMPOSE) exec -T worker make backend-lint
docker-backend-lint-with-report: ## Run backend linter and generate report in docker-compose
$(DOCKER_COMPOSE) exec -T worker make backend-lint-with-report
docker-backend-make-translations: ## Update translations files (update .po files) in docker-compose
$(DOCKER_COMPOSE) exec -T worker make backend-make-translations
docker-backend-compile-translations: ## Compile translations files (update .mo files) in docker-compose
$(DOCKER_COMPOSE_PROD) exec -T worker make backend-compile-translations
docker-backend-runserver: ## Runserver for development environment in docker-compose
$(DOCKER_COMPOSE_PROD) exec -T worker make backend-runserver
docker-frontend-start-dev: ## Start frontend for development environment in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn start
docker-frontend-install-dependencies: ## Install frontend dev dependencies in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn install
docker-frontend-build: ## Build frontend code for production environment in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn build
docker-frontend-build-dev: ## Build frontend code for development environment in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn yarn build:dev
docker-frontend-test: ## Run frontend test in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn test
docker-frontend-lint: ## Run frontend linter in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn eslint
docker-frontend-lint-fix: ## Run frontend linter and autofix errors in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn eslint:fix
docker-frontend-lint-with-report: ## Run frontend linter and generate report in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn eslint:report
docker-frontend-sasslint: ## Run sass linter in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn sasslint
docker-frontend-sasslint-fix: ## Run sass linter and autofix errors in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn sasslint:fix
docker-frontend-sasslint-with-report: ## Run sass linter and generate report in docker-compose
$(DOCKER_COMPOSE) exec -T reactjs yarn sasslint:report
## Alias
collectstatic: docker-backend-collectstatic ## Alias to docker-backend-collectstatic
createsuperuser: docker-backend-createsuperuser ## Alias to docker-backend-createsuperuser
makemigrations: docker-backend-makemigrations ## Alias to docker-backend-makemigrations
migrate: docker-backend-migrate ## Alias to docker-backend-migrate
runserver: docker-backend-runserver ## Alias to docker-backend-runserver
setup-frontend: docker-frontend-install-dependencies ## Setup front end in docker-compose
start-frontend: docker-frontend-start-dev ## Alias to docker-frontend-start-dev
make-translations: docker-backend-make-translations ## Alias to docker-backend-make-translations
compile-translations: docker-backend-compile-translations ## Alias to docker-backend-compile-translations