-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
297 lines (229 loc) · 9.16 KB
/
Copy pathMakefile
File metadata and controls
297 lines (229 loc) · 9.16 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
.PHONY: help build up down logs shell migrate test clean
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m
help:
@echo ""
@echo "$(BLUE)╔═══════════════════════════════════════════════════════════╗$(NC)"
@echo "$(BLUE)║$(NC) $(GREEN)🛡️ Parvahan - Enterprise Proxy Platform$(NC) $(BLUE)║$(NC)"
@echo "$(BLUE)╚═══════════════════════════════════════════════════════════╝$(NC)"
@echo ""
@echo "$(YELLOW)Development:$(NC)"
@echo " make setup - Initial setup (first time)"
@echo " make build - Build all Docker images"
@echo " make up - Start all services"
@echo " make down - Stop all services"
@echo " make restart - Restart all services"
@echo " make logs - View logs (all services)"
@echo " make logs-core - View parvahan-core logs"
@echo " make logs-admin - View parvahan-admin logs"
@echo " make logs-ui - View parvahan-ui logs"
@echo ""
@echo "$(YELLOW)Database:$(NC)"
@echo " make migrate - Run database migrations"
@echo " make makemigrations - Create new migrations"
@echo " make shell - Open Django shell"
@echo " make dbshell - Open PostgreSQL shell"
@echo " make backup-db - Backup database"
@echo ""
@echo "$(YELLOW)Testing:$(NC)"
@echo " make test - Run all tests"
@echo " make test-core - Run parvahan-core tests"
@echo " make test-admin - Run parvahan-admin tests"
@echo " make test-unit - Run unit tests only"
@echo " make test-integration - Run integration tests"
@echo " make test-load - Run k6 load tests"
@echo " make lint - Run linters"
@echo ""
@echo "$(YELLOW)Monitoring:$(NC)"
@echo " make monitoring-up - Start monitoring stack"
@echo " make monitoring-down - Stop monitoring stack"
@echo ""
@echo "$(YELLOW)Kubernetes:$(NC)"
@echo " make k8s-apply - Apply Kubernetes manifests"
@echo " make k8s-delete - Delete Kubernetes resources"
@echo " make k8s-status - Show Kubernetes status"
@echo " make k8s-logs - View Kubernetes logs"
@echo ""
@echo "$(YELLOW)Infrastructure:$(NC)"
@echo " make vagrant-up - Start Vagrant VM"
@echo " make vagrant-ssh - SSH into Vagrant VM"
@echo " make terraform-plan - Terraform plan"
@echo " make terraform-apply - Terraform apply"
@echo ""
@echo "$(YELLOW)Utilities:$(NC)"
@echo " make clean - Remove all containers and volumes"
@echo " make prune - Docker system prune"
@echo " make status - Show service status"
@echo " make version - Show version info"
@echo ""
setup:
@echo "$(GREEN)Setting up Parvahan...$(NC)"
@cp -n .env.example .env 2>/dev/null || true
@./scripts/setup.sh
@echo "$(GREEN)Setup complete!$(NC)"
build:
@echo "$(BLUE)Building Docker images...$(NC)"
docker compose build
build-no-cache:
@echo "$(BLUE)Building Docker images (no cache)...$(NC)"
docker compose build --no-cache
up:
@echo "$(GREEN)Starting Parvahan services...$(NC)"
docker compose up -d
@echo "$(GREEN)Services started! Access at http://localhost$(NC)"
up-logs:
docker compose up
down:
@echo "$(YELLOW)Stopping Parvahan services...$(NC)"
docker compose down
restart:
@echo "$(YELLOW)Restarting Parvahan services...$(NC)"
docker compose restart
logs:
docker compose logs -f
logs-core:
docker compose logs -f parvahan-core
logs-admin:
docker compose logs -f parvahan-admin
logs-ui:
docker compose logs -f parvahan-ui
logs-traefik:
docker compose logs -f traefik
migrate:
@echo "$(BLUE)Running database migrations...$(NC)"
docker compose exec parvahan-admin python manage.py migrate
makemigrations:
docker compose exec parvahan-admin python manage.py makemigrations
shell:
docker compose exec parvahan-admin python manage.py shell
dbshell:
docker compose exec postgres psql -U parvahan -d parvahan
create-admin:
docker compose exec parvahan-admin python manage.py createsuperuser
collectstatic:
docker compose exec parvahan-admin python manage.py collectstatic --noinput
backup-db:
@echo "$(BLUE)Backing up database...$(NC)"
@mkdir -p backups
docker compose exec postgres pg_dump -U parvahan parvahan > backups/parvahan_$$(date +%Y%m%d_%H%M%S).sql
@echo "$(GREEN)Backup saved to backups/$(NC)"
restore-db:
@echo "Usage: cat backups/backup.sql | docker compose exec -T postgres psql -U parvahan -d parvahan"
test:
@echo "$(BLUE)Running all tests...$(NC)"
docker compose exec parvahan-admin pytest -v
docker compose exec parvahan-core pytest -v
test-core:
@echo "$(BLUE)Running parvahan-core tests...$(NC)"
docker compose exec parvahan-core pytest -v
test-admin:
@echo "$(BLUE)Running parvahan-admin tests...$(NC)"
docker compose exec parvahan-admin pytest -v
test-unit:
@echo "$(BLUE)Running unit tests...$(NC)"
pytest tests/unit -v
test-integration:
@echo "$(BLUE)Running integration tests...$(NC)"
pytest tests/integration -v --run-integration
test-load:
@echo "$(BLUE)Running k6 load tests...$(NC)"
docker compose --profile testing run k6
test-coverage:
docker compose exec parvahan-admin pytest --cov=apps --cov-report=html
docker compose exec parvahan-core pytest --cov=. --cov-report=html
lint:
@echo "$(BLUE)Running linters...$(NC)"
docker compose exec parvahan-core ruff check .
docker compose exec parvahan-admin ruff check .
lint-fix:
docker compose exec parvahan-core ruff check --fix .
docker compose exec parvahan-admin ruff check --fix .
format:
docker compose exec parvahan-core ruff format .
docker compose exec parvahan-admin ruff format .
monitoring-up:
@echo "$(BLUE)Starting monitoring stack...$(NC)"
docker compose up -d prometheus grafana alertmanager node-exporter redis-exporter postgres-exporter
monitoring-down:
docker compose stop prometheus grafana alertmanager node-exporter redis-exporter postgres-exporter
logging-up:
@echo "$(BLUE)Starting logging stack...$(NC)"
docker compose --profile logging up -d
k8s-apply:
@echo "$(BLUE)Applying Kubernetes manifests...$(NC)"
kubectl apply -k kubernetes/base/
k8s-delete:
@echo "$(RED)Deleting Kubernetes resources...$(NC)"
kubectl delete -k kubernetes/base/
k8s-status:
kubectl get all -n parvahan
k8s-logs:
kubectl logs -f deployment/parvahan-core -n parvahan
k8s-logs-admin:
kubectl logs -f deployment/parvahan-admin -n parvahan
k8s-port-forward:
@echo "$(GREEN)Forwarding ports...$(NC)"
@echo "Dashboard: http://localhost:8080"
@echo "Proxy: http://localhost:3128"
kubectl port-forward svc/traefik 8080:80 -n parvahan &
kubectl port-forward svc/parvahan-core 3128:8080 -n parvahan &
k8s-scale-core:
kubectl scale deployment/parvahan-core --replicas=$(n) -n parvahan
vagrant-up:
@echo "$(BLUE)Starting Vagrant VM...$(NC)"
cd infrastructure/vagrant && vagrant up
vagrant-ssh:
cd infrastructure/vagrant && vagrant ssh
vagrant-halt:
cd infrastructure/vagrant && vagrant halt
vagrant-destroy:
cd infrastructure/vagrant && vagrant destroy -f
terraform-init:
cd infrastructure/terraform/arvancloud && terraform init
terraform-plan:
cd infrastructure/terraform/arvancloud && terraform plan
terraform-apply:
cd infrastructure/terraform/arvancloud && terraform apply
terraform-destroy:
cd infrastructure/terraform/arvancloud && terraform destroy
opentofu-init:
cd infrastructure/opentofu/arvancloud && tofu init
opentofu-plan:
cd infrastructure/opentofu/arvancloud && tofu plan
opentofu-apply:
cd infrastructure/opentofu/arvancloud && tofu apply
clean:
@echo "$(RED)Cleaning up...$(NC)"
docker compose down -v --remove-orphans
docker system prune -f
prune:
@echo "$(RED)Pruning Docker system...$(NC)"
docker system prune -af
status:
@echo "$(BLUE)Service Status:$(NC)"
@docker compose ps
version:
@echo "$(BLUE)Parvahan Version Info:$(NC)"
@echo "Docker Compose: $$(docker compose version)"
@echo "Docker: $$(docker --version)"
@if command -v kubectl &> /dev/null; then echo "Kubectl: $$(kubectl version --client --short 2>/dev/null || kubectl version --client)"; fi
scale-proxy:
docker compose up -d --scale parvahan-core=$(n)
generate-certs:
@echo "$(BLUE)Generating self-signed certificates...$(NC)"
@mkdir -p traefik/certs
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout traefik/certs/parvahan.key \
-out traefik/certs/parvahan.crt \
-subj "/CN=parvahan.dwin.codes"
@echo "$(GREEN)Certificates generated in traefik/certs/$(NC)"
health:
@echo "$(BLUE)Checking service health...$(NC)"
@curl -sf http://localhost:8082/health && echo "$(GREEN)Parvahan Core: ✓$(NC)" || echo "$(RED)Parvahan Core: ✗$(NC)"
@curl -sf http://localhost:8099/api/v1/health/ && echo "$(GREEN)Parvahan Admin: ✓$(NC)" || echo "$(RED)Parvahan Admin: ✗$(NC)"
@curl -sf http://localhost:3000/ && echo "$(GREEN)Parvahan UI: ✓$(NC)" || echo "$(RED)Parvahan UI: ✗$(NC)"
@curl -sf http://localhost:9090/-/healthy && echo "$(GREEN)Prometheus: ✓$(NC)" || echo "$(RED)Prometheus: ✗$(NC)"
@curl -sf http://localhost:3001/api/health && echo "$(GREEN)Grafana: ✓$(NC)" || echo "$(RED)Grafana: ✗$(NC)"