-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
65 lines (48 loc) · 2.15 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
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)
EXISTS_POETRY := $(shell command -v poetry 2> /dev/null)
EXISTS_FLASK := $(shell command -v uvicorn 2> /dev/null)
export BERLIN_API_PORT ?= 28900
export BERLIN_API_HOST ?= 0.0.0.0
export FLASK_APP ?= app/main.py
export BERLIN_API_GIT_COMMIT=$(shell git rev-parse HEAD)
export BERLIN_API_VERSION ?= 0.1.0
export BERLIN_API_BUILD_TIME=$(shell date +%s)
.PHONY: all audit build build-bin deps help lint run test test-component test-unit fmt
all: audit lint fmt
audit: deps ## audits code for vulnerable dependencies
poetry run safety check
build: ## Builds a docker image berlin_api
docker build --build-arg build_time="${BERLIN_API_BUILD_TIME}" --build-arg commit="${BERLIN_API_GIT_COMMIT}" --build-arg version="${BERLIN_API_VERSION}" -t berlin_api .
build-bin: deps ## Builds a python wheel
poetry build
deps: ## Installs dependencies
bash ./ci/scripts/deps.sh
fmt: ## Formats your code automatically.
poetry run isort .
poetry run black .
lint: deps ## Lints code
poetry run ruff .
run: deps ## Start the api locally on port 28900.
@FLASK_APP=${FLASK_APP} poetry run gunicorn "app.main:create_app()" -b 0.0.0.0:${BERLIN_API_PORT} -c gunicorn_config.py
run-container: build ## Runs a container from the pre-build image
docker run -p 28900:28900 --env BERLIN_API_BUILD_TIME='${BERLIN_API_BUILD_TIME}' -e BERLIN_API_BUILD_TIME="${BERLIN_API_BUILD_TIME}" -e BERLIN_API_VERSION="${BERLIN_API_VERSION}" -ti berlin_api
test: deps ## runs all tests
poetry run pytest -v tests/
test-component: deps ## runs component tests
poetry run pytest -v tests/api
test-unit: deps ## runs unit tests
poetry run pytest -v tests/unit
help: ## Show this help.
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)