-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
101 lines (83 loc) · 4.03 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
.PHONY: all clean run shell lint tests django-test python-coverage
SHELL := /bin/bash
# specify environment
export ENVIRONMENT ?= development
# project directories
DIR_APP := visitors_book
DIR_ACCOUNT_MODELS := account
DIR_VISITS_RESTAURANTS_MODELS := visits_restaurants
DIR_ACCOUNT_MIGRATIONS := account/migrations
DIR_VISITS_RESTAURANTS_MIGRATIONS := visits_restaurants/migrations
DIR_ACCOUNT_FIXTURES := account/fixtures
DIR_VISITS_RESTAURANTS_FIXTURES := visits_restaurants/fixtures
# some other auxiliary variables
MIGRATIONS_ACCOUNT := $(shell ls $(DIR_ACCOUNT_MIGRATIONS)/*.py)
MIGRATIONS_VISITS_RESTAURANTS := $(shell ls $(DIR_VISITS_RESTAURANTS_MIGRATIONS)/*.py)
MODELS_ACCOUNT := $(DIR_ACCOUNT_MODELS)/models.py
MODELS_VISITS_RESTAURANTS := $(DIR_VISITS_RESTAURANTS_MODELS)/models.py
FIXTURES_ACCOUNT := $(shell ls $(DIR_ACCOUNT_FIXTURES))
FIXTURES_VISITS_RESTAURANTS := $(shell ls $(DIR_VISITS_RESTAURANTS_FIXTURES))
FIXTURE_ACCOUNT_FILES := $(shell for fixture in $(FIXTURES_ACCOUNT); do echo "$(DIR_ACCOUNT_FIXTURES)/$$fixture"; done)
FIXTURE_VISITS_RESTAURANTS_FILES := $(shell for fixture in $(FIXTURES_VISITS_RESTAURANTS); do echo "$(DIR_VISITS_RESTAURANTS_FIXTURES)/$$fixture"; done)
all:
@echo "make"
@echo " Print this help."
@echo "make clean"
@echo " It cleans the project files from database migrations and docker things and others..."
@echo "make makemigrations"
@echo " It calls django-admin makemigrations."
@echo "make migrate"
@echo " It calls django-admin migrate."
@echo "make run"
@echo " It runs Django development server at port 8000."
@echo "make loadfixtures"
@echo " It load fixtures into database to have some tests data in it."
@echo "make shell"
@echo " It runs django-admin shell command to inspect database models or code ..."
@echo "make tests"
@echo " It runs django-admin test command with coverage report."
@echo "make lint"
@echo " It runs linting of source code with pylint."
clean:
rm -f -v /tmp/visitors-book-*
rm -f -v $(DIR_ACCOUNT_MIGRATIONS)/*.py
rm -f -v $(DIR_VISITS_RESTAURANTS_MIGRATIONS)/*.py
touch $(DIR_ACCOUNT_MIGRATIONS)/__init__.py
touch $(DIR_VISITS_RESTAURANTS_MIGRATIONS)/__init__.py
@sudo docker stop $(shell sudo docker ps -a -q --filter name=visitorsbook*) || echo "cannot stop docker container"
@sudo docker rm $(shell sudo docker ps -a -q --filter name=visitorsbook*) || echo "cannot remove docker container"
@sudo docker rmi visitor:latest || echo "cannot remove docker image"
build-visitor-latest: /tmp/visitors-book-docker-image
/tmp/visitors-book-docker-image:
sudo docker build --no-cache --build-arg ENVIRONMENT=$(ENVIRONMENT) -t visitor:latest .
touch /tmp/visitors-book-docker-image
makemigrations: build-visitor-latest $(MODELS_ACCOUNT) $(MODELS_VISITS_RESTAURANTS) /tmp/visitors-book-makemigrations
/tmp/visitors-book-makemigrations:
sudo -E docker-compose run api makemigrations
touch /tmp/visitors-book-makemigrations
migrate: makemigrations $(MIGRATIONS_ACCOUNT) $(MIGRATIONS_VISITS_RESTAURANTS) /tmp/visitors-book-migrate
/tmp/visitors-book-migrate:
sudo -E docker-compose run api migrate
touch /tmp/visitors-book-migrate
loadfixtures: migrate /tmp/visitors-book-load-fixtures
/tmp/visitors-book-load-fixtures:
sudo -E docker-compose run api loaddata $(FIXTURE_ACCOUNT_FILES) $(FIXTURE_VISITS_RESTAURANTS_FILES)
touch /tmp/visitors-book-load-fixtures
tests: django-test python-coverage
django-test:
sudo -E docker-compose run --entrypoint 'python -m coverage' api run \
--source="visits_restaurants" manage.py test
python-coverage:
sudo -E docker-compose run --entrypoint 'python -m coverage' api report
lint:
sudo -E docker-compose run --entrypoint 'python -m pylint' api --rcfile=pylintrc \
account visitors_book visits_restaurants
run: migrate
sudo -E docker-compose up api
shell: migrate
sudo -E docker-compose run api shell
openapi: migrate schema.yml
schema.yml:
sudo -E docker-compose run api spectacular --file schema.yml --validate
celery: migrate
sudo -E docker-compose run --entrypoint 'python -m celery' api -A visitors_book worker -l INFO