-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
303 lines (259 loc) · 10.6 KB
/
Makefile
File metadata and controls
303 lines (259 loc) · 10.6 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
# Banking Application Makefile
# Configuration
REGISTRY ?= ghcr.io/speedscale/microsvc
IMAGE_TAG ?= $(shell ./scripts/version.sh tag)
NAMESPACE ?= banking-app
KUSTOMIZE_DIR ?= kubernetes/base
SERVICES = user-service accounts-service transactions-service api-gateway
# Default target
.PHONY: help
.DEFAULT_GOAL := help
# Docker related targets
.PHONY: build-backend build-frontend build-all
build-backend:
@echo "Building backend services..."
@for service in $(SERVICES); do \
echo "Building $$service..."; \
cd backend/$$service && ./mvnw clean package -DskipTests && cd ../..; \
done
build-frontend:
@echo "Building frontend..."
cd frontend && npm ci && npm run build
build-all: build-backend build-frontend
# Docker image targets
.PHONY: docker-build docker-push docker-build-push
docker-build:
@echo "Building Docker images with version: $(IMAGE_TAG)..."
@for service in $(SERVICES); do \
echo "Building Docker image for $$service..."; \
docker build -t $(REGISTRY)/$$service:$(IMAGE_TAG) backend/$$service/; \
done
@echo "Building Docker image for frontend..."
docker build -t $(REGISTRY)/frontend:$(IMAGE_TAG) frontend/
docker-push:
@echo "Pushing Docker images to $(REGISTRY)..."
@for service in $(SERVICES) frontend; do \
echo "Pushing $$service..."; \
docker push $(REGISTRY)/$$service:$(IMAGE_TAG); \
done
docker-build-push: docker-build docker-push
# Local development with versioned images
.PHONY: docker-build-versioned docker-clean-versioned
docker-build-versioned:
@echo "Building versioned Docker images for local development..."
@VERSION_TAG=$$(./scripts/version.sh tag); \
for service in $(SERVICES); do \
echo "Building Docker image for $$service with tag: $$VERSION_TAG..."; \
docker build -t $(REGISTRY)/$$service:$$VERSION_TAG backend/$$service/; \
done
@VERSION_TAG=$$(./scripts/version.sh tag); \
echo "Building Docker image for frontend with tag: $$VERSION_TAG..."; \
docker build -t $(REGISTRY)/frontend:$$VERSION_TAG frontend/
@echo "Versioned images built successfully!"
@echo "Current version: $(shell ./scripts/version.sh get)"
@echo "Image tag: $(shell ./scripts/version.sh tag)"
docker-clean-versioned:
@echo "Cleaning versioned Docker images..."
@VERSION_TAG=$$(./scripts/version.sh tag); \
for service in $(SERVICES) frontend; do \
echo "Removing $$service:$$VERSION_TAG..."; \
docker rmi $(REGISTRY)/$$service:$$VERSION_TAG 2>/dev/null || true; \
done
# Test targets
.PHONY: test-backend test-frontend test-all test-e2e validate-e2e
test-backend:
@echo "Running backend tests..."
@for service in $(SERVICES); do \
echo "Testing $$service..."; \
cd backend/$$service && ./mvnw test && cd ../..; \
done
test-frontend:
@echo "Running frontend tests..."
cd frontend && npm ci && npm test -- --coverage --watchAll=false
test-e2e:
@echo "🎭 Running Playwright E2E tests..."
@cd frontend && ./run-e2e.sh
test-e2e-ui:
@echo "🎭 Running Playwright E2E tests with UI..."
@cd frontend && npm run test:e2e:ui
test-e2e-debug:
@echo "🎭 Running Playwright E2E tests in debug mode..."
@cd frontend && npm run test:e2e:headed
test-e2e-k8s:
@echo "🎭 Running Playwright E2E tests against Kubernetes..."
@echo "📡 Setting up port-forward to frontend service..."
@kubectl port-forward -n banking-app service/frontend-nodeport 30080:80 &
@sleep 3
@BASE_URL=http://localhost:30080 cd frontend && ./run-e2e.sh
@pkill -f "kubectl port-forward.*frontend-nodeport" || true
validate-e2e: test-e2e
test-all: test-backend test-frontend test-e2e
# Same as CI job proxymock-validation (requires initialized proxymock or PROXYMOCK_API_KEY; port 5432 must be free on host).
.PHONY: proxymock-validation
proxymock-validation:
./scripts/run-proxymock-validation.sh
# Run proxymock validation in Docker when host port 5432 is in use (set PROXYMOCK_API_KEY if proxymock is not initialized).
.PHONY: proxymock-validation-docker
proxymock-validation-docker:
./scripts/run-proxymock-validation-docker.sh
# Kubernetes targets - Consolidated
.PHONY: k8s-deploy observability-deploy speedscale-deploy k8s-cleanup k8s-status
k8s-deploy:
@echo "Deploying banking application to Kubernetes..."
kubectl apply -k $(KUSTOMIZE_DIR)/
observability-deploy:
@echo "Deploying observability stack..."
kubectl apply -k kubernetes/observability/
speedscale-deploy:
@echo "Deploying with Speedscale overlay..."
kubectl apply -k kubernetes/overlays/speedscale/
k8s-cleanup:
@echo "Cleaning up all Kubernetes resources..."
kubectl delete -k kubernetes/overlays/speedscale/ || true
kubectl delete -k kubernetes/observability/ || true
kubectl delete -k $(KUSTOMIZE_DIR)/ || true
k8s-status:
@echo "Checking deployment status..."
kubectl get all -n $(NAMESPACE)
@echo "\nPod status:"
kubectl get pods -n $(NAMESPACE) -o wide
@echo "\nService endpoints:"
kubectl get svc -n $(NAMESPACE)
# Development targets
.PHONY: dev-up dev-down dev-logs dev-reset
dev-up:
@echo "Starting development environment..."
docker-compose up -d
dev-down:
@echo "Stopping development environment..."
docker-compose down
dev-logs:
docker-compose logs -f
dev-reset: dev-down
@echo "Resetting development environment..."
docker-compose down -v
docker-compose up -d
# Testing and debugging targets
.PHONY: logs port-forward test-deployment
logs:
@echo "Fetching logs from all services..."
kubectl logs -n $(NAMESPACE) -l app.kubernetes.io/name=banking-app --tail=100 -f
port-forward:
@echo "Port forwarding API Gateway to localhost:8080..."
kubectl port-forward -n $(NAMESPACE) service/api-gateway 8080:8080
test-deployment:
@echo "Testing deployment with E2E test client..."
kubectl apply -f kubernetes/testing/test-client-job.yaml
@echo "Waiting for test job to complete..."
kubectl wait --for=condition=complete job/banking-e2e-test -n $(NAMESPACE) --timeout=300s
kubectl logs -n $(NAMESPACE) job/banking-e2e-test
kubectl delete job/banking-e2e-test -n $(NAMESPACE)
# CI/CD targets
.PHONY: ci-test ci-build ci-deploy pre-commit
ci-test: test-all
ci-build: build-all docker-build-push
ci-deploy: ci-build k8s-deploy
# Pre-commit validation
pre-commit:
@echo "🔍 Running pre-commit validation..."
@if [ -n "$(shell git diff --cached --name-only | grep -E '^frontend/')" ] || [ -n "$(shell git diff --name-only | grep -E '^frontend/')" ]; then \
echo "⚠️ Frontend changes detected. Running E2E validation..."; \
$(MAKE) test-e2e; \
else \
echo "✅ No frontend changes detected. Skipping E2E validation."; \
fi
@echo "✅ Pre-commit validation completed successfully!"
# Version management targets
.PHONY: version version-info version-bump version-set update-k8s-version
version:
@./scripts/version.sh get
version-info:
@./scripts/version.sh info
version-bump:
@if [ -z "$(BUMP_TYPE)" ]; then \
echo "Usage: make version-bump BUMP_TYPE=<patch|minor|major>"; \
exit 1; \
fi
@./scripts/version.sh bump $(BUMP_TYPE)
version-set:
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make version-set VERSION=<version>"; \
exit 1; \
fi
@./scripts/version.sh set $(VERSION)
update-frontend-version:
@./scripts/version.sh update-frontend
update-k8s-version:
@./scripts/version.sh update-k8s
# Utility targets
.PHONY: clean help
clean:
@echo "Cleaning up..."
@for service in $(SERVICES); do \
cd backend/$$service && ./mvnw clean && cd ../..; \
done
cd frontend && rm -rf .next node_modules || true
help:
@echo "Banking Application Makefile - Available targets:"
@echo ""
@echo "Build & Test:"
@echo " build-backend - Build all backend services"
@echo " build-frontend - Build frontend application"
@echo " build-all - Build all services"
@echo " docker-build - Build Docker images"
@echo " docker-push - Push Docker images to registry"
@echo " docker-build-push - Build and push Docker images"
@echo " docker-build-versioned - Build Docker images with current version tag"
@echo " docker-clean-versioned - Remove versioned Docker images"
@echo " test-backend - Run backend tests"
@echo " test-frontend - Run frontend tests"
@echo " test-e2e - Run Playwright E2E tests (automated user journey)"
@echo " test-e2e-ui - Run E2E tests with Playwright UI"
@echo " test-e2e-debug - Run E2E tests in headed browser mode"
@echo " test-e2e-k8s - Run E2E tests against Kubernetes deployment"
@echo " validate-e2e - Validate E2E tests (alias for test-e2e)"
@echo " test-all - Run all tests (backend, frontend, e2e)"
@echo " proxymock-validation - user-service proxymock mock+replay (matches CI; needs free :5432)"
@echo " proxymock-validation-docker - same test in Docker if host :5432 is busy"
@echo ""
@echo "Kubernetes:"
@echo " k8s-deploy - Deploy banking application to Kubernetes"
@echo " observability-deploy - Deploy observability stack (Grafana, Prometheus, Jaeger)"
@echo " speedscale-deploy - Deploy with Speedscale overlay"
@echo " k8s-cleanup - Clean up all Kubernetes resources"
@echo " k8s-status - Check deployment status"
@echo ""
@echo "Testing & Debugging:"
@echo " logs - Fetch logs from all services"
@echo " port-forward - Port forward API Gateway to localhost:8080"
@echo " test-deployment - Run E2E test against deployment"
@echo ""
@echo "Development:"
@echo " dev-up - Start development environment (Docker Compose)"
@echo " dev-down - Stop development environment"
@echo " dev-logs - Show development logs"
@echo " dev-reset - Reset development environment"
@echo ""
@echo "CI/CD:"
@echo " ci-test - Run CI tests"
@echo " ci-build - Run CI build and push"
@echo " ci-deploy - Run full CI/CD pipeline"
@echo " pre-commit - Run pre-commit validation"
@echo ""
@echo "Version Management:"
@echo " version - Get current version"
@echo " version-info - Show version information"
@echo " version-bump - Bump version (BUMP_TYPE=<patch|minor|major>)"
@echo " version-set - Set version (VERSION=<version>)"
@echo " update-frontend-version - Sync frontend/simulation-client package.json version from VERSION file"
@echo " update-k8s-version - Update Kubernetes manifests with current version"
@echo ""
@echo "Utilities:"
@echo " clean - Clean build artifacts"
@echo " help - Show this help"
@echo ""
@echo "Environment Variables:"
@echo " REGISTRY - Docker registry (default: ghcr.io/speedscale/microsvc)"
@echo " IMAGE_TAG - Docker image tag (default: latest)"
@echo " NAMESPACE - Kubernetes namespace (default: banking-app)"
@echo " KUSTOMIZE_DIR - Kustomize directory (default: kubernetes/base)"