This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
114 lines (87 loc) · 2.74 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
## options
# based on https://tech.davis-hansson.com/p/make/
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.ONESHELL:
.DEFAULT_GOAL := help
.DELETE_ON_ERROR:
## variables
ENVIRONMENT ?= dev
ARGS =
APP_NAME = $(shell python -m src.config app_name)
SOURCE_DIR := src
TEST_DIR := tests
IMAGE_HOST = $(shell python -m src.config image_host)
IMAGE_REPO = $(shell python -m src.config image_repo)
IMAGE_NAME = $(IMAGE_HOST)/$(IMAGE_REPO)/$(APP_NAME)
IMAGE_TAG ?= latest
## formula
# based on https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## print help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
## dependencies
.PHONY: deps-install-python
deps-install-python:
poetry install --no-root
pip list
.PHONY: install-hooks
install-hooks:
python -m pre_commit install --install-hooks
wget -O .git/hooks/prepare-commit-msg https://raw.githubusercontent.com/commitizen-tools/commitizen/master/hooks/prepare-commit-msg.py
chmod +x .git/hooks/prepare-commit-msg
wget -O .git/hooks/post-commit https://raw.githubusercontent.com/commitizen-tools/commitizen/master/hooks/post-commit.py
chmod +x .git/hooks/post-commit
.PHONY: deps-install
deps-install: deps-install-python install-hooks ## install dependencies
.PHONY: deps-update
deps-update:
poetry update
poetry export --format requirements.txt --output requirements.txt --without-hashes
python -m pre_commit autoupdate
requirements.txt: poetry.lock
poetry export --format requirements.txt --output requirements.txt --without-hashes
requirements-dev.txt: poetry.lock
poetry export --with dev --format requirements.txt --output requirements-dev.txt --without-hashes
## checks
.PHONY: format
format:
python -m ruff check --fix .
python -m ruff format .
.PHONY: lint
lint:
python -m ruff check .
python -m ruff format .
python -m mypy $(SOURCE_DIR)
.PHONY: test
test:
python -m pytest $(TEST_DIR) --cov $(SOURCE_DIR)
.PHONY: run-ci
run-ci: deps-install-python lint test ## run ci
## app
.PHONY: run-task
run-task: ## run python task
python -m src.task
.PHONY: run-web-dev
run-web-dev:
python -m uvicorn src.web:app --reload
.PHONY: run-web
run-web: ## run python web
python -m gunicorn src.web:app -c src/gunicorn_conf.py
.PHONY: run
run: run-web ## run main python app
## docker-compose
.PHONY: dc-build
dc-build: requirements.txt ## build app image
IMAGE_TAG=$(IMAGE_TAG) docker compose build web_dev web_ci web
.PHONY: dc-test
dc-ci:
docker compose run --build --rm web_ci
.PHONY: dc-up
dc-up: ## run app image
docker compose up web_dev
.PHONY: dc-exec
dc-exec:
docker compose exec web_dev /bin/bash