-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
246 lines (225 loc) · 8.38 KB
/
makefile
File metadata and controls
246 lines (225 loc) · 8.38 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# Cross-Platform Color Definitions
ifeq ($(OS),Windows_NT)
# Git Bash Support Only
ifeq ($(shell echo $$BASH_VERSION 2>/dev/null),)
$(error This Makefile Only Supports Git Bash On Windows)
endif
GREEN=\033[0;32m
BLUE=\033[0;34m
YELLOW=\033[1;33m
RED=\033[0;31m
NC=\033[0m
else
# Unix Systems Have Full ANSI Color Support
GREEN=\033[0;32m
BLUE=\033[0;34m
YELLOW=\033[1;33m
RED=\033[0;31m
NC=\033[0m
endif
# Default Goal
.DEFAULT_GOAL := help
# Utility Echo And Color Variable Aliases
ECHO_CMD=echo
GREEN_START=${GREEN}
BLUE_START=${BLUE}
YELLOW_START=${YELLOW}
RED_START=${RED}
COLOR_END=${NC}
# Compose Helpers And Sonar Config
COMPOSE_FILE ?= docker-compose.yml
DOCKER_COMPOSE ?= docker compose
PODMAN_COMPOSE ?= podman compose
SONAR_HOST_URL ?= http://localhost:9000
SONAR_PROJECT_KEY ?= InitStack
# Environment Variables Loading
ifneq (,$(wildcard ./.env))
# Read .env File And Export Variables
include ./.env
export $(shell sed 's/=.*//' ./.env)
endif
# Help Target: Show Available Makefile Commands
help:
@echo ""
@printf "${BLUE}InitStack Makefile Commands${NC}\n"
@echo ""
@printf "${GREEN}General:${NC}\n"
@echo " help - Show This Help Message"
@echo ""
@printf "${GREEN}Code Analysis:${NC}\n"
@echo " sonar-scan - Run SonarQube Analysis (Requires SONAR_TOKEN Env Var)"
@echo " ruff-check - Run Ruff Linter In Check Mode"
@echo " ruff-lint - Run Ruff Linter With Auto-Fix"
@echo ""
@printf "${GREEN}Podman:${NC}\n"
@echo " podman-build - Build All Services"
@echo " podman-up - Build And Start All Services"
@echo " podman-down - Stop And Remove Services"
@echo " podman-restart - Restart All Services"
@echo " podman-clean - Clean Unused Podman Resources"
@echo ""
@printf "${GREEN}Docker:${NC}\n"
@echo " docker-build - Build All Services"
@echo " docker-up - Build And Start All Services"
@echo " docker-down - Stop And Remove Services"
@echo " docker-restart - Restart All Services"
@echo " docker-clean - Clean Unused Docker Resources"
@echo ""
@printf "${GREEN}Cleaning:${NC}\n"
@echo " clean-all - Remove Python And Tooling Artifacts"
@echo " fix-line-endings - Convert Line Endings To Unix Format For Windows Compatibility"
@echo ""
# Sonar-Scan Target: Run SonarQube Analysis
sonar-scan:
@echo ""
@printf "${YELLOW}Starting SonarScanner...${NC}\n"
@if [ -f .env ]; then \
export $$(cat .env | grep -v '^#' | xargs) && \
[ -n "$$SONAR_TOKEN" ] || (printf "${RED}SONAR_TOKEN Is Not Set. Check Your .env File.${NC}\n"; exit 1) && \
pysonar \
--sonar-host-url $(SONAR_HOST_URL) \
--sonar-project-key $(SONAR_PROJECT_KEY) \
--token $$SONAR_TOKEN; \
else \
[ -n "$$SONAR_TOKEN" ] || (printf "${RED}SONAR_TOKEN Is Not Set. Export SONAR_TOKEN And Re-Run.${NC}\n"; exit 1) && \
pysonar \
--sonar-host-url $(SONAR_HOST_URL) \
--sonar-project-key $(SONAR_PROJECT_KEY) \
--token $$SONAR_TOKEN; \
fi
@printf "${GREEN}SonarQube Scan Completed!${NC}\n"
@echo ""
# Podman-Build Target: Build All Services
podman-build:
@echo ""
@printf "${YELLOW}Building All Services...${NC}\n"
$(PODMAN_COMPOSE) -f $(COMPOSE_FILE) build --detach
@printf "${GREEN}Services Built Successfully!${NC}\n"
@echo ""
# Podman-Up Target: Build And Start All Services
podman-up:
@echo ""
@printf "${YELLOW}Building And Starting Services...${NC}\n"
$(PODMAN_COMPOSE) -f $(COMPOSE_FILE) up -d --build
@printf "${GREEN}Services Built And Started Successfully!${NC}\n"
@echo ""
# Podman-Down Target: Stop And Remove Services
podman-down:
@echo ""
@printf "${YELLOW}Stopping And Removing Services...${NC}\n"
$(PODMAN_COMPOSE) -f $(COMPOSE_FILE) down --remove-orphans
@printf "${GREEN}Services Stopped And Removed Successfully!${NC}\n"
@echo ""
# Podman-Restart Target: Restart All Services
podman-restart:
@echo ""
@printf "${YELLOW}Restarting Services...${NC}\n"
$(PODMAN_COMPOSE) -f $(COMPOSE_FILE) restart
@printf "${GREEN}Services Restarted Successfully!${NC}\n"
@echo ""
# Podman-Clean Target: Prune Unused Podman Resources
podman-clean:
@echo ""
@printf "${YELLOW}Cleaning Unused Podman Resources...${NC}\n"
podman system prune -f --filter "until=24h"
podman builder prune -f
@printf "${GREEN}Podman Resources Cleaned Successfully!${NC}\n"
@echo ""
# Docker-Build Target: Build All Services With Docker
docker-build:
@echo ""
@printf "${YELLOW}Building All Services With Docker...${NC}\n"
$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) build
@printf "${GREEN}Services Built Successfully With Docker!${NC}\n"
@echo ""
# Docker-Up Target: Build And Start All Services With Docker
docker-up:
@echo ""
@printf "${YELLOW}Building And Starting Services With Docker...${NC}\n"
$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) up -d --build
@printf "${GREEN}Services Built And Started Successfully With Docker!${NC}\n"
@echo ""
# Docker-Down Target: Stop And Remove Services With Docker
docker-down:
@echo ""
@printf "${YELLOW}Stopping And Removing Services With Docker...${NC}\n"
$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) down --remove-orphans
@printf "${GREEN}Services Stopped And Removed Successfully With Docker!${NC}\n"
@echo ""
# Docker-Restart Target: Restart Services With Docker
docker-restart:
@echo ""
@printf "${YELLOW}Restarting Services With Docker...${NC}\n"
$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) restart
@printf "${GREEN}Services Restarted Successfully With Docker!${NC}\n"
@echo ""
# Docker-Clean Target: Prune Unused Docker Resources
docker-clean:
@echo ""
@printf "${YELLOW}Cleaning Unused Docker Resources...${NC}\n"
docker system prune -f --filter "until=24h"
docker builder prune -f
@printf "${GREEN}Docker Resources Cleaned Successfully!${NC}\n"
@echo ""
# Clean-All Target: Remove Python, Tooling, Celery, And Coverage Artifacts
clean-all:
@echo ""
@printf "${YELLOW}Cleaning All Python And Tooling Artifacts...${NC}\n"
find . -type d -name 'build' -prune -exec rm -rf {} +
find . -type d -name 'dist' -prune -exec rm -rf {} +
find . -type d -name 'sdist' -prune -exec rm -rf {} +
find . -type d -name 'wheels' -prune -exec rm -rf {} +
find . -type d -name '*.egg-info' -prune -exec rm -rf {} +
find . -type d -name 'pip-wheel-metadata' -prune -exec rm -rf {} +
find . -type d -name '__pycache__' -prune -exec rm -rf {} +
find . -type d -name '.pytest_cache' -prune -exec rm -rf {} +
find . -type d -name '.mypy_cache' -prune -exec rm -rf {} +
find . -type d -name '.ruff_cache' -prune -exec rm -rf {} +
find . -type d -name '.tox' -prune -exec rm -rf {} +
find . -type d -name '.nox' -prune -exec rm -rf {} +
find . -type d -name '.cache' -prune -exec rm -rf {} +
find . -type d -name 'htmlcov' -prune -exec rm -rf {} +
find . -type d -name '.scannerwork' -prune -exec rm -rf {} +
find . -type f -name '.coverage' -exec rm -f {} \;
find . -type f -name '.coverage.*' -delete
find . -type f -name 'coverage.xml' -delete
find . -type d -name 'coverage' -prune -exec rm -rf {} +
find . -type f -name '*.pyc' -delete
find . -type f -name '*.pyo' -delete
find . -type f -name 'celery.pid' -delete
find . -type f -name 'celerybeat.pid' -delete
find . -type f -name 'celerybeat-schedule' -delete
find . -type f -name 'celerybeat-schedule.db' -delete
find . -type f -name 'celerybeat-schedule.*' -delete
find . -type d -name 'celerybeat-schedule' -prune -exec rm -rf {} +
find . -type f -name 'flower.pid' -delete
@printf "${GREEN}Cleanup Completed Successfully!${NC}\n"
@echo ""
# Fix-Line-Endings Target: Convert Line Endings To Unix Format
fix-line-endings:
@echo ""
@printf "${YELLOW}Converting Line Endings For Windows Compatibility...${NC}\n"
dos2unix ./compose/django/entrypoint
dos2unix ./compose/django/start
dos2unix ./compose/celery-flower/start
@printf "${GREEN}Line Endings Converted Successfully!${NC}\n"
@echo ""
# Ruff-Check Target: Run Ruff Linter In Check Mode
ruff-check:
@echo ""
@printf "${YELLOW}Running Ruff Linter In Check Mode...${NC}\n"
ruff check .
@printf "${GREEN}Ruff Check Completed!${NC}\n"
@echo ""
# Ruff-Lint Target: Run Ruff Linter With Auto-Fix
ruff-lint:
@echo ""
@printf "${YELLOW}Running Ruff Linter With Auto-Fix...${NC}\n"
ruff check --fix .
@printf "${GREEN}Ruff Lint Completed!${NC}\n"
@echo ""
# Phony Targets Declaration
.PHONY: help sonar-scan ruff-check ruff-lint clean-all \
podman-build podman-up podman-restart podman-clean \
podman-down \
docker-build docker-up docker-restart docker-clean docker-down fix-line-endings