-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
419 lines (341 loc) · 14.5 KB
/
Makefile
File metadata and controls
419 lines (341 loc) · 14.5 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
# Project Template Makefile
# This Makefile provides common development tasks for multi-language projects
.PHONY: help setup dev test build clean lint format docker deploy
# Default target
.DEFAULT_GOAL := help
# Variables
PROJECT_NAME := project-template
VERSION := $(shell cat .version 2>/dev/null || echo "development")
DOCKER_REGISTRY := ghcr.io
DOCKER_ORG := penguintechinc
GO_VERSION := 1.24.2
PYTHON_VERSION := 3.12
NODE_VERSION := 18
# Colors for output
RED := \033[31m
GREEN := \033[32m
YELLOW := \033[33m
BLUE := \033[34m
RESET := \033[0m
# Help target
help: ## Show this help message
@echo "$(BLUE)$(PROJECT_NAME) Development Commands$(RESET)"
@echo ""
@echo "$(GREEN)Setup Commands:$(RESET)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / && /Setup/ {printf " $(YELLOW)%-20s$(RESET) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "$(GREEN)Development Commands:$(RESET)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / && /Development/ {printf " $(YELLOW)%-20s$(RESET) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "$(GREEN)Testing Commands:$(RESET)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / && /Testing/ {printf " $(YELLOW)%-20s$(RESET) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "$(GREEN)Build Commands:$(RESET)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / && /Build/ {printf " $(YELLOW)%-20s$(RESET) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "$(GREEN)Docker Commands:$(RESET)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / && /Docker/ {printf " $(YELLOW)%-20s$(RESET) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "$(GREEN)Other Commands:$(RESET)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / && !/Setup|Development|Testing|Build|Docker/ {printf " $(YELLOW)%-20s$(RESET) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Setup Commands
setup: ## Setup - Install all dependencies and initialize the project
@echo "$(BLUE)Setting up $(PROJECT_NAME)...$(RESET)"
@$(MAKE) setup-env
@$(MAKE) setup-go
@$(MAKE) setup-python
@$(MAKE) setup-node
@$(MAKE) setup-git-hooks
@echo "$(GREEN)Setup complete!$(RESET)"
setup-env: ## Setup - Create environment file from template
@if [ ! -f .env ]; then \
echo "$(YELLOW)Creating .env from .env.example...$(RESET)"; \
cp .env.example .env; \
echo "$(YELLOW)Please edit .env with your configuration$(RESET)"; \
fi
setup-go: ## Setup - Install Go dependencies and tools
@echo "$(BLUE)Setting up Go dependencies...$(RESET)"
@go version || (echo "$(RED)Go $(GO_VERSION) not installed$(RESET)" && exit 1)
@go mod download
@go mod tidy
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@go install github.com/air-verse/air@latest
setup-python: ## Setup - Install Python dependencies and tools
@echo "$(BLUE)Setting up Python dependencies...$(RESET)"
@python3 --version || (echo "$(RED)Python $(PYTHON_VERSION) not installed$(RESET)" && exit 1)
@pip install --upgrade pip
@pip install -r requirements.txt
@pip install black isort flake8 mypy pytest pytest-cov
setup-node: ## Setup - Install Node.js dependencies and tools
@echo "$(BLUE)Setting up Node.js dependencies...$(RESET)"
@node --version || (echo "$(RED)Node.js $(NODE_VERSION) not installed$(RESET)" && exit 1)
@npm install
@cd services/webui && npm install
setup-git-hooks: ## Setup - Install Git pre-commit hooks
@echo "$(BLUE)Installing Git hooks...$(RESET)"
@cp scripts/git-hooks/pre-commit .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@cp scripts/git-hooks/commit-msg .git/hooks/commit-msg
@chmod +x .git/hooks/commit-msg
# Development Commands
dev: ## Development - Start development environment
@echo "$(BLUE)Starting development environment...$(RESET)"
@docker-compose up -d postgres redis
@sleep 5
@$(MAKE) dev-services
dev-services: ## Development - Start all services for development
@echo "$(BLUE)Starting development services...$(RESET)"
@docker-compose up -d api-manager webui worker-ipxe access-agent
dev-db: ## Development - Start only database services
@docker-compose up -d postgres redis
dev-monitoring: ## Development - Start monitoring services
@docker-compose up -d prometheus grafana
dev-full: ## Development - Start full development stack
@docker-compose up -d
# Testing Commands
test: ## Testing - Run all tests
@echo "$(BLUE)Running all tests...$(RESET)"
@$(MAKE) test-go
@$(MAKE) test-python
@$(MAKE) test-node
@echo "$(GREEN)All tests completed!$(RESET)"
test-go: ## Testing - Run Go tests
@echo "$(BLUE)Running Go tests...$(RESET)"
@go test -v -race -coverprofile=coverage-go.out ./...
test-python: ## Testing - Run Python tests
@echo "$(BLUE)Running Python tests...$(RESET)"
@pytest --cov-report=xml:coverage-python.xml --cov-report=html:htmlcov-python
test-node: ## Testing - Run Node.js tests
@echo "$(BLUE)Running Node.js tests...$(RESET)"
@npm test
@cd services/webui && npm test
test-integration: ## Testing - Run integration tests
@echo "$(BLUE)Running integration tests...$(RESET)"
@docker-compose up --build --abort-on-container-exit
test-coverage: ## Testing - Generate coverage reports
@$(MAKE) test
@echo "$(GREEN)Coverage reports generated:$(RESET)"
@echo " Go: coverage-go.out"
@echo " Python: coverage-python.xml, htmlcov-python/"
@echo " Node.js: coverage/"
smoke-test: ## Testing - Run alpha smoke tests (full local validation)
@echo "$(BLUE)Running alpha smoke tests...$(RESET)"
@./tests/smoke/run-smoke-tests.sh alpha
smoke-test-quick: ## Testing - Run alpha smoke tests (skip builds)
@echo "$(BLUE)Running quick smoke tests...$(RESET)"
@./tests/smoke/run-smoke-tests.sh alpha quick
smoke-test-beta: ## Testing - Run beta smoke tests against staging
@echo "$(BLUE)Running beta smoke tests against https://gough.penguintech.io...$(RESET)"
@./tests/smoke/run-smoke-tests.sh beta
# Build Commands
build: ## Build - Build all applications
@echo "$(BLUE)Building all applications...$(RESET)"
@$(MAKE) build-go
@$(MAKE) build-python
@$(MAKE) build-node
@echo "$(GREEN)All builds completed!$(RESET)"
build-go: ## Build - Build Go applications
@echo "$(BLUE)Building Go applications with Docker...$(RESET)"
@docker compose build worker-ipxe access-agent
build-python: ## Build - Build Python applications
@echo "$(BLUE)Building Python applications with Docker...$(RESET)"
@docker compose build api-manager
build-node: ## Build - Build Node.js applications
@echo "$(BLUE)Building Node.js applications with Docker...$(RESET)"
@docker compose build webui
build-production: ## Build - Build for production with optimizations
@echo "$(BLUE)Building for production...$(RESET)"
@docker compose build api-manager webui worker-ipxe access-agent
# Docker Commands
docker-build: ## Docker - Build all Docker images
@echo "$(BLUE)Building Docker images...$(RESET)"
@docker compose build
docker-push: ## Docker - Push Docker images to registry
@echo "$(BLUE)Pushing Docker images...$(RESET)"
@docker compose push
docker-run: ## Docker - Run application with Docker Compose
@docker-compose up --build
docker-clean: ## Docker - Clean up Docker resources
@echo "$(BLUE)Cleaning up Docker resources...$(RESET)"
@docker-compose down -v
@docker system prune -f
# Kubernetes Commands
k8s-deploy: ## Kubernetes - Deploy to K8s cluster (default registry)
@echo "$(BLUE)Deploying to Kubernetes...$(RESET)"
@./tests/k8s/deploy-k8s.sh
k8s-deploy-custom: ## Kubernetes - Deploy to K8s with custom registry (usage: make k8s-deploy-custom REGISTRY=registry.example.com)
@echo "$(BLUE)Deploying to Kubernetes with custom registry...$(RESET)"
@./tests/k8s/deploy-k8s.sh $(REGISTRY)
k8s-deploy-staging: ## Kubernetes - Deploy to staging namespace
@echo "$(BLUE)Deploying to staging...$(RESET)"
@./tests/k8s/deploy-k8s.sh registry.penguintech.io staging
k8s-status: ## Kubernetes - Check deployment status
@echo "$(BLUE)Kubernetes deployment status:$(RESET)"
@kubectl get all -n gough
k8s-logs: ## Kubernetes - View logs from all pods
@echo "$(BLUE)Fetching logs...$(RESET)"
@kubectl logs -n gough -l app=api-manager --tail=50
@kubectl logs -n gough -l app=webui --tail=50
k8s-clean: ## Kubernetes - Delete all resources
@echo "$(RED)Deleting Kubernetes resources...$(RESET)"
@kubectl delete namespace gough --wait=true
# Code Quality Commands
lint: ## Code Quality - Run linting for all languages
@echo "$(BLUE)Running linting...$(RESET)"
@$(MAKE) lint-go
@$(MAKE) lint-python
@$(MAKE) lint-node
lint-go: ## Code Quality - Run Go linting
@echo "$(BLUE)Linting Go code...$(RESET)"
@golangci-lint run
lint-python: ## Code Quality - Run Python linting
@echo "$(BLUE)Linting Python code...$(RESET)"
@flake8 .
@mypy . --ignore-missing-imports
lint-node: ## Code Quality - Run Node.js linting
@echo "$(BLUE)Linting Node.js code...$(RESET)"
@npm run lint
@cd services/webui && npm run lint
format: ## Code Quality - Format code for all languages
@echo "$(BLUE)Formatting code...$(RESET)"
@$(MAKE) format-python
@$(MAKE) format-node
format-python: ## Code Quality - Format Python code
@echo "$(BLUE)Formatting Python code...$(RESET)"
@black services/
@isort services/
format-node: ## Code Quality - Format Node.js code
@echo "$(BLUE)Formatting Node.js code...$(RESET)"
@npm run format
@cd services/webui && npm run format
# Database Commands
db-migrate: ## Database - Run database migrations
@echo "$(BLUE)Running database migrations...$(RESET)"
@go run scripts/migrate.go
db-seed: ## Database - Seed database with test data
@echo "$(BLUE)Seeding database...$(RESET)"
@go run scripts/seed.go
db-reset: ## Database - Reset database (WARNING: destroys data)
@echo "$(RED)WARNING: This will destroy all data!$(RESET)"
@read -p "Are you sure? (y/N): " confirm && [ "$$confirm" = "y" ]
@docker-compose down -v
@docker-compose up -d postgres redis
@sleep 5
@$(MAKE) db-migrate
@$(MAKE) db-seed
db-backup: ## Database - Create database backup
@echo "$(BLUE)Creating database backup...$(RESET)"
@mkdir -p backups
@docker-compose exec postgres pg_dump -U postgres project_template > backups/backup-$(shell date +%Y%m%d-%H%M%S).sql
db-restore: ## Database - Restore database from backup (requires BACKUP_FILE)
@echo "$(BLUE)Restoring database from $(BACKUP_FILE)...$(RESET)"
@docker-compose exec -T postgres psql -U postgres project_template < $(BACKUP_FILE)
# License Commands
license-validate: ## License - Validate license configuration
@echo "$(BLUE)Validating license configuration...$(RESET)"
@go run scripts/license-validate.go
license-test: ## License - Test license server integration
@echo "$(BLUE)Testing license server integration...$(RESET)"
@curl -f $${LICENSE_SERVER_URL:-https://license.penguintech.io}/api/v2/validate \
-H "Authorization: Bearer $${LICENSE_KEY}" \
-H "Content-Type: application/json" \
-d '{"product": "'$${PRODUCT_NAME:-project-template}'"}'
# Version Management Commands
version-update: ## Version - Update version (patch by default)
@./scripts/version/update-version.sh
version-update-minor: ## Version - Update minor version
@./scripts/version/update-version.sh minor
version-update-major: ## Version - Update major version
@./scripts/version/update-version.sh major
version-show: ## Version - Show current version
@echo "Current version: $(VERSION)"
# Deployment Commands
deploy-staging: ## Deploy - Deploy to staging environment
@echo "$(BLUE)Deploying to staging...$(RESET)"
@$(MAKE) docker-build
@$(MAKE) docker-push
# Add staging deployment commands here
deploy-production: ## Deploy - Deploy to production environment
@echo "$(BLUE)Deploying to production...$(RESET)"
@$(MAKE) docker-build
@$(MAKE) docker-push
# Add production deployment commands here
# Health Check Commands
health: ## Health - Check service health
@echo "$(BLUE)Checking service health...$(RESET)"
@curl -f http://localhost:8080/health || echo "$(RED)API health check failed$(RESET)"
@curl -f http://localhost:8000/health || echo "$(RED)Python web health check failed$(RESET)"
@curl -f http://localhost:3000/health || echo "$(RED)Node web health check failed$(RESET)"
logs: ## Logs - Show service logs
@docker-compose logs -f
logs-api: ## Logs - Show API logs
@docker-compose logs -f api
logs-web: ## Logs - Show web logs
@docker-compose logs -f web-python web-node
logs-db: ## Logs - Show database logs
@docker-compose logs -f postgres redis
# Cleanup Commands
clean: ## Clean - Clean build artifacts and caches
@echo "$(BLUE)Cleaning build artifacts...$(RESET)"
@rm -rf bin/
@rm -rf dist/
@rm -rf node_modules/
@rm -rf services/*/node_modules/
@rm -rf services/*/dist/
@rm -rf __pycache__/
@rm -rf .pytest_cache/
@rm -rf htmlcov-python/
@rm -rf coverage-*.out
@rm -rf coverage-*.xml
clean-docker: ## Clean - Clean Docker resources
@$(MAKE) docker-clean
clean-all: ## Clean - Clean everything (build artifacts, Docker, etc.)
@$(MAKE) clean
@$(MAKE) clean-docker
# Security Commands
security-scan: ## Security - Run security scans
@echo "$(BLUE)Running security scans...$(RESET)"
@safety check --json
audit: ## Security - Run security audit
@echo "$(BLUE)Running security audit...$(RESET)"
@npm audit
@cd services/webui && npm audit
# Monitoring Commands
metrics: ## Monitoring - Show application metrics
@echo "$(BLUE)Application metrics:$(RESET)"
@curl -s http://localhost:8080/metrics | grep -E '^# (HELP|TYPE)' | head -20
monitor: ## Monitoring - Open monitoring dashboard
@echo "$(BLUE)Opening monitoring dashboard...$(RESET)"
@open http://localhost:3001 # Grafana
# Documentation Commands
docs-serve: ## Documentation - Serve documentation locally
@echo "$(BLUE)Serving documentation...$(RESET)"
@cd docs && python -m http.server 8080
docs-build: ## Documentation - Build documentation
@echo "$(BLUE)Building documentation...$(RESET)"
@echo "Documentation build not implemented yet"
# Git Commands
git-hooks-install: ## Git - Install Git hooks
@$(MAKE) setup-git-hooks
git-hooks-test: ## Git - Test Git hooks
@echo "$(BLUE)Testing Git hooks...$(RESET)"
@.git/hooks/pre-commit
@echo "$(GREEN)Git hooks test completed$(RESET)"
# Info Commands
info: ## Info - Show project information
@echo "$(BLUE)Project Information:$(RESET)"
@echo "Name: $(PROJECT_NAME)"
@echo "Version: $(VERSION)"
@echo "Go Version: $(GO_VERSION)"
@echo "Python Version: $(PYTHON_VERSION)"
@echo "Node Version: $(NODE_VERSION)"
@echo ""
@echo "$(BLUE)Service URLs:$(RESET)"
@echo "API: http://localhost:8080"
@echo "Python Web: http://localhost:8000"
@echo "Node Web: http://localhost:3000"
@echo "Prometheus: http://localhost:9090"
@echo "Grafana: http://localhost:3001"
env: ## Info - Show environment variables
@echo "$(BLUE)Environment Variables:$(RESET)"
@env | grep -E "^(LICENSE_|POSTGRES_|REDIS_|NODE_|GIN_|PY4WEB_)" | sort