-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
178 lines (140 loc) Β· 5.78 KB
/
Makefile
File metadata and controls
178 lines (140 loc) Β· 5.78 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
# ShieldGate Makefile
# Provides convenient commands for development and deployment
.PHONY: help setup build start stop restart logs clean test lint fmt vet security backup restore deploy
# Default target
help: ## Show this help message
@echo "ShieldGate OAuth 2.0 Authorization Server"
@echo ""
@echo "Available commands:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Development commands
setup: ## Setup development environment
@echo "π Setting up development environment..."
@chmod +x scripts/*.sh
@./scripts/setup.sh
build: ## Build the application
@echo "π¨ Building application..."
@docker-compose build
start: ## Start all services
@echo "βΆοΈ Starting services..."
@docker-compose up -d
start-dev: ## Start services in development mode
@echo "π§ Starting development environment..."
@docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
start-monitoring: ## Start services with monitoring
@echo "π Starting services with monitoring..."
@docker-compose --profile monitoring up -d
stop: ## Stop all services
@echo "βΉοΈ Stopping services..."
@docker-compose down
restart: ## Restart all services
@echo "π Restarting services..."
@docker-compose restart
logs: ## Show logs for all services
@docker-compose logs -f
logs-auth: ## Show logs for auth server only
@docker-compose logs -f auth-server
status: ## Show service status
@docker-compose ps
# Database commands
db-shell: ## Connect to database shell
@docker-compose exec postgres psql -U ${POSTGRES_USER:-authuser} -d ${POSTGRES_DB:-authdb}
db-migrate: ## Run database migrations
@echo "ποΈ Running database migrations..."
@docker-compose exec auth-server ./main migrate
db-seed: ## Seed database with test data
@echo "π± Seeding database..."
@docker-compose exec postgres psql -U ${POSTGRES_USER:-authuser} -d ${POSTGRES_DB:-authdb} -f /docker-entrypoint-initdb.d/01-init.sql
# Backup and restore
backup: ## Create database and configuration backup
@echo "πΎ Creating backup..."
@./scripts/backup.sh
restore-db: ## Restore database from backup (requires BACKUP_FILE)
@echo "π Restoring database..."
@./scripts/restore.sh database $(BACKUP_FILE)
restore-config: ## Restore configuration from backup (requires BACKUP_FILE)
@echo "π Restoring configuration..."
@./scripts/restore.sh config $(BACKUP_FILE)
# Development tools
test: ## Run tests
@echo "π§ͺ Running tests..."
@go test -v ./...
test-coverage: ## Run tests with coverage
@echo "π Running tests with coverage..."
@go test -cover ./...
@go test -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
lint: ## Run linter
@echo "π Running linter..."
@golangci-lint run
fmt: ## Format code
@echo "β¨ Formatting code..."
@go fmt ./...
vet: ## Run go vet
@echo "π Running go vet..."
@go vet ./...
security: ## Run security scan
@echo "π Running security scan..."
@gosec ./...
# Build and deployment
build-prod: ## Build production image
@echo "ποΈ Building production image..."
@docker build -t shieldgate/auth-server:latest .
deploy-prod: ## Deploy to production
@echo "π Deploying to production..."
@docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Cleanup commands
clean: ## Clean up containers and volumes
@echo "π§Ή Cleaning up..."
@docker-compose down -v
@docker system prune -f
clean-all: ## Clean up everything including images
@echo "π§Ή Cleaning up everything..."
@docker-compose down -v --rmi all
@docker system prune -af
# Utility commands
shell: ## Access auth server shell
@docker-compose exec auth-server sh
redis-cli: ## Access Redis CLI
@docker-compose exec redis redis-cli
generate-secret: ## Generate a new JWT secret
@echo "π Generated JWT secret:"
@openssl rand -base64 64 | tr -d "=+/" | cut -c1-64
health: ## Check service health
@echo "π₯ Checking service health..."
@curl -f http://localhost:8080/health || echo "β Auth server is not healthy"
@docker-compose exec postgres pg_isready -U ${POSTGRES_USER:-authuser} -d ${POSTGRES_DB:-authdb} || echo "β Database is not ready"
@docker-compose exec redis redis-cli ping || echo "β Redis is not ready"
# OAuth testing
test-oauth: ## Test OAuth flow
@echo "π Testing OAuth flow..."
@echo "Authorization URL:"
@echo "http://localhost:8080/oauth/authorize?response_type=code&client_id=shieldgate-dev-client&redirect_uri=http://localhost:3000/callback&scope=read%20openid&state=test123&code_challenge=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk&code_challenge_method=S256"
# Documentation
docs: ## Generate documentation
@echo "π Generating documentation..."
@godoc -http=:6060 &
@echo "Documentation available at http://localhost:6060"
# Environment management
env-example: ## Create .env from example
@cp .env.example .env
@echo "π Created .env file from example"
env-validate: ## Validate environment configuration
@echo "β
Validating environment configuration..."
@docker-compose config > /dev/null && echo "β
Docker Compose configuration is valid" || echo "β Docker Compose configuration is invalid"
# Monitoring
monitor: ## Open monitoring dashboards
@echo "π Opening monitoring dashboards..."
@echo "Prometheus: http://localhost:9090"
@echo "Grafana: http://localhost:3000 (admin/admin)"
# Quick start
quick-start: setup start health test-oauth ## Quick start for development
@echo ""
@echo "π ShieldGate is ready!"
@echo ""
@echo "π Service URLs:"
@echo " β’ Auth Server: http://localhost:8080"
@echo " β’ Health Check: http://localhost:8080/health"
@echo ""
@echo "π Test OAuth flow:"
@echo " http://localhost:8080/oauth/authorize?response_type=code&client_id=shieldgate-dev-client&redirect_uri=http://localhost:3000/callback&scope=read%20openid&state=test123"