-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
176 lines (134 loc) · 6.06 KB
/
Makefile
File metadata and controls
176 lines (134 loc) · 6.06 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
# ============================================================================
# Surypus Event Sourcing - Makefile
# ============================================================================
.PHONY: help build test migrate seed clean docker-up docker-down
# Default values
ENV ?= development
DB_URL ?= postgresql://surypus:surypus_secret@localhost:5432/surypus
COMPOSE_FILE ?= docker/docker-compose.yml
# Colors for output
BLUE := \033[36m
GREEN := \033[32m
RED := \033[31m
YELLOW := \033[33m
NC := \033[0m
help: ## Show this help message
@echo "$(BLUE)Surypus Event Sourcing - Available Commands:$(NC)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
# ============================================================================
# DATABASE OPERATIONS
# ============================================================================
migrate: ## Run database migrations
@echo "$(BLUE)Running migrations...$(NC)"
psql $(DB_URL) -f sql/migrations/V100__event_sourcing_init.sql
@echo "$(GREEN)Migrations complete!$(NC)"
migrate-test: ## Run test migrations
@echo "$(BLUE)Running test migrations...$(NC)"
psql $(DB_URL) -f sql/test/V001__test_event_store.sql
psql $(DB_URL) -f sql/test/V002__test_inventory_aggregate.sql
@echo "$(GREEN)Test migrations complete!$(NC)"
seed: ## Seed database with test data
@echo "$(BLUE)Seeding database...$(NC)"
psql $(DB_URL) -f sql/seeds/basic_seed.sql
@echo "$(GREEN)Seeding complete!$(NC)"
# ============================================================================
# TESTING
# ============================================================================
test: test-unit test-integration ## Run all tests
test-unit: ## Run unit tests (Haskell)
@echo "$(BLUE)Running unit tests...$(NC)"
stack test
test-integration: ## Run integration tests (Haskell)
@echo "$(BLUE)Running integration tests...$(NC)"
stack test test/Integration/EventSourcingSpec.hs
test-sql: ## Run SQL tests
@echo "$(BLUE)Running SQL tests...$(NC)"
psql $(DB_URL) -f sql/test/V001__test_event_store.sql
psql $(DB_URL) -f sql/test/V002__test_inventory_aggregate.sql
# ============================================================================
# BUILDING
# ============================================================================
build: ## Build Haskell application
@echo "$(BLUE)Building application...$(NC)"
stack build
build-docker: ## Build Docker image
@echo "$(BLUE)Building Docker image...$(NC)"
docker build -t surypus:latest .
build-proto: ## Generate code from protobuf
@echo "$(BLUE)Generating protobuf code...$(NC)"
protoc --haskell_out=src/api/grpc api/grpc/surypus.proto
# ============================================================================
# DOCKER OPERATIONS
# ============================================================================
docker-up: ## Start all services with Docker Compose
@echo "$(BLUE)Starting services...$(NC)"
docker-compose -f $(COMPOSE_FILE) up -d
@echo "$(GREEN)Services started!$(NC)"
@echo "API: http://localhost:3000"
@echo "Grafana: http://localhost:3001"
@echo "Redpanda Console: http://localhost:8080"
docker-down: ## Stop all services
@echo "$(RED)Stopping services...$(NC)"
docker-compose -f $(COMPOSE_FILE) down
docker-logs: ## Show service logs
docker-compose -f $(COMPOSE_FILE) logs -f
docker-ps: ## Show running containers
docker-compose -f $(COMPOSE_FILE) ps
docker-clean: ## Remove all containers and volumes
@echo "$(RED)Cleaning up Docker resources...$(NC)"
docker-compose -f $(COMPOSE_FILE) down -v --remove-orphans
docker system prune -f
# ============================================================================
# EVENT STORE OPERATIONS
# ============================================================================
events-replay: ## Replay events to rebuild projections
@echo "$(BLUE)Replaying events...$(NC)"
psql $(DB_URL) -c "SELECT rebuild_all_projections();"
events-stats: ## Show event store statistics
@echo "$(BLUE)Event Store Statistics:$(NC)"
psql $(DB_URL) -c "SELECT aggregate_type, COUNT(*) as event_count FROM event_store GROUP BY aggregate_type;"
snapshot-create: ## Create snapshots for aggregates
@echo "$(BLUE)Creating snapshots...$(NC)"
psql $(DB_URL) -c "SELECT create_snapshots_for_active_aggregates();"
# ============================================================================
# MONITORING
# ============================================================================
metrics: ## Show current metrics
@echo "$(BLUE)System Metrics:$(NC)"
psql $(DB_URL) -c "SELECT * FROM metrics_get_system_health();"
logs-api: ## Show API logs
docker-compose -f $(COMPOSE_FILE) logs -f surypus-api
logs-db: ## Show database logs
docker-compose -f $(COMPOSE_FILE) logs -f postgres
# ============================================================================
# OPA POLICIES
# ============================================================================
opa-test: ## Test OPA policies
@echo "$(BLUE)Testing OPA policies...$(NC)"
docker run --rm -v $(PWD)/opa/policies:/policies openpolicyagent/opa test /policies
opa-check: ## Validate OPA policies
@echo "$(BLUE)Validating OPA policies...$(NC)"
docker run --rm -v $(PWD)/opa/policies:/policies openpolicyagent/opa check /policies
# ============================================================================
# DEVELOPMENT UTILITIES
# ============================================================================
repl: ## Start Haskell REPL
stack repl
lint: ## Run linter
@echo "$(BLUE)Running linter...$(NC)"
hlint src/
format: ## Format code
@echo "$(BLUE)Formatting code...$(NC)"
find src -name "*.hs" -exec stylish-haskell -i {} \;
psql: ## Connect to database
psql $(DB_URL)
# ============================================================================
# CLEANUP
# ============================================================================
clean: ## Clean build artifacts
@echo "$(RED)Cleaning build artifacts...$(NC)"
stack clean
rm -rf .stack-work
distclean: clean docker-clean ## Clean everything
@echo "$(RED)Deep cleaning...$(NC)"
rm -rf docker/volumes