-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
382 lines (303 loc) · 13.3 KB
/
Copy pathMakefile
File metadata and controls
382 lines (303 loc) · 13.3 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
# FFprobe API - Automated Build and Deployment
# Simple commands for all platforms and deployment modes
.PHONY: help install quick prod dev clean test test-unit test-coverage test-coverage-html test-race test-short test-all test-ffmpeg test-ai test-integration test-benchmark http-benchmark build docker health logs backup
# Default target
help: ## Show this help message
@echo "FFprobe API - Automated Deployment Commands"
@echo ""
@echo "🚀 QUICK START:"
@echo " make install # One-command setup (recommended)"
@echo " make quick # Quick development setup"
@echo ""
@echo "📦 DEPLOYMENT MODES:"
@echo " make minimal # Minimal (4 core services)"
@echo " make quick # Quick start (no auth, dev mode)"
@echo " make prod # Production with monitoring"
@echo " make dev # Development with hot reload"
@echo ""
@echo "🔧 MANAGEMENT:"
@echo " make start # Start all services"
@echo " make stop # Stop all services"
@echo " make restart # Restart all services"
@echo " make logs # Show logs"
@echo " make health # Check service health"
@echo ""
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
# === INSTALLATION ===
install: ## One-command installation with setup wizard
@echo "🚀 Starting FFprobe API installation..."
@chmod +x setup.sh && ./setup.sh
quick: ## Quick start (no auth, development mode)
@echo "⚡ Quick start deployment..."
@docker compose -f docker-image/compose.yaml --profile quick up -d
@$(MAKE) wait-ready
@echo "✅ Quick start complete! Access: http://localhost:8080"
minimal: ## Minimal deployment (4 core services only)
@echo "⚡ Minimal deployment (API + DB + Redis + AI)..."
@docker compose -f docker-image/compose.yaml --profile minimal up -d
@$(MAKE) wait-ready
@echo "✅ Minimal deployment complete! Access: http://localhost:8080"
@echo " Services: API, PostgreSQL, Redis, Ollama only"
prod: ## Production deployment with monitoring
@echo "🏭 Production deployment..."
@if [ ! -f .env ]; then echo "❌ .env file required for production. Run 'make install' first."; exit 1; fi
@docker compose -f docker-image/compose.yaml -f docker-image/compose.production.yaml --profile production up -d
@$(MAKE) wait-ready
@echo "✅ Production deployment complete!"
@echo " API: http://localhost:8080"
@echo " Monitoring: http://localhost:3000"
dev: ## Development setup with hot reload
@echo "🔧 Development setup..."
@docker compose -f docker-image/compose.yaml -f docker-image/compose.development.yaml --profile development up -d
@$(MAKE) wait-ready
@echo "✅ Development environment ready!"
# === MANAGEMENT ===
start: ## Start all services
@docker compose -f docker-image/compose.yaml up -d
stop: ## Stop all services
@docker compose -f docker-image/compose.yaml stop
restart: ## Restart all services
@docker compose -f docker-image/compose.yaml restart
down: ## Stop and remove all containers
@docker compose -f docker-image/compose.yaml down
clean: ## Remove all containers, volumes, and images
@echo "🧹 Cleaning up..."
@docker compose -f docker-image/compose.yaml down -v --rmi all
@docker system prune -f
@echo "✅ Cleanup complete"
# === MONITORING ===
status: ## Show service status
@docker compose -f docker-image/compose.yaml ps
health: ## Check health of all services
@echo "🏥 Health Check:"
@echo "API: $(shell curl -s http://localhost:8080/health | grep -o '"status":"[^"]*"' || echo '❌ Down')"
@echo "Database: $(shell test -f ./data/sqlite/rendiff-probe.db && echo '✅ Ready (SQLite)' || echo '❌ Down')"
@echo "Valkey: $(shell docker compose exec -T valkey valkey-cli ping 2>/dev/null || echo '❌ Down')"
@echo "Ollama: $(shell curl -s http://localhost:11434/api/version >/dev/null && echo '✅ Ready' || echo '❌ Down')"
logs: ## Show logs from all services
@docker compose -f docker-image/compose.yaml logs -f
logs-api: ## Show API logs only
@docker compose -f docker-image/compose.yaml logs -f api
logs-ollama: ## Show Ollama (AI) logs only
@docker compose -f docker-image/compose.yaml logs -f ollama
# === TESTING ===
test: ## Run health checks and basic tests
@echo "🧪 Running tests..."
@$(MAKE) wait-ready
@echo "Testing API endpoint..."
@curl -f http://localhost:8080/health > /dev/null && echo "✅ API healthy" || echo "❌ API failed"
@echo "Testing file upload..."
@curl -f -X POST -F "file=@README.md" http://localhost:8080/api/v1/probe/file > /dev/null 2>&1 && echo "✅ Upload works" || echo "⚠️ Upload test skipped (auth required)"
test-unit: ## Run Go unit tests
@echo "🧪 Running Go unit tests..."
go test -v ./...
test-coverage: ## Run Go tests with coverage report
@echo "📊 Running tests with coverage..."
go test -cover -coverprofile=coverage.out ./...
@echo ""
@echo "Coverage Summary:"
@go tool cover -func=coverage.out | tail -1
test-coverage-html: test-coverage ## Generate HTML coverage report
@echo "📊 Generating HTML coverage report..."
go tool cover -html=coverage.out -o coverage.html
@echo "✅ Coverage report generated: coverage.html"
test-race: ## Run tests with race detection
@echo "🏃 Running tests with race detection..."
go test -race ./...
test-short: ## Run short tests only (skip long-running tests)
@echo "⚡ Running short tests..."
go test -short ./...
test-all: test-unit test-race test-coverage ## Run all Go tests
@echo "✅ All tests completed"
test-ffmpeg: ## Test FFmpeg functionality
@echo "🎬 Testing FFmpeg..."
@docker compose -f docker-image/compose.yaml exec api ffmpeg -version | head -1
@docker compose -f docker-image/compose.yaml exec api ffprobe -version | head -1
@echo "✅ FFmpeg tests passed"
test-ai: ## Test AI model functionality
@echo "🤖 Testing AI models..."
@curl -s http://localhost:11434/api/tags | jq -r '.models[].name' | head -5 || echo "⚠️ AI models still downloading"
test-integration: ## Run integration tests (requires Docker services)
@echo "🔗 Running integration tests..."
@$(MAKE) wait-ready
go test -tags=integration ./tests/integration/... 2>/dev/null || echo "ℹ️ No integration tests found"
test-benchmark: ## Run benchmark tests
@echo "📊 Running Go benchmarks..."
go test -bench=. -benchmem ./... 2>/dev/null || echo "ℹ️ No benchmarks found"
http-benchmark: ## Run HTTP performance benchmarks
@echo "📊 Running HTTP benchmarks..."
@ab -n 100 -c 10 http://localhost:8080/health 2>/dev/null | grep -E "(Requests per second|Time per request)" || echo "⚠️ Install 'apache2-utils' for benchmarking"
# === MAINTENANCE ===
update: ## Update to latest versions
@echo "🔄 Updating FFprobe API..."
@git pull origin main || echo "⚠️ Manual git pull required"
@docker compose -f docker-image/compose.yaml pull
@docker compose -f docker-image/compose.yaml up -d --build
@echo "✅ Update complete"
backup: ## Create backup of data and configuration
@echo "💾 Creating backup..."
@mkdir -p backups/$(shell date +%Y%m%d_%H%M%S)
@cp -r data/sqlite backups/$(shell date +%Y%m%d_%H%M%S)/ 2>/dev/null || echo "⚠️ SQLite database backup failed"
@cp -r data/uploads backups/$(shell date +%Y%m%d_%H%M%S)/ 2>/dev/null || echo "⚠️ No uploads to backup"
@cp -r data/valkey backups/$(shell date +%Y%m%d_%H%M%S)/ 2>/dev/null || echo "⚠️ Valkey backup failed"
@cp .env backups/$(shell date +%Y%m%d_%H%M%S)/ 2>/dev/null || echo "ℹ️ No .env to backup"
@echo "✅ Backup created in backups/$(shell date +%Y%m%d_%H%M%S)"
migrate: ## Run database migrations
@echo "🔄 Running migrations..."
@docker compose -f docker-image/compose.yaml exec api ./rendiff-probe migrate up
@echo "✅ Migrations complete"
# === DEVELOPMENT ===
build: ## Build the API image
@echo "🔨 Building API image..."
@docker compose -f docker-image/compose.yaml build api
shell: ## Open shell in API container
@docker compose -f docker-image/compose.yaml exec api /bin/bash
db-shell: ## Open SQLite shell
@docker compose -f docker-image/compose.yaml exec api sqlite3 /app/data/rendiff-probe.db
valkey-shell: ## Open Valkey shell
@docker compose -f docker-image/compose.yaml exec valkey valkey-cli -a $$VALKEY_PASSWORD
# === UTILITIES ===
env: ## Generate .env file with secure defaults
@echo "🔐 Generating secure .env file..."
@./scripts/generate-env.sh
config: ## Show current configuration
@echo "⚙️ Current Configuration:"
@docker compose -f docker-image/compose.yaml config
ps: ## Show running containers
@docker compose -f docker-image/compose.yaml ps -a
top: ## Show container resource usage
@docker stats --no-stream $(shell docker compose ps -q)
# === INTERNAL HELPERS ===
wait-ready: ## Wait for services to be ready (internal)
@echo "⏳ Waiting for services to be ready..."
@timeout=60; \
while [ $$timeout -gt 0 ]; do \
if curl -s http://localhost:8080/health >/dev/null 2>&1; then \
echo "✅ Services ready!"; \
break; \
fi; \
echo -n "."; \
sleep 2; \
timeout=$$((timeout-1)); \
done; \
if [ $$timeout -eq 0 ]; then \
echo "⚠️ Services may still be starting. Check logs with 'make logs'"; \
fi
check-docker: ## Check if Docker is available (internal)
@docker --version >/dev/null 2>&1 || { echo "❌ Docker not found. Please install Docker first."; exit 1; }
@docker compose -f docker-image/compose.yaml version >/dev/null 2>&1 || { echo "❌ Docker Compose not found. Please install Docker Compose."; exit 1; }
# === QUICK COMMANDS ===
# One-liners for common tasks
all: install ## Complete setup and start
fresh: clean install ## Clean install from scratch
reset: down clean quick ## Reset everything and quick start
# Run linter
lint:
@echo "Running linter..."
golangci-lint run ./...
# Format code
fmt:
@echo "Formatting code..."
go fmt ./...
goimports -w .
# Download dependencies
deps:
@echo "Downloading dependencies..."
go mod download
go mod tidy
# Generate mocks (if using mockery)
mocks:
@echo "Generating mocks..."
mockery --all --output tests/mocks
# Install development tools
install-tools:
@echo "Installing development tools..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/vektra/mockery/v2@latest
# Database migrations (if using migrate)
migrate-up:
@echo "Running database migrations..."
migrate -path migrations -database "postgres://localhost/ffprobe_api?sslmode=disable" up
migrate-down:
@echo "Rolling back database migrations..."
migrate -path migrations -database "postgres://localhost/ffprobe_api?sslmode=disable" down
# Generate API documentation
docs:
@echo "Generating API documentation..."
swag init -g cmd/rendiff-probe/main.go -o docs/
# Security scan
security:
@echo "Running security scan..."
gosec ./...
# Benchmark tests
benchmark:
@echo "Running benchmark tests..."
go test -bench=. -benchmem ./tests/...
# Profile application
profile:
@echo "Running with profiling..."
go run -tags profile ./cmd/rendiff-probe
# Check dependencies for vulnerabilities
vuln-check:
@echo "Checking for vulnerabilities..."
govulncheck ./...
# Generate code coverage badge
coverage-badge: test-coverage
@echo "Generating coverage badge..."
go tool cover -func=coverage.out | grep total | awk '{print $$3}' | sed 's/%//' > coverage.txt
# =============================================================================
# INSTALLATION & DEPLOYMENT TARGETS
# =============================================================================
# Interactive installer
install:
@echo "🎬 Starting FFprobe API Interactive Installer..."
./scripts/setup/install.sh
# Quick setup
quick-setup:
@echo "⚡ Starting FFprobe API Quick Setup..."
./scripts/setup/quick-setup.sh
# Validate configuration
validate:
@echo "✅ Validating configuration..."
./scripts/setup/validate-config.sh
# Deploy to production
deploy:
@echo "🚀 Deploying to production..."
./scripts/deployment/deploy.sh deploy production latest
# Deploy to staging
deploy-staging:
@echo "🧪 Deploying to staging..."
./scripts/deployment/deploy.sh deploy staging latest
# Check deployment health
health-check:
@echo "🏥 Checking deployment health..."
./scripts/deployment/healthcheck.sh
# Create backup
backup:
@echo "💾 Creating backup..."
./scripts/maintenance/backup.sh
# Setup Ollama models
setup-ollama:
@echo "🦙 Setting up Ollama models..."
./scripts/setup/setup-ollama.sh
# Update Docker Compose files to new syntax
docker-update:
@echo "🐳 Updating Docker Compose syntax..."
docker compose -f docker-image/compose.yaml config > /dev/null && echo "✅ Base config valid"
docker compose -f docker-image/compose.yaml -f docker-image/compose.development.yaml config > /dev/null && echo "✅ Dev config valid"
docker compose -f docker-image/compose.yaml -f docker-image/compose.production.yaml config > /dev/null && echo "✅ Prod config valid"
# Complete setup workflow
setup-complete: install validate docker-update
@echo "🎉 Complete setup workflow finished!"
@echo "Your FFprobe API is ready to deploy!"
# Development workflow
dev-workflow: deps install-tools fmt lint test
@echo "🔧 Development workflow complete!"
# CI/CD pipeline simulation
ci: deps fmt lint test test-integration security vuln-check
@echo "🚦 CI pipeline simulation complete!"
# Production readiness check
prod-ready: validate docker-update security vuln-check test-all
@echo "🏭 Production readiness check complete!"