generated from ks6088ts/template-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
154 lines (126 loc) · 4.16 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
# Git
GIT_REVISION ?= $(shell git rev-parse --short HEAD)
GIT_TAG ?= $(shell git describe --tags --abbrev=0 --always | sed -e s/v//g)
LOG_LEVEL ?= "INFO"
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help
.PHONY: info
info: ## show information
@echo "GIT_REVISION: $(GIT_REVISION)"
@echo "GIT_TAG: $(GIT_TAG)"
.PHONY: install-deps-dev
install-deps-dev: ## install dependencies for development
poetry install
poetry run pre-commit install
.PHONY: install-deps
install-deps: ## install dependencies for production
poetry install --without dev
.PHONY: format-check
format-check: ## format check
poetry run black . --check --extend-exclude client/ --verbose
.PHONY: format
format: ## format code
poetry run isort .
poetry run black . --extend-exclude client/ --verbose
.PHONY: fix
fix: format ## apply auto-fixes
poetry run ruff check --fix
.PHONY: lint
lint: ## lint
poetry run ruff check .
shellcheck scripts/*.sh
.PHONY: test
test: ## run tests
poetry run pytest --log-cli-level=$(LOG_LEVEL)
.PHONY: ci-test
ci-test: install-deps-dev format-check lint test ## run CI tests
# ---
# Docker
# ---
DOCKER_REPO_NAME ?= ks6088ts
DOCKER_IMAGE_NAME ?= azure-ai-services-solutions
DOCKER_SERVICE_NAME ?= backend
DOCKER_COMMAND ?=
DOCKER_TAG ?= $(DOCKER_SERVICE_NAME)-$(GIT_TAG)
DOCKER_FILE ?= ./$(DOCKER_SERVICE_NAME)/Dockerfile
DOCKER_COMPOSE_FILE ?= ./compose.yaml
# Tools
TOOLS_DIR ?= $(HOME)/.local/bin
TRIVY_VERSION ?= 0.49.1
.PHONY: docker-build
docker-build: ## build Docker image
docker build \
--tag $(DOCKER_REPO_NAME)/$(DOCKER_IMAGE_NAME):$(DOCKER_TAG) \
--file $(DOCKER_FILE) \
--build-arg GIT_REVISION=$(GIT_REVISION) \
--build-arg GIT_TAG=$(GIT_TAG) \
--no-cache \
.
.PHONY: docker-run
docker-run: ## run Docker container
docker run --rm $(DOCKER_REPO_NAME)/$(DOCKER_IMAGE_NAME):$(DOCKER_TAG) $(DOCKER_COMMAND)
.PHONY: docker-lint
docker-lint: ## lint Dockerfile
docker run --rm -i hadolint/hadolint < $(DOCKER_FILE)
.PHONY: docker-compose-lint
docker-compose-lint: ## lint docker compose file
docker compose --file $(DOCKER_COMPOSE_FILE) config --quiet
.PHONY: docker-scan
docker-scan: ## scan Docker image
@# https://aquasecurity.github.io/trivy/v0.18.3/installation/#install-script
@which trivy || curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b $(TOOLS_DIR) v$(TRIVY_VERSION)
trivy image $(DOCKER_REPO_NAME)/$(DOCKER_IMAGE_NAME):$(DOCKER_TAG)
.PHONY: _ci-test-docker
_ci-test-docker: docker-lint docker-build docker-scan docker-run
.PHONY: ci-test-docker
ci-test-docker: docker-compose-lint ## run CI test for Docker
$(MAKE) _ci-test-docker DOCKER_SERVICE_NAME=backend
$(MAKE) _ci-test-docker DOCKER_SERVICE_NAME=frontend
# ---
# Application
# ---
.PHONY: backend
backend: ## run backend
cd backend \
&& poetry run python main.py backend --reload
.PHONY: frontend
frontend: ## run frontend
cd frontend \
&& poetry run streamlit run main.py
# ---
# Azure Functions
# ---
.PHONY: azure-functions-start
azure-functions-start: ## start Azure Functions
cd backend \
&& poetry run func start
.PHONY: azure-functions-deploy
azure-functions-deploy: ## deploy Azure Functions resources
sh ./scripts/deploy-azure-functions.sh
.PHONY: azure-functions-destroy
azure-functions-destroy: ## destroy Azure Functions resources
sh ./scripts/destroy-azure-functions.sh
.PHONY: azure-functions-publish
azure-functions-publish: ## publish Azure Functions App
sh ./scripts/publish-azure-functions.sh
# ---
# OpenAPI Client
# ---
.PHONY: generate-openapi-spec
generate-openapi-spec: ## generate OpenAPI spec
cd backend \
&& poetry run python main.py generate-openapi-spec
.PHONY: generate-openapi-client
generate-openapi-client: ## generate OpenAPI client
@kiota generate \
--language Python \
--class-name ApiClient \
--namespace-name client \
--openapi ./specs/openapi.json \
--output ./client
@echo "Get the list of dependencies"
@kiota info -d ./specs/openapi.json --language Python
.PHONY: generate-openapi
generate-openapi: generate-openapi-spec generate-openapi-client ## generate OpenAPI artifacts