-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
309 lines (255 loc) · 10.9 KB
/
Makefile
File metadata and controls
309 lines (255 loc) · 10.9 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
# VoidRunner Makefile
# Provides standardized commands for building, testing, and running the application
.PHONY: help test test-fast test-integration test-all build run dev clean coverage coverage-check docs docs-serve lint fmt vet security deps deps-update migrate-up migrate-down migrate-reset migration docker-build docker-run clean-docs install-tools setup all pre-commit bench services-start services-stop services-reset services-status dev-up dev-down dev-logs dev-restart dev-status prod-up prod-down prod-logs prod-restart prod-status docker-clean env-status
# Default target
help: ## Show this help message
@echo "VoidRunner API Development Commands"
@echo "=================================="
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
# Build targets
build: ## Build the API server binary
@echo "Building VoidRunner API server..."
@go build -o bin/voidrunner-api ./cmd/api
@echo "Build complete: bin/voidrunner-api"
# Test targets
test: ## Run unit tests only (with coverage if CI=true)
@echo "Running unit tests (excluding integration tests)..."
ifeq ($(CI),true)
@go test -race -coverprofile=coverage.out ./cmd/... ./internal/... ./pkg/...
@go tool cover -func=coverage.out
@./scripts/check-coverage.sh coverage.out 80.0 || echo "Coverage check failed but not blocking CI"
else
@go test -cover -race ./cmd/... ./internal/... ./pkg/...
endif
test-fast: ## Run unit tests in short mode (fast, excluding integration)
@echo "Running unit tests (fast mode, excluding integration tests)..."
@go test -short ./cmd/... ./internal/... ./pkg/...
test-integration: ## Run integration tests (requires services to be running)
@echo "Running integration tests..."
@echo "Note: PostgreSQL and Redis must be running before running integration tests"
@echo "Use 'make services-start' to start the test services"
@INTEGRATION_TESTS=true \
TEST_DB_HOST=$${TEST_DB_HOST:-localhost} \
TEST_DB_PORT=$${TEST_DB_PORT:-5432} \
TEST_DB_USER=$${TEST_DB_USER:-testuser} \
TEST_DB_PASSWORD=$${TEST_DB_PASSWORD:-testpassword} \
TEST_DB_NAME=$${TEST_DB_NAME:-voidrunner_test} \
TEST_DB_SSLMODE=$${TEST_DB_SSLMODE:-disable} \
JWT_SECRET_KEY=$${JWT_SECRET_KEY:-test-secret-key-for-integration} \
REDIS_HOST=$${REDIS_HOST:-localhost} \
REDIS_PORT=$${REDIS_PORT:-6379} \
REDIS_PASSWORD=$${REDIS_PASSWORD:-} \
REDIS_DATABASE=$${REDIS_DATABASE:-0} \
LOG_STREAM_ENABLED=$${LOG_STREAM_ENABLED:-true} \
LOG_BUFFER_SIZE=$${LOG_BUFFER_SIZE:-50} \
LOG_MAX_CONCURRENT_STREAMS=$${LOG_MAX_CONCURRENT_STREAMS:-5} \
LOG_BATCH_INSERT_SIZE=$${LOG_BATCH_INSERT_SIZE:-5} \
LOG_BATCH_INSERT_INTERVAL=$${LOG_BATCH_INSERT_INTERVAL:-1s} \
go test -tags=integration -v -race ./tests/integration/...
test-all: test test-integration ## Run both unit and integration tests (database must be running)
coverage: ## Run unit tests with coverage (check threshold if CI=true)
@echo "Running unit tests with coverage (excluding integration tests)..."
@go test -v -race -coverprofile=coverage.out ./cmd/... ./internal/... ./pkg/...
@go tool cover -func=coverage.out
ifeq ($(CI),true)
@./scripts/check-coverage.sh coverage.out 80.0
else
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
endif
coverage-check: ## Check if coverage meets minimum threshold (80%)
@echo "Checking coverage threshold (excluding integration tests)..."
@go test -v -race -coverprofile=coverage.out ./cmd/... ./internal/... ./pkg/...
@go tool cover -func=coverage.out
@./scripts/check-coverage.sh coverage.out 80.0
# Development targets
run: build ## Run the API server locally
@echo "Starting VoidRunner API server..."
@./bin/voidrunner-api
dev: ## Run in development mode with auto-reload
@echo "Starting development server..."
@air || go run ./cmd/api
# Code quality targets
fmt: ## Format Go code
@echo "Formatting Go code..."
@go fmt ./...
vet: ## Run go vet
@echo "Running go vet..."
@go vet ./...
lint: ## Run all linting checks (including format check if CI=true)
@echo "Running golangci-lint..."
@golangci-lint run $(if $(CI),--timeout=5m)
ifeq ($(CI),true)
@echo "Checking code formatting..."
@if [ "$$(gofmt -s -l . | wc -l)" -gt 0 ]; then \
echo "Code is not formatted properly:"; \
gofmt -s -l .; \
exit 1; \
fi
endif
# Documentation targets
docs: ## Generate Swagger documentation
@echo "Generating Swagger documentation..."
@swag init -g cmd/api/main.go -o docs/
@echo "Documentation generated in docs/"
docs-serve: docs ## Serve documentation locally
@echo "Serving documentation at http://localhost:8081"
@cd docs && python3 -m http.server 8081 || python -m SimpleHTTPServer 8081
# Database targets
migrate-up: ## Run database migrations up
@echo "Running database migrations..."
@go run ./cmd/migrate up
migrate-down: ## Run database migrations down (rollback one)
@echo "Rolling back last migration..."
@go run ./cmd/migrate down
migrate-reset: ## Reset database (rollback all migrations)
@echo "Resetting database..."
@go run ./cmd/migrate reset
migration: ## Create a new migration file (usage: make migration name=migration_name)
@if [ -z "$(name)" ]; then echo "Usage: make migration name=migration_name"; exit 1; fi
@echo "Creating migration: $(name)"
@mkdir -p migrations
@touch migrations/$(shell date +%Y%m%d%H%M%S)_$(name).up.sql
@touch migrations/$(shell date +%Y%m%d%H%M%S)_$(name).down.sql
@echo "Migration files created in migrations/"
# Test services management targets
services-start: ## Start test services (PostgreSQL + Redis)
@echo "Starting test services..."
@./scripts/start-test-services.sh
services-stop: ## Stop test services (PostgreSQL + Redis)
@echo "Stopping test services..."
@./scripts/stop-test-services.sh
services-reset: ## Reset test services (clean slate)
@echo "Resetting test services..."
@./scripts/reset-test-services.sh
services-status: ## Show test services status
@echo "Test services status:"
@if command -v docker-compose &> /dev/null; then \
docker-compose -f docker-compose.test.yml ps; \
else \
echo "docker-compose not found"; \
fi
# Environment Management
dev-up: ## Start development environment (DB + Redis + API with embedded workers)
@echo "Starting development environment..."
@./scripts/dev-env.sh up
dev-down: ## Stop development environment
@echo "Stopping development environment..."
@./scripts/dev-env.sh down
dev-logs: ## Show development environment logs
@echo "Showing development logs..."
@./scripts/dev-env.sh logs
dev-restart: ## Restart development environment
@echo "Restarting development environment..."
@./scripts/dev-env.sh restart
dev-status: ## Show development environment status
@echo "Development environment status:"
@./scripts/dev-env.sh status
prod-up: ## Start production environment
@echo "Starting production environment..."
@./scripts/prod-env.sh up
prod-down: ## Stop production environment
@echo "Stopping production environment..."
@./scripts/prod-env.sh down
prod-logs: ## Show production environment logs
@echo "Showing production logs..."
@./scripts/prod-env.sh logs
prod-restart: ## Restart production environment
@echo "Restarting production environment..."
@./scripts/prod-env.sh restart
prod-status: ## Show production environment status
@echo "Production environment status:"
@./scripts/prod-env.sh status
env-status: ## Show all environment status
@echo "=== Development Environment ==="
@./scripts/dev-env.sh status || echo "Development environment not running"
@echo ""
@echo "=== Production Environment ==="
@./scripts/prod-env.sh status || echo "Production environment not running"
@echo ""
@echo "=== Test Services ==="
@if command -v docker-compose &> /dev/null; then \
if docker-compose -f docker-compose.test.yml ps | grep -q "Up"; then \
echo "Test services: Running"; \
else \
echo "Test services: Stopped"; \
fi; \
else \
echo "docker-compose not found"; \
fi
docker-clean: ## Clean Docker resources (containers, images, volumes)
@echo "Cleaning Docker resources..."
@echo "WARNING: This will remove all VoidRunner containers, images, and volumes"
@read -p "Are you sure? [y/N] " -n 1 -r && echo && \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
docker-compose -f docker-compose.yml down -v --remove-orphans 2>/dev/null || true; \
docker-compose -f docker-compose.dev.yml down -v --remove-orphans 2>/dev/null || true; \
docker-compose -f docker-compose.test.yml down -v --remove-orphans 2>/dev/null || true; \
docker system prune -f --volumes; \
echo "Docker cleanup complete"; \
else \
echo "Docker cleanup cancelled"; \
fi
# Dependency management
deps: ## Download and tidy dependencies
@echo "Downloading dependencies..."
@go mod download
@go mod tidy
deps-update: ## Update dependencies
@echo "Updating dependencies..."
@go get -u ./...
@go mod tidy
# Security targets
security: ## Run security scan (SARIF format if CI=true)
@echo "Running security scan..."
ifeq ($(CI),true)
@gosec -no-fail -fmt sarif -out gosec.sarif ./...
else
@gosec ./... || echo "Security scan completed with findings"
endif
# Docker targets
docker-build: ## Build Docker image
@echo "Building Docker image..."
@docker build -t voidrunner-api .
docker-run: docker-build ## Run in Docker container
@echo "Running in Docker container..."
@docker run -p 8080:8080 --env-file .env voidrunner-api
# Clean targets
clean: ## Clean build artifacts and caches
@echo "Cleaning build artifacts..."
@rm -rf bin/
@rm -f coverage.out coverage.html
@go clean -cache -testcache -modcache
@echo "Clean complete"
clean-docs: ## Clean generated documentation
@echo "Cleaning generated documentation..."
@rm -f docs/docs.go docs/swagger.json docs/swagger.yaml
# Install development tools
install-tools: ## Install development tools
@echo "Installing development tools..."
@go install github.com/swaggo/swag/cmd/swag@latest
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@go install github.com/securego/gosec/v2/cmd/gosec@latest
@go install github.com/air-verse/air@latest
@echo "Development tools installed"
# Environment setup
setup: deps install-tools ## Setup development environment
@echo "Setting up development environment..."
@cp .env.example .env || echo ".env.example not found, skipping"
@echo "✅ Development environment setup complete!"
@echo " - Tools: installed"
@echo " - Dependencies: downloaded"
@echo " - .env file: created (edit with your configuration)"
@echo ""
@echo "To run integration tests:"
@echo " make services-start # Start test services (PostgreSQL + Redis)"
@echo " make test-integration # Run integration tests"
@echo " make services-stop # Stop test services (optional)"
# Performance testing
bench: ## Run benchmark tests
@echo "Running benchmark tests..."
@go test -bench=. -benchmem ./...
all: clean deps lint test build ## Run all quality checks and build
# Precommit hook
pre-commit: fmt vet lint test ## Run pre-commit checks
@echo "Pre-commit checks passed"