-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
189 lines (143 loc) · 6.33 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
help: ## Display this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sort \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[0;32m%-30s\033[0m %s\n", $$1, $$2}'
# Environment commands
# ------------------------------------------------------------------------------
env-dev: ## Create template .env files for dev environment (if files don't exist already)
@test ! -f ./.envs/.dev/.db && cp ./.envs/.dev/.db.example ./.envs/.dev/.db
@test ! -f ./.envs/.dev/.django && cp ./.envs/.dev/.django.example ./.envs/.dev/.django
env-staging: ## Create template .env files for staging environment (if files don't exist already)
@test ! -f ./.envs/.staging/.db && cp ./.envs/.staging/.db.example ./.envs/.staging/.db
@test ! -f ./.envs/.staging/.django && cp ./.envs/.staging/.django.example ./.envs/.staging/.django
@test ! -f ./.envs/.staging/.nginx-proxy-letsencrypt && \
cp ./.envs/.staging/.nginx-proxy-letsencrypt.example ./.envs/.staging/.nginx-proxy-letsencrypt
env-production: ## Create template .env files for production environment (if files don't exist already)
@test ! -f ./.envs/.production/.db && cp ./.envs/.production/.db.example ./.envs/.production/.db
@test ! -f ./.envs/.production/.django && cp ./.envs/.production/.django.example ./.envs/.production/.django
@test ! -f ./.envs/.production/.nginx-proxy-letsencrypt && \
cp ./.envs/.production/.nginx-proxy-letsencrypt.example ./.envs/.production/.nginx-proxy-letsencrypt
env-all: env-dev env-staging env-production ## Create .env files for all environments: dev, staging, production (if files don't exist already)
secretkey: ## Output a secure secret key (i.e. for using as Django SECRET_KEY env variable)
@poetry run python3 -c 'from django.utils.crypto import get_random_string; print(get_random_string(40))'
requirements: ## Export app dependencies to requirements.txt
@poetry export --format requirements.txt --output requirements.txt --extras psycopg2 --without-hashes
reqs: ## Export app dependencies with dev dependencies for dev environment / without dev deps for staging or production env (used for building Docker containers)
ifeq (${MODE}, dev)
poetry export --format requirements.txt --output requirements.txt --with dev --extras psycopg2 --without-hashes
else ifeq ($(filter ${MODE},staging production),${MODE})
poetry export --format requirements.txt --output requirements.txt --extras psycopg2 --without-hashes --without dev --without optional
else
@echo "Error: MODE not set properly. Please set MODE to 'dev', 'staging', or 'production'."
@exit 1
endif
# App setup
# ------------------------------------------------------------------------------
migrate: ## Run database migrations (when running app locally)
@poetry run python3 manage.py migrate
migrate-docker: ## Run database migrations (when running app in Docker)
python3 manage.py migrate
wait-postgres: # Wait for postgres to start up
python3 ./task_manager/utils/wait_for_postgres.py
install: .env
@poetry install --extras psycopg2-binary
setup: migrate
@echo Create a super user:
@poetry run python3 manage.py createsuperuser
shell: ## Run Django REPL shell
@poetry run python3 manage.py shell
shell-docker: ## Run Django REPL shell (when running app in Docker)
@python3 manage.py shell
# i18n localization/translation commands
# ------------------------------------------------------------------------------
transprepare:
@poetry run django-admin makemessages --ignore="static" --ignore=".venv" -a
transprepare-docker:
django-admin makemessages --ignore="static" --ignore=".venv" -a
transcompile:
@poetry run django-admin compilemessages --ignore="static" --ignore=".venv"
transcompile-docker:
django-admin compilemessages --ignore="static" --ignore=".venv"
# Static files management
# ------------------------------------------------------------------------------
collectstatic: # Run Django migrations (when running app locally)
@poetry run python3 manage.py collectstatic --no-input
collectstatic-docker: # Run Django migrations (when running app in Docker)
python3 manage.py collectstatic --no-input
# Checks, tests, lint
lint: ## Run flake8 code linter
@poetry run flake8 task_manager
lint-docker: ## Run flake8 code linter (for use in Docker and CI)
@python3 -m flake8 task_manager
selfcheck:
@poetry check
test: ## Run tests
@export DJANGO_ALLOWED_HOSTS="*"; \
poetry run pytest --cov=task_manager --cov-report=xml
test-docker: ## Run tests (for use in Docker and CI)
python3 -m pytest
test-coverage-report: test
@poetry run coverage report -m $(ARGS)
@poetry run coverage erase
test-coverage-report-xml:
@poetry run coverage xml
check: lint selfcheck test requirements.txt
check-docker: lint-docker test-docker
# App deployment
# ------------------------------------------------------------------------------
docker-up-dev: ## Build and run docker container (development environment)
docker compose -f docker-compose.dev.yml up -d --build
docker-up-staging: ## Build and run docker container (staging environment)
docker compose -f docker-compose.staging.yml up -d --build
docker-up-production: ## Build and run docker container (production environment)
docker compose -f docker-compose.production.yml up -d --build
run-dev: migrate transcompile ## Run Django dev server (when running app locally)
@poetry run python3 manage.py runserver 0.0.0.0:8000
run-dev-docker: \
wait-postgres \
migrate-docker \
transcompile-docker \
collectstatic-docker ## Run Django dev server (when running app in Docker)
python3 manage.py runserver 0.0.0.0:8000
run-gunicorn-dev: migrate transcompile
@poetry run gunicorn task_manager.wsgi --bind 0.0.0.0:8000
run-gunicorn-docker: \
wait-postgres \
migrate-docker \
transcompile-docker \
collectstatic-docker ## Run gunicorn wsgi server (when running app in Docker)
gunicorn task_manager.wsgi --bind 0.0.0.0:8000
deploy-heroku: ## Deploy the app to Heroku via git
git push heroku
.PHONY: \
help \
env-dev \
env-staging \
env-production \
env-all \
secretkey \
requirements \
reqs \
migrate \
migrate-docker \
wait-postgres \
install \
setup \
shell \
transprepare \
transprepare-docker \
transcompile \
transcompile-docker \
collectstatic \
collectstatic-docker \
lint \
selfcheck \
test \
test-coverage-report \
test-coverage-report-xml \
check \
run-dev \
run-dev-docker \
run-gunicorn-dev \
run-gunicorn-docker \
deploy-heroku