-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
538 lines (449 loc) · 18.1 KB
/
Makefile
File metadata and controls
538 lines (449 loc) · 18.1 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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# Media Vault - Makefile
# Color definitions
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
# Default target
.DEFAULT_GOAL := help
# Phony targets - Keep this list in sync with actual targets
.PHONY: help \
init \
up up-build down restart \
build rebuild \
test test-unit test-integration test-e2e \
lint format \
logs \
clean clean-all \
setup-keycloak keycloak-clean keycloak-export \
deploy \
monitoring monitoring-down monitoring-restart monitoring-logs monitoring-status \
grafana prometheus alerts \
status shell-api shell-keycloak \
dev-start prod-setup backup \
keycloak keycloak-db media-vault-api media-vault-analyzer nsfw-analyzer flutter-web media-vault-admin caddy redis
## Help
help: ## Show this help
@echo 'Media Vault - Available Commands:'
@echo '================================='
@echo ''
@echo '🚀 Quick Start:'
@echo ' make up Start basic application stack'
@echo ' make up-build Rebuild and start all services'
@echo ' make full-stack Complete setup with monitoring'
@echo ' make dev-start Quick start for development'
@echo ''
@echo '📊 Monitoring:'
@echo ' make monitoring Start monitoring stack'
@echo ' make monitoring-status Show monitoring status'
@echo ' make monitoring-logs Show monitoring logs'
@echo ' make grafana Open Grafana (http://localhost:3333)'
@echo ' make prometheus Open Prometheus (http://localhost:9090)'
@echo ' make alerts Open AlertManager (http://localhost:9093)'
@echo ''
@echo '🔐 Authentication:'
@echo ' make setup-keycloak Configure Keycloak'
@echo ' make keycloak-clean Reset Keycloak config'
@echo ' make keycloak-export Export Keycloak configuration'
@echo ''
@echo '🛠️ Individual Services:'
@echo ' make keycloak Start Keycloak service'
@echo ' make keycloak-db Start Keycloak database'
@echo ' make media-vault-api Start Media Vault API'
@echo ' make media-vault-analyzer Start AI Processing service'
@echo ' make nsfw-analyzer Start NSFW Analyzer service'
@echo ' make flutter-web Start Flutter Web Frontend'
@echo ' make media-vault-admin Start Admin Panel'
@echo ' make caddy Start Caddy Reverse Proxy'
@echo ' make redis Start Redis Cache'
@echo ''
@echo '🔧 Management:'
@echo ' make down Stop all services'
@echo ' make restart Restart all services'
@echo ' make clean Clean up containers and volumes'
@echo ' make clean-all Remove all containers, volumes, and images'
@echo ' make logs Show application logs'
@echo ' make status Show container status'
@echo ' make backup Create database backup'
@echo ' make prod-setup Configure production settings'
@echo ''
@echo '🔍 Development:'
@echo ' make test Run all tests'
@echo ' make lint Run linters'
@echo ' make format Format code'
@echo ' make coverage Generate test coverage report'
## Environment
init: ## Initialize development environment
@echo "${GREEN}🚀 Initializing development environment...${RESET}"
cp .env.example .env
@echo "✅ Created .env file"
@echo "${YELLOW}ℹ️ Please edit .env with your configuration${RESET}"
## Docker Composee
up: ## Start all services
@echo "${GREEN}🚀 Starting all services...${RESET}"
docker-compose up -d
up-build: ## Rebuild and start all services
@echo "${GREEN}🚀 Rebuilding and starting all services...${RESET}"
docker-compose up -d --build
down: ## Stop and remove all services
@echo "${YELLOW}🛑 Stopping and removing all services...${RESET}"
docker-compose down
stop: ## Stop all services without removing containers
@echo "${YELLOW}🛑 Stopping all services (containers will remain)...${RESET}"
docker-compose stop
restart: ## Restart all services
@echo "${YELLOW}🔄 Restarting all services...${RESET}"
docker-compose restart
logs: ## View logs from all services
docker-compose logs -f
status: ## Show container status
docker-compose ps
shell-api: ## Open shell in API container
docker-compose exec media-vault-api sh
shell-keycloak: ## Open shell in Keycloak container
docker-compose exec keycloak bash
## Development
dev: up ## Start development environment
run-browse: up ## Start services and open in browser
@echo "${GREEN}🌐 Opening application in browser...${RESET}"
@if command -v xdg-open > /dev/null; then \
xdg-open http://localhost; \
elif command -v open > /dev/null; then \
open http://localhost; \
else \
echo "${YELLOW}Could not detect the web browser to use. Please open http://localhost manually${RESET}"; \
fi
## Testing
test: test-unit test-integration ## Run all tests
test-unit: ## Run unit tests
@echo "🧪 Running unit tests..."
docker-compose run --rm media-vault-api go test -v ./... -short
test-integration: ## Run integration tests
@echo "${GREEN}🧪 Running integration tests...${RESET}"
docker-compose -f docker-compose.test.yml up --abort-on-container-exit
test-e2e: ## Run end-to-end tests
@echo "${GREEN}🧪 Running E2E tests...${RESET}"
# TODO: Add E2E test command
coverage: ## Generate test coverage report
@echo "${GREEN}📊 Generating test coverage...${RESET}"
docker-compose run --rm media-vault-api go test -coverprofile=coverage.out ./...
docker-compose run --rm media-vault-api go tool cover -html=coverage.out -o coverage.html
## Code Quality
lint: ## Run linters
@echo "${GREEN}🔍 Running linters...${RESET}"
docker-compose run --rm media-vault-api golangci-lint run
format: ## Format code
@echo "${GREEN}🎨 Formatting code...${RESET}"
docker-compose run --rm media-vault-api gofmt -w .
## Monitoring
monitoring: ## Start monitoring stack
@echo "${GREEN}📊 Starting monitoring stack...${RESET}"
docker-compose -f docker-compose.monitoring.yml up -d
monitoring-down: ## Stop monitoring stack
@echo "${YELLOW}🛑 Stopping monitoring stack...${RESET}"
docker-compose -f docker-compose.monitoring.yml down
monitoring-restart: ## Restart monitoring stack
@echo "🔄 Restarting monitoring stack..."
docker-compose -f docker-compose.monitoring.yml restart
monitoring-logs: ## Show monitoring logs
@echo "📜 Showing monitoring logs..."
docker-compose -f docker-compose.monitoring.yml logs -f
monitoring-status: ## Show monitoring status
@echo "📊 Monitoring Status:"
@echo "===================="
docker-compose -f docker-compose.monitoring.yml ps
grafana: ## Open Grafana dashboard
@echo "🌐 Opening Grafana..."
@echo "URL: http://localhost:3333"
@echo "Login: admin / grafana123"
prometheus: ## Open Prometheus dashboard
@echo "🌐 Opening Prometheus..."
@echo "URL: http://localhost:9090"
alerts: ## Open AlertManager
@echo "🌐 Opening AlertManager..."
@echo "URL: http://localhost:9093"
## Keycloak Management
setup-keycloak: ## Set up Keycloak with initial configuration
@echo "${GREEN}🔐 Setting up Keycloak...${RESET}"
./keycloak/setup-keycloak.sh
keycloak-clean: ## Reset Keycloak configuration
@echo "${YELLOW}🧹 Cleaning Keycloak configuration...${RESET}"
./setup-keycloak.sh --clean
keycloak-export: ## Export Keycloak configuration
@echo "${GREEN}💾 Exporting Keycloak configuration...${RESET}"
./setup-keycloak.sh --export-only
restart-keycloak: ## Restart Keycloak service
@echo "🔄 Restarting Keycloak..."
docker-compose restart keycloak
## Deployment
deploy: ## Deploy to production
@echo "${GREEN}🚀 Deploying to production...${RESET}"
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build
## Cleanup
clean: ## Remove all containers and volumes
@echo "${YELLOW}🧹 Cleaning up...${RESET}"
docker-compose down -v
clean-all: ## Remove all containers, volumes, and images
@echo "${YELLOW}🧹 Deep cleaning (containers, volumes, and images)...${RESET}"
docker-compose down -v --rmi all --remove-orphans
dev-clean: clean ## Clean development environment
@echo "${YELLOW}🧹 Cleaning development environment...${RESET}"
rm -rf node_modules
## Documentation
docs: ## Generate documentation
@echo "${GREEN}📚 Generating documentation...${RESET}"
# TODO: Add documentation generation command
## Complete Setup
full-stack: setup-keycloak up monitoring ## Start complete stack with monitoring
@echo "${GREEN}🎉 Media Vault is ready!${RESET}"
@echo ""
@echo "${YELLOW}📊 Service URLs:${RESET}"
@echo " 🌐 Main App: http://localhost"
@echo " 📊 Grafana: http://localhost:3333 (admin/grafana123)"
@echo " 📈 Prometheus: http://localhost:9090"
@echo " 🔐 Keycloak: http://localhost:8080/admin (admin/admin123)"
@echo " ⚠️ AlertManager: http://localhost:9093"
## Service Management
# Keycloak Services
keycloak: ## Start Keycloak identity service
@echo "${GREEN}🚀 Starting Keycloak service...${RESET}"
docker-compose rm -fsv keycloak 2>/dev/null || true
docker-compose up -d --remove-orphans keycloak
@echo "✅ Keycloak service started"
@echo "🌐 Access at: http://localhost:8080/admin (admin/admin123)"
keycloak-db: ## Start Keycloak database
@echo "${GREEN}🚀 Starting Keycloak database...${RESET}"
docker-compose rm -fsv keycloak-db 2>/dev/null || true
docker-compose up -d --remove-orphans keycloak-db
@echo "✅ Keycloak database started"
# Media Vault Services
media-vault-api: ## Start Media Vault API
@echo "${GREEN}🚀 Starting Media Vault API...${RESET}"
docker-compose rm -fsv media-vault-api 2>/dev/null || true
docker-compose up -d --remove-orphans media-vault-api
@echo "✅ Media Vault API started"
media-vault-analyzer: ## Start Media Vault Analyzer (AI Processing)
@echo "${GREEN}🚀 Starting Media Vault Analyzer...${RESET}"
docker-compose rm -fsv media-vault-analyzer 2>/dev/null || true
docker-compose up -d --remove-orphans media-vault-analyzer
@echo "✅ Media Vault Analyzer started"
nsfw-analyzer: ## Start NSFW Analyzer Service
@echo "${GREEN}🚀 Starting NSFW Analyzer...${RESET}"
docker-compose rm -fsv nsfw-analyzer 2>/dev/null || true
docker-compose up -d --remove-orphans nsfw-analyzer
@echo "✅ NSFW Analyzer started"
# Frontend Services
flutter-web: ## Start Flutter Web Frontend
@echo "${GREEN}🚀 Starting Flutter Web Frontend...${RESET}"
docker-compose rm -fsv flutter-web 2>/dev/null || true
docker-compose up -d --remove-orphans flutter-web
@echo "✅ Flutter Web Frontend started"
@echo "🌐 Access at: http://localhost:3000"
media-vault-admin: ## Start Media Vault Admin Panel
@echo "${GREEN}🚀 Starting Media Vault Admin Panel...${RESET}"
docker-compose rm -fsv media-vault-admin 2>/dev/null || true
docker-compose up -d --remove-orphans media-vault-admin
@echo "✅ Media Vault Admin Panel started"
@echo "🌐 Access at: http://localhost:3001"
# Infrastructure Services
caddy: ## Start Caddy Reverse Proxy
@echo "${GREEN}🚀 Starting Caddy Reverse Proxy...${RESET}"
docker-compose rm -fsv caddy 2>/dev/null || true
docker-compose up -d --remove-orphans caddy
@echo "✅ Caddy Reverse Proxy started"
redis: ## Start Redis Cache
@echo "${GREEN}🚀 Starting Redis...${RESET}"
docker-compose rm -fsv redis 2>/dev/null || true
docker-compose up -d --remove-orphans redis
@echo "✅ Redis started"
## Development
dev-start: clean up ## Quick start for development
@echo "🚀 Development environment ready!"
## Production
prod-setup: ## Production setup instructions
@echo "🏭 Production setup..."
@echo "⚠️ Remember to:"
@echo " 1. Change default passwords"
@echo " 2. Configure SSL"
@echo " 3. Set up backup strategy"
@echo " 4. Configure monitoring"
## Backup
backup: ## Create database backup
@echo "💾 Creating backup..."
@mkdir -p backups
docker-compose exec media-vault-api sqlite3 /data/media.db ".backup /data/backup_$$(date +%Y%m%d_%H%M%S).db"
./setup-keycloak.sh --export-only
tar -czf backups/media-vault-backup-$$(date +%Y%m%d).tar.gz data/ uploads/ media-vault-realm-export.json 2>/dev/null || true
@echo "✅ Backup created: backups/media-vault-backup-$$(date +%Y%m%d).tar.gz"
## Infrastructure
infrastructure: ## Start infrastructure services
@echo "${GREEN}🏗️ Starting infrastructure stack...${RESET}"
docker-compose -f docker-compose.infrastructure.yml up -d
monitoring: ## Start monitoring stack
@echo "${GREEN}📊 Starting monitoring stack...${RESET}"
docker-compose -f docker-compose.monitoring.yml up -d
@echo "✅ Monitoring started"
@echo "📊 Grafana: http://localhost:3333"
@echo "📈 Prometheus: http://localhost:9090"
monitoring-down:
@echo "📊 Stopping monitoring stack..."
docker-compose -f docker-compose.monitoring.yml down
# Quick monitoring access
grafana:
@echo "🌐 Opening Grafana..."
@echo "URL: http://localhost:3333"
@echo "Login: admin / grafana123"
prometheus:
@echo "🌐 Opening Prometheus..."
@echo "URL: http://localhost:9090"
alerts:
@echo "🌐 Opening AlertManager..."
@echo "URL: http://localhost:9093"
# Monitoring management
monitoring-restart:
docker-compose -f docker-compose.monitoring.yml restart
monitoring-logs:
docker-compose -f docker-compose.monitoring.yml logs -f
monitoring-status:
@echo "📊 Monitoring Status:"
@echo "===================="
@docker-compose -f docker-compose.monitoring.yml ps
# Dashboard management
dashboard-import:
@echo "📊 Importing custom dashboards..."
# Custom script to import dashboards via Grafana API
dashboard-backup:
@echo "💾 Backing up Grafana dashboards..."
# Custom script to export dashboards
# Alerting management
test-alerts:
@echo "🚨 Testing alert system..."
curl -XPOST http://localhost:9093/api/v1/alerts \
-H "Content-Type: application/json" \
-d '[{"labels":{"alertname":"TestAlert","severity":"warning","instance":"test"},"annotations":{"summary":"Test alert"}}]'
silence-alerts:
@echo "🔇 Creating alert silence..."
# Script to create alert silence via AlertManager API
# Performance testing with monitoring
load-test-monitored:
@echo "⚡ Running monitored load test..."
docker run --rm -i --network media-vault-network \
grafana/k6 run - <<EOF
import http from 'k6/http';
import { check } from 'k6';
export let options = {
stages: [
{ duration: '2m', target: 50 },
{ duration: '5m', target: 50 },
{ duration: '2m', target: 100 },
{ duration: '5m', target: 100 },
{ duration: '2m', target: 0 },
],
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.1'],
},
};
export default function() {
let response = http.get('http://media-vault-api:8080/health');
check(response, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
}
EOF
# System health check
health-check-full:
@echo "🏥 Comprehensive Health Check:"
@echo "=============================="
@echo "📊 Checking main services..."
@curl -s http://localhost:8080/health | jq '.' || echo "❌ API: DOWN"
@curl -s http://localhost:8443/health/ready | jq '.' || echo "❌ Keycloak: DOWN"
@echo ""
@echo "📊 Checking monitoring..."
@curl -s http://localhost:9090/-/healthy || echo "❌ Prometheus: DOWN"
@curl -s http://localhost:3333/api/health || echo "❌ Grafana: DOWN"
@curl -s http://localhost:9093/-/healthy || echo "❌ AlertManager: DOWN"
@echo ""
@echo "📊 Checking containers..."
@docker-compose ps
@echo ""
@echo "📊 Resource usage:"
@docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}"
# Backup monitoring data
backup-monitoring:
@echo "💾 Backing up monitoring data..."
docker run --rm -v grafana_data:/source -v $(PWD)/backups:/backup alpine tar czf /backup/grafana-backup-$(shell date +%Y%m%d).tar.gz -C /source .
docker run --rm -v prometheus_data:/source -v $(PWD)/backups:/backup alpine tar czf /backup/prometheus-backup-$(shell date +%Y%m%d).tar.gz -C /source .
# Podstawowe komendy
build:
docker-compose build
up:
docker-compose up -d
up-full:
docker-compose --profile full up -d
down:
docker-compose down
logs:
docker-compose logs -f
clean:
docker-compose down -v
docker system prune -f
# Keycloak setup
setup-keycloak:
@echo "🔐 Konfigurowanie Keycloak..."
docker-compose up -d keycloak keycloak-db
sleep 30
chmod +x keycloak/setup-keycloak.sh
./keycloak/setup-keycloak.sh
./update-env.sh
# Keycloak management
keycloak-clean:
./setup-keycloak.sh --clean
keycloak-export:
./setup-keycloak.sh --export-only
# Media Vault with Keycloak
up-with-auth: setup-keycloak
docker-compose up -d
@echo ""
@echo "🎉 Media Vault z Keycloak uruchomiony!"
@echo "🌐 Aplikacja: http://localhost"
@echo "🔐 Keycloak Admin: http://localhost:8443/admin"
@echo "👤 Test login: vaultadmin / admin123"
# Restart specific services
restart-api:
docker-compose restart media-vault-api
restart-keycloak:
docker-compose restart keycloak
# Status and debugging
status:
docker-compose ps
shell-api:
docker-compose exec media-vault-api sh
shell-keycloak:
docker-compose exec keycloak bash
# Quick start dla development
dev-start: clean up-with-auth
@echo "🚀 Development environment ready!"
## Production Setup
prod-setup: ## Configure production settings
@echo "${YELLOW}⚠️ Production Setup${RESET}"
@echo "Please ensure you have configured:"
@echo " 1. Strong passwords in production"
@echo " 2. SSL/TLS configuration"
@echo " 3. Backup strategy"
@echo " 4. Monitoring and alerting"
## Backup
backup: ## Create database backup
@echo "${GREEN}💾 Creating backup...${RESET}
@mkdir -p backups
docker-compose exec media-vault-api sqlite3 /data/media.db ".backup /data/backup_$(shell date +%Y%m%d_%H%M%S).db"
./setup-keycloak.sh --export-only
tar -czf backups/media-vault-backup-$(shell date +%Y%m%d_%H%M%S).tar.gz data/ uploads/ media-vault-realm-export.json
@echo "✅ Backup created in backups/ directory"
## Health Check
health-check: ## Run comprehensive health check
@echo "🏥 Running health checks..."
@echo "📊 Checking main services..."
@curl -s http://localhost:8080/health | jq '.' || echo "❌ API: DOWN"
@echo "✅ Health check completed"