Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
614 lines (557 loc) · 23.8 KB
/
Copy pathMakefile
File metadata and controls
614 lines (557 loc) · 23.8 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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
# OpenShift Deployment Makefile for Spending Transaction Monitor
# Configuration
PROJECT_NAME = spending-monitor
REGISTRY_URL ?= quay.io
REPOSITORY ?= rh-ai-quickstart
NAMESPACE ?= spending-transaction-monitor
IMAGE_TAG ?= latest
# Component image names
UI_IMAGE = $(REGISTRY_URL)/$(REPOSITORY)/$(PROJECT_NAME)-ui:$(IMAGE_TAG)
API_IMAGE = $(REGISTRY_URL)/$(REPOSITORY)/$(PROJECT_NAME)-api:$(IMAGE_TAG)
DB_IMAGE = $(REGISTRY_URL)/$(REPOSITORY)/$(PROJECT_NAME)-db:$(IMAGE_TAG)
# Local development image names (tagged as 'local')
UI_IMAGE_LOCAL = $(REGISTRY_URL)/$(REPOSITORY)/$(PROJECT_NAME)-ui:local
API_IMAGE_LOCAL = $(REGISTRY_URL)/$(REPOSITORY)/$(PROJECT_NAME)-api:local
DB_IMAGE_LOCAL = $(REGISTRY_URL)/$(REPOSITORY)/$(PROJECT_NAME)-db:local
# Environment file paths
ENV_FILE_DEV = .env.development
ENV_FILE_PROD = .env.production
ENV_FILE = $(ENV_FILE_DEV) # Default to development for backwards compatibility
# Helper function to generate helm parameters from environment variables
define HELM_SECRET_PARAMS
--set secrets.POSTGRES_DB="$$POSTGRES_DB" \
--set secrets.POSTGRES_USER="$$POSTGRES_USER" \
--set secrets.POSTGRES_PASSWORD="$$POSTGRES_PASSWORD" \
--set secrets.DATABASE_URL="$$DATABASE_URL" \
--set secrets.API_KEY="$$API_KEY" \
--set secrets.BASE_URL="$$BASE_URL" \
--set secrets.LLM_PROVIDER="$$LLM_PROVIDER" \
--set secrets.MODEL="$$MODEL" \
--set secrets.ENVIRONMENT="$$ENVIRONMENT" \
--set secrets.DEBUG="$$DEBUG" \
--set secrets.BYPASS_AUTH="$$BYPASS_AUTH" \
--set secrets.CORS_ALLOWED_ORIGINS="$${CORS_ALLOWED_ORIGINS//,/\\,}" \
--set secrets.ALLOWED_ORIGINS="$${ALLOWED_ORIGINS//,/\\,}" \
--set secrets.SMTP_HOST="$$SMTP_HOST" \
--set secrets.SMTP_PORT="$$SMTP_PORT" \
--set secrets.SMTP_FROM_EMAIL="$$SMTP_FROM_EMAIL" \
--set secrets.SMTP_USE_TLS="$$SMTP_USE_TLS" \
--set secrets.SMTP_USE_SSL="$$SMTP_USE_SSL" \
--set secrets.KEYCLOAK_URL="$$KEYCLOAK_URL" \
--set secrets.KEYCLOAK_REALM="$$KEYCLOAK_REALM" \
--set secrets.KEYCLOAK_CLIENT_ID="$$KEYCLOAK_CLIENT_ID" \
--set secrets.VITE_API_BASE_URL="$$VITE_API_BASE_URL"
endef
# Default target when running 'make' without arguments
.DEFAULT_GOAL := help
# Check if environment file exists
.PHONY: check-env-file
check-env-file:
@if [ ! -f "$(ENV_FILE)" ]; then \
echo "❌ Error: Environment file not found at $(ENV_FILE)"; \
echo ""; \
echo "Please create the environment file by copying the example:"; \
echo " cp env.example $(ENV_FILE)"; \
echo ""; \
echo "Then edit $(ENV_FILE) and update the values for your environment."; \
echo ""; \
echo "Key variables to update:"; \
echo " - API_KEY: Your OpenAI API key"; \
echo " - BASE_URL: Your LLM provider base URL"; \
echo " - POSTGRES_PASSWORD: Your database password"; \
echo ""; \
exit 1; \
fi
@echo "✅ Environment file found at $(ENV_FILE)"
# Check if development environment file exists
.PHONY: check-env-dev
check-env-dev:
@if [ ! -f "$(ENV_FILE_DEV)" ]; then \
echo "❌ Error: Development environment file not found at $(ENV_FILE_DEV)"; \
echo ""; \
echo "Please create the development environment file by copying the example:"; \
echo " cp env.example $(ENV_FILE_DEV)"; \
echo ""; \
exit 1; \
fi
@echo "✅ Development environment file found at $(ENV_FILE_DEV)"
# Check if production environment file exists
.PHONY: check-env-prod
check-env-prod:
@if [ ! -f "$(ENV_FILE_PROD)" ]; then \
echo "❌ Error: Production environment file not found at $(ENV_FILE_PROD)"; \
echo ""; \
echo "Please create the production environment file by copying the example:"; \
echo " cp env.example $(ENV_FILE_PROD)"; \
echo ""; \
echo "Remember to update production values:"; \
echo " - Set ENVIRONMENT=production"; \
echo " - Set BYPASS_AUTH=false"; \
echo " - Use strong production passwords"; \
echo " - Update DATABASE_URL to use Kubernetes service names"; \
echo ""; \
exit 1; \
fi
@echo "✅ Production environment file found at $(ENV_FILE_PROD)"
# Set up environment file for local development
.PHONY: setup-dev-env
setup-dev-env: check-env-dev
@echo "Using development environment file: $(ENV_FILE_DEV)"
@echo "✅ Development environment file is ready"
# Create environment file from example
.PHONY: create-env-file
create-env-file:
@if [ -f "$(ENV_FILE)" ]; then \
echo "⚠️ Environment file already exists at $(ENV_FILE)"; \
echo "Remove it first if you want to recreate it."; \
exit 1; \
fi
@echo "📄 Creating environment file from example..."
@cp env.example "$(ENV_FILE)"
@echo "✅ Environment file created at $(ENV_FILE)"
@echo ""
@echo "🔧 Please edit .env and update the following required values:"
@echo " - API_KEY: Your OpenAI API key"
@echo " - POSTGRES_PASSWORD: Your desired database password"
@echo " - Other values as needed for your environment"
# List available alert rule samples
.PHONY: list-alert-samples
list-alert-samples:
@echo "📋 Available Alert Rule Sample Files:"
@echo "============================================"
@echo ""
@for file in packages/db/src/db/scripts/json/*.json; do \
if [ -f "$$file" ]; then \
filename=$$(basename "$$file"); \
alert_text=$$(jq -r '.alert_text // "No alert_text found"' "$$file" 2>/dev/null || echo "Invalid JSON"); \
printf "🔹 %-45s\n" "$$filename"; \
printf " %s\n\n" "$$alert_text"; \
fi; \
done
# Interactive alert rule testing menu
.PHONY: test-alert-rules
test-alert-rules:
@echo "🧪 Alert Rule Testing Menu"
@echo "============================================"
@echo ""
@echo "Select an alert rule to test:"
@echo ""
@i=1; \
declare -a files; \
declare -a alert_texts; \
for file in packages/db/src/db/scripts/json/*.json; do \
if [ -f "$$file" ]; then \
filename=$$(basename "$$file"); \
alert_text=$$(jq -r '.alert_text // "No alert_text found"' "$$file" 2>/dev/null || echo "Invalid JSON"); \
files[$$i]="$$filename"; \
alert_texts[$$i]="$$alert_text"; \
printf "%-3s %s\n" "$$i)" "$$alert_text"; \
i=$$((i + 1)); \
fi; \
done; \
echo ""; \
printf "Enter your choice (1-$$((i-1))) or 'q' to quit: "; \
read choice; \
if [ "$$choice" = "q" ] || [ "$$choice" = "Q" ]; then \
echo "👋 Exiting..."; \
exit 0; \
fi; \
if [ "$$choice" -ge 1 ] && [ "$$choice" -le $$((i-1)) ] 2>/dev/null; then \
selected_file="$${files[$$choice]}"; \
selected_alert_text="$${alert_texts[$$choice]}"; \
echo ""; \
echo "📋 Selected Alert Rule: $$selected_alert_text"; \
echo "============================================"; \
echo ""; \
echo "📊 Data Preview will be shown by the test script..."; \
echo ""; \
printf "🤔 Do you want to proceed with this test? (y/N): "; \
read confirm; \
if [ "$$confirm" = "y" ] || [ "$$confirm" = "Y" ] || [ "$$confirm" = "yes" ] || [ "$$confirm" = "Yes" ]; then \
echo ""; \
echo "🚀 Running test for: $$selected_alert_text"; \
echo "============================================"; \
cd packages/db/src/db/scripts && ./test_alert_rules.sh "$$selected_file"; \
else \
echo ""; \
echo "❌ Test cancelled. Returning to main menu..."; \
echo ""; \
make test-alert-rules; \
fi; \
else \
echo "❌ Invalid choice. Please enter a number between 1 and $$((i-1)), or 'q' to quit."; \
exit 1; \
fi
# Default target
.PHONY: help
help:
@echo "Available targets:"
@echo " Building:"
@echo " build-all Build all Podman images"
@echo " build-ui Build UI image"
@echo " build-api Build API image"
@echo " build-db Build database migration image (includes CSV data loading)"
@echo ""
@echo " Pushing:"
@echo " push-all Push all images to registry"
@echo " push-ui Push UI image to registry"
@echo " push-api Push API image to registry"
@echo " push-db Push database migration image to registry"
@echo ""
@echo " Deploying:"
@echo " deploy Deploy application using Helm"
@echo " deploy-dev Deploy in development mode"
@echo " deploy-all Build, push and deploy all components"
@echo " full-deploy Complete pipeline: login, build, push, deploy"
@echo ""
@echo " Undeploying:"
@echo " undeploy Remove application deployment"
@echo " undeploy-all Remove deployment and namespace"
@echo ""
@echo " Development:"
@echo " port-forward-api Forward API service to localhost:8000"
@echo " port-forward-ui Forward UI service to localhost:8080"
@echo " port-forward-db Forward database to localhost:5432"
@echo ""
@echo " Local Development:"
@echo " run-local Start all services (always pull latest from quay.io registry)"
@echo " build-local Build local Podman images and tag them as 'local'"
@echo " build-run-local Build and run all services locally using 'local' tagged images"
@echo " stop-local Stop local Podman Compose services"
@echo " logs-local Show logs from local services"
@echo " reset-local Reset environment (pull latest, restart with fresh data)"
@echo " pull-local Pull latest images from quay.io registry"
@echo " setup-local Complete local setup (pull, run, migrate, seed)"
@echo ""
@echo " Helm:"
@echo " helm-lint Lint Helm chart"
@echo " helm-template Render Helm templates"
@echo " helm-debug Debug Helm deployment"
@echo ""
@echo " Testing:"
@echo " test-alert-rules Interactive menu to test alert rules"
@echo " list-alert-samples List available sample alert rule files"
@echo ""
@echo " Setup:"
@echo " setup-data Complete data setup (migrations + seed all)"
@echo ""
@echo " Seeding:"
@echo " seed-db Seed database with sample data"
@echo " seed-keycloak Set up Keycloak realm (without DB user sync)"
@echo " seed-keycloak-with-users Set up Keycloak and sync DB users"
@echo " seed-all Seed both database and Keycloak with users"
@echo ""
@echo " Utilities:"
@echo " login Login to OpenShift registry"
@echo " create-project Create OpenShift project"
@echo " status Show deployment status"
@echo " clean-all Clean up all resources"
@echo " clean-images Remove local Podman images"
@echo " clean-local-images Remove local development images (tagged as 'local')"
@echo " check-env-file Check if environment file exists"
@echo " create-env-file Create environment file from example"
@echo ""
@echo " Environment Setup:"
@echo " This project uses separate environment files for different scenarios:"
@echo " .env.development - For local development (run-local, build-run-local, etc.)"
@echo " .env.production - For OpenShift deployment (deploy, deploy-dev, etc.)"
@echo ""
@echo " Environment file checks:"
@echo " make check-env-dev # Check development environment file"
@echo " make check-env-prod # Check production environment file"
@echo " make setup-dev-env # Set up .env from .env.development for local use"
@echo ""
@echo "Examples:"
@echo " make setup-local # Complete local setup (pulls from quay.io)"
@echo " make run-local # Start all services (pulls latest from quay.io)"
@echo " make build-run-local # Build and run with local images (tagged as 'local')"
@echo " make test-alert-rules # Interactive alert rule testing"
@echo " make list-alert-samples # List available alert samples"
@echo " make NAMESPACE=my-app deploy # Deploy to custom namespace"
# Login to OpenShift registry
.PHONY: login
login:
@echo "Logging into OpenShift registry..."
@oc whoami --show-token | podman login --username=$(shell oc whoami) --password-stdin $(REGISTRY_URL)
# Create OpenShift project
.PHONY: create-project
create-project:
@echo "Creating OpenShift project: $(NAMESPACE)"
@oc new-project $(NAMESPACE) || echo "Project $(NAMESPACE) already exists"
# Build targets
.PHONY: build-ui
build-ui:
@echo "Building UI image..."
podman build --platform=linux/amd64 -t $(UI_IMAGE) -f ./packages/ui/Containerfile .
.PHONY: build-api
build-api:
@echo "Building API image..."
podman build --platform=linux/amd64 -t $(API_IMAGE) -f ./packages/api/Containerfile .
.PHONY: build-db
build-db:
@echo "Building database image..."
podman build --platform=linux/amd64 -t $(DB_IMAGE) -f ./packages/db/Containerfile .
.PHONY: build-all
build-all: build-ui build-api build-db
@echo "All images built successfully"
# Push targets
.PHONY: push-ui
push-ui: build-ui
@echo "Pushing UI image..."
podman push $(UI_IMAGE)
.PHONY: push-api
push-api: build-api
@echo "Pushing API image..."
podman push $(API_IMAGE)
.PHONY: push-db
push-db: build-db
@echo "Pushing database image..."
podman push $(DB_IMAGE)
.PHONY: push-all
push-all: push-ui push-api push-db
@echo "All images pushed successfully"
# Deploy targets
.PHONY: deploy
deploy: create-project check-env-prod
@echo "Deploying application using Helm with production environment variables..."
@echo "Using production environment file: $(ENV_FILE_PROD)"
@set -a; source $(ENV_FILE_PROD); set +a; \
export POSTGRES_DB POSTGRES_USER POSTGRES_PASSWORD DATABASE_URL API_KEY BASE_URL LLM_PROVIDER MODEL ENVIRONMENT DEBUG BYPASS_AUTH CORS_ALLOWED_ORIGINS ALLOWED_ORIGINS ALLOWED_HOSTS SMTP_HOST SMTP_PORT SMTP_FROM_EMAIL SMTP_USE_TLS SMTP_USE_SSL KEYCLOAK_URL KEYCLOAK_REALM KEYCLOAK_CLIENT_ID VITE_API_BASE_URL; \
helm upgrade --install $(PROJECT_NAME) ./deploy/helm/spending-monitor \
--namespace $(NAMESPACE) \
--set global.imageRegistry=$(REGISTRY_URL) \
--set global.imageRepository=$(REPOSITORY) \
--set global.imageTag=$(IMAGE_TAG) \
$(HELM_SECRET_PARAMS)
.PHONY: deploy-dev
deploy-dev: create-project check-env-prod
@echo "Deploying application in development mode with production environment variables..."
@echo "Using production environment file: $(ENV_FILE_PROD)"
@echo "Note: This is still a production deployment with reduced resources for development/testing"
@set -a; source $(ENV_FILE_PROD); set +a; \
export POSTGRES_DB POSTGRES_USER POSTGRES_PASSWORD DATABASE_URL API_KEY BASE_URL LLM_PROVIDER MODEL ENVIRONMENT DEBUG BYPASS_AUTH CORS_ALLOWED_ORIGINS ALLOWED_ORIGINS ALLOWED_HOSTS SMTP_HOST SMTP_PORT SMTP_FROM_EMAIL SMTP_USE_TLS SMTP_USE_SSL KEYCLOAK_URL KEYCLOAK_REALM KEYCLOAK_CLIENT_ID VITE_API_BASE_URL; \
helm upgrade --install $(PROJECT_NAME) ./deploy/helm/spending-monitor \
--namespace $(NAMESPACE) \
--set global.imageRegistry=$(REGISTRY_URL) \
--set global.imageRepository=$(REPOSITORY) \
--set global.imageTag=$(IMAGE_TAG) \
--set database.persistence.enabled=false \
--set api.replicas=1 \
--set ui.replicas=1 \
$(HELM_SECRET_PARAMS)
.PHONY: deploy-all
deploy-all: build-all push-all deploy
@echo "Complete deployment finished successfully"
# Undeploy targets
.PHONY: undeploy
undeploy:
@echo "Undeploying application..."
helm uninstall $(PROJECT_NAME) --namespace $(NAMESPACE) || echo "Release $(PROJECT_NAME) not found"
.PHONY: undeploy-all
undeploy-all: undeploy
@echo "Cleaning up namespace..."
oc delete project $(NAMESPACE) || echo "Project $(NAMESPACE) not found or cannot be deleted"
# Full deployment pipeline
.PHONY: full-deploy
full-deploy: login create-project build-all push-all deploy
@echo "Full deployment completed!"
# Development helpers
.PHONY: port-forward-api
port-forward-api:
@echo "Port forwarding API service to localhost:8000..."
oc port-forward service/spending-monitor-api 8000:8000 --namespace $(NAMESPACE)
.PHONY: port-forward-ui
port-forward-ui:
@echo "Port forwarding UI service to localhost:8080..."
oc port-forward service/spending-monitor-ui 8080:8080 --namespace $(NAMESPACE)
.PHONY: port-forward-db
port-forward-db:
@echo "Port forwarding database service to localhost:5432..."
oc port-forward service/spending-monitor-db 5432:5432 --namespace $(NAMESPACE)
# Helm helpers
.PHONY: helm-lint
helm-lint:
@echo "Linting Helm chart..."
helm lint ./deploy/helm/spending-monitor
.PHONY: helm-template
helm-template: check-env-prod
@echo "Rendering Helm templates with production environment variables..."
@echo "Using production environment file: $(ENV_FILE_PROD)"
@set -a; source $(ENV_FILE_PROD); set +a; \
export POSTGRES_DB POSTGRES_USER POSTGRES_PASSWORD DATABASE_URL API_KEY BASE_URL LLM_PROVIDER MODEL ENVIRONMENT DEBUG BYPASS_AUTH CORS_ALLOWED_ORIGINS ALLOWED_ORIGINS ALLOWED_HOSTS SMTP_HOST SMTP_PORT SMTP_FROM_EMAIL SMTP_USE_TLS SMTP_USE_SSL KEYCLOAK_URL KEYCLOAK_REALM KEYCLOAK_CLIENT_ID VITE_API_BASE_URL; \
helm template $(PROJECT_NAME) ./deploy/helm/spending-monitor \
--set global.imageRegistry=$(REGISTRY_URL) \
--set global.imageRepository=$(REPOSITORY) \
--set global.imageTag=$(IMAGE_TAG) \
$(HELM_SECRET_PARAMS)
.PHONY: helm-debug
helm-debug: check-env-prod
@echo "Debugging Helm deployment with production environment variables..."
@echo "Using production environment file: $(ENV_FILE_PROD)"
@set -a; source $(ENV_FILE_PROD); set +a; \
export POSTGRES_DB POSTGRES_USER POSTGRES_PASSWORD DATABASE_URL API_KEY BASE_URL LLM_PROVIDER MODEL ENVIRONMENT DEBUG BYPASS_AUTH CORS_ALLOWED_ORIGINS ALLOWED_ORIGINS ALLOWED_HOSTS SMTP_HOST SMTP_PORT SMTP_FROM_EMAIL SMTP_USE_TLS SMTP_USE_SSL KEYCLOAK_URL KEYCLOAK_REALM KEYCLOAK_CLIENT_ID VITE_API_BASE_URL; \
helm upgrade --install $(PROJECT_NAME) ./deploy/helm/spending-monitor \
--namespace $(NAMESPACE) \
--set global.imageRegistry=$(REGISTRY_URL) \
--set global.imageRepository=$(REPOSITORY) \
--set global.imageTag=$(IMAGE_TAG) \
$(HELM_SECRET_PARAMS) \
--dry-run --debug
# Clean up targets
.PHONY: clean-images
clean-images:
@echo "Cleaning up local images..."
@podman rmi $(UI_IMAGE) $(API_IMAGE) $(DB_IMAGE) || true
.PHONY: clean-local-images
clean-local-images:
@echo "Cleaning up local development images..."
@podman rmi $(UI_IMAGE_LOCAL) $(API_IMAGE_LOCAL) $(DB_IMAGE_LOCAL) || true
.PHONY: clean-all
clean-all: undeploy-all clean-images clean-local-images
@echo "Complete cleanup finished"
# Status and logs
.PHONY: status
status:
@echo "Checking application status..."
@helm status $(PROJECT_NAME) --namespace $(NAMESPACE) || echo "Release not found"
@echo "\nPod status:"
@oc get pods --namespace $(NAMESPACE) || echo "No pods found"
@echo "\nServices:"
@oc get svc --namespace $(NAMESPACE) || echo "No services found"
@echo "\nIngress:"
@oc get ingress --namespace $(NAMESPACE) || echo "No ingress found"
.PHONY: logs
logs:
@echo "Getting application logs..."
@echo "=== API Logs ==="
@oc logs -l app.kubernetes.io/component=api --namespace $(NAMESPACE) --tail=20 || echo "No API logs found"
@echo "\n=== UI Logs ==="
@oc logs -l app.kubernetes.io/component=ui --namespace $(NAMESPACE) --tail=20 || echo "No UI logs found"
@echo "\n=== Database Logs ==="
@oc logs -l app.kubernetes.io/component=database --namespace $(NAMESPACE) --tail=20 || echo "No database logs found"
.PHONY: logs-ui
logs-ui:
@oc logs -f -l app.kubernetes.io/component=ui --namespace $(NAMESPACE)
.PHONY: logs-api
logs-api:
@oc logs -f -l app.kubernetes.io/component=api --namespace $(NAMESPACE)
.PHONY: logs-db
logs-db:
@oc logs -f -l app.kubernetes.io/component=database --namespace $(NAMESPACE)
# Local development targets using Podman Compose
.PHONY: run-local
run-local: setup-dev-env
@echo "Starting all services locally with Podman Compose using development environment..."
@echo "Using development environment file: $(ENV_FILE_DEV)"
@echo "This will start: PostgreSQL, API, UI, nginx proxy, and SMTP server"
@echo "Services will be available at:"
@echo " - Frontend: http://localhost:3000"
@echo " - API (proxied): http://localhost:3000/api/*"
@echo " - API (direct): http://localhost:8000"
@echo " - API Docs: http://localhost:8000/docs"
@echo " - SMTP Web UI: http://localhost:3002"
@echo " - Database: localhost:5432"
@echo ""
@echo "Pulling latest images from quay.io registry..."
IMAGE_TAG=latest podman-compose -f podman-compose.yml pull
IMAGE_TAG=latest podman-compose -f podman-compose.yml up -d
@echo ""
@echo "Waiting for database to be ready..."
@sleep 15
@echo ""
@echo "✅ All services started and database is ready!"
@echo ""
@echo "To also start pgAdmin for database management, run:"
@echo " podman-compose -f podman-compose.yml --profile tools up -d pgadmin"
@echo " Then access pgAdmin at: http://localhost:8080"
@echo ""
@echo "To view logs: make logs-local"
@echo "To stop services: make stop-local"
.PHONY: stop-local
stop-local:
@echo "Stopping local Podman Compose services..."
podman-compose -f podman-compose.yml down
@echo "Removing db data..."
podman volume rm --all || true
.PHONY: build-local
build-local:
@echo "Building local Podman images with 'local' tag..."
podman-compose -f podman-compose.yml -f podman-compose.build.yml build
@echo "✅ Local images built and tagged successfully"
.PHONY: pull-local
pull-local:
@echo "Pulling latest images from quay.io registry..."
IMAGE_TAG=latest podman-compose -f podman-compose.yml pull
.PHONY: logs-local
logs-local:
@echo "Showing logs from local services..."
podman-compose -f podman-compose.yml logs -f
.PHONY: reset-local
reset-local: setup-dev-env
@echo "Resetting local environment..."
@echo "This will stop services, remove containers and volumes, pull latest images, and restart"
podman-compose -f podman-compose.yml down -v
@echo "Pulling latest images from quay.io registry..."
IMAGE_TAG=latest podman-compose -f podman-compose.yml pull
IMAGE_TAG=latest podman-compose -f podman-compose.yml up -d
@echo ""
@echo "Waiting for database to be ready..."
@sleep 15
@echo "Running database migrations..."
@pnpm db:upgrade || (echo "❌ Database upgrade failed. Check if database is running." && exit 1)
@echo "Seeding database with test data..."
@pnpm db:seed || (echo "❌ Database seeding failed. Check migration status." && exit 1)
@echo ""
@echo "✅ Local environment has been reset and database is ready!"
.PHONY: build-run-local
build-run-local: setup-dev-env build-local
@echo "Starting all services locally with freshly built images (tagged as 'local')..."
@echo "This will start: PostgreSQL, API, UI, nginx proxy, and SMTP server"
@echo "Services will be available at:"
@echo " - Frontend: http://localhost:3000"
@echo " - API (proxied): http://localhost:3000/api/*"
@echo " - API (direct): http://localhost:8000"
@echo " - API Docs: http://localhost:8000/docs"
@echo " - SMTP Web UI: http://localhost:3002"
@echo " - Database: localhost:5432"
@echo ""
IMAGE_TAG=local podman-compose -f podman-compose.yml -f podman-compose.build.yml up -d
@echo ""
@echo "Waiting for database to be ready..."
@sleep 15
@echo "Database migrations and seeding are handled automatically by the migrations container..."
@echo ""
@echo "✅ All services started and database is ready!"
@echo ""
@echo "To also start pgAdmin for database management, run:"
@echo " IMAGE_TAG=local podman-compose -f podman-compose.yml -f podman-compose.build.yml --profile tools up -d pgadmin"
@echo " Then access pgAdmin at: http://localhost:8080"
@echo ""
@echo "To view logs: make logs-local"
@echo "To stop services: make stop-local"
.PHONY: setup-local
setup-local: check-env-dev pull-local run-local
@echo "✅ Local development environment is fully set up and ready!"
@echo "Database has been migrated and seeded with test data."
# Seeding targets
.PHONY: seed-db
seed-db:
@echo "🌱 Seeding database with sample data..."
@echo "Running seed script inside API container..."
podman exec spending-monitor-api python -m db.scripts.seed
@echo "✅ Database seeded successfully"
.PHONY: seed-keycloak
seed-keycloak:
@echo "🔐 Setting up Keycloak realm..."
pnpm seed:keycloak
.PHONY: seed-keycloak-with-users
seed-keycloak-with-users:
@echo "🔐 Setting up Keycloak realm and syncing database users..."
pnpm seed:keycloak-with-users
.PHONY: seed-all
seed-all: seed-keycloak-with-users seed-db
@echo "✅ All data seeded successfully (database + Keycloak)"
.PHONY: setup-data
setup-data:
@echo "🚀 Setting up data: Running migrations, then seeding database and Keycloak..."
pnpm setup:data