-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
186 lines (150 loc) · 5.12 KB
/
Copy pathMakefile
File metadata and controls
186 lines (150 loc) · 5.12 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
# Makefile for Node Microservices
.PHONY: help install dev build test lint format clean docker-up docker-down k8s-deploy terraform-init terraform-plan terraform-apply
# Default target
help:
@echo "Available commands:"
@echo " make install - Install dependencies"
@echo " make dev - Start development environment"
@echo " make build - Build all applications"
@echo " make test - Run tests"
@echo " make lint - Run linting"
@echo " make format - Format code"
@echo " make clean - Clean build artifacts"
@echo " make docker-up - Start Docker services"
@echo " make docker-down - Stop Docker services"
@echo " make kong-setup - Initialize Kong Gateway configuration"
@echo " make kong-status - Check Kong Gateway status"
@echo " make kong-services - List Kong services"
@echo " make kong-routes - List Kong routes"
@echo " make kong-logs - View Kong logs"
@echo " make k8s-deploy - Deploy to Kubernetes"
@echo " make terraform-init - Initialize Terraform"
@echo " make terraform-plan - Plan Terraform changes"
@echo " make terraform-apply - Apply Terraform changes"
# Install dependencies
install:
npm install
# Start development environment
dev: docker-up
@echo "Kong Gateway is running at http://localhost:8000"
@echo "Start your microservices with: make serve-<service-name>"
@echo "Available services: user-service, auth-service, notification-service"
# Build all applications
build:
npm run nx run-many --target=build --all --configuration=production
# Run tests
test:
npm run test
# Run linting
lint:
npm run lint
# Format code
format:
npm run format
# Clean build artifacts
clean:
rm -rf dist node_modules .nx
# Docker commands
# Detect docker compose command (new vs old style)
DOCKER_COMPOSE := $(shell command -v docker-compose 2> /dev/null || echo "docker compose")
docker-up:
$(DOCKER_COMPOSE) up -d
@echo "Waiting for services to be healthy..."
@sleep 10
@echo "Services are running:"
@echo " PostgreSQL: localhost:5432"
@echo " Redis: localhost:6379"
@echo " RabbitMQ: localhost:15672"
@echo " PgAdmin: localhost:5050"
@echo " Prometheus: localhost:9090"
@echo " Grafana: localhost:3001"
docker-down:
@if [ ! -f apps/stripe-service/.env ]; then \
echo "Creating empty apps/stripe-service/.env file..."; \
touch apps/stripe-service/.env; \
fi
$(DOCKER_COMPOSE) down
docker-clean:
$(DOCKER_COMPOSE) down -v
# Kubernetes commands
k8s-deploy-dev:
./scripts/deploy-k8s.sh -e development
k8s-deploy-staging:
./scripts/deploy-k8s.sh -e staging
k8s-deploy-prod:
./scripts/deploy-k8s.sh -e production
# Terraform commands
terraform-init:
./scripts/deploy-terraform.sh -a init
terraform-plan:
./scripts/deploy-terraform.sh -a plan
terraform-apply:
./scripts/deploy-terraform.sh -a apply
terraform-destroy:
./scripts/deploy-terraform.sh -a destroy
# Service-specific commands
serve-user-service:
npm run nx serve user-service
serve-auth-service:
npm run nx serve auth-service
serve-notification-service:
npm run nx serve notification-service
# Kong Gateway commands
kong-status:
@echo "Checking Kong status..."
@curl -s http://localhost:8001/status | jq '.' || echo "Kong is not running"
kong-services:
@echo "Listing Kong services..."
@curl -s http://localhost:8001/services | jq '.data[]' || echo "No services found"
kong-routes:
@echo "Listing Kong routes..."
@curl -s http://localhost:8001/routes | jq '.data[]' || echo "No routes found"
kong-reload:
@echo "Reloading Kong configuration..."
@docker-compose exec kong kong reload
kong-logs:
$(DOCKER_COMPOSE) logs -f kong
kong-admin:
@echo "Kong Admin API available at: http://localhost:8001"
@echo "Kong Manager GUI available at: http://localhost:8002"
@echo "Konga UI available at: http://localhost:1337"
kong-setup:
@echo "Running Kong setup script..."
@./scripts/setup-kong.sh
# Database commands
db-migrate:
npm run nx run-many --target=db:migrate --all
db-seed:
npm run nx run-many --target=db:seed --all
# Monitoring
logs-all:
$(DOCKER_COMPOSE) logs -f
# Security
security-scan:
npm audit
trivy fs .
# Auth Services Docker commands
docker-build-auth:
@echo "Building auth services Docker images..."
docker build -f apps/auth-service/Dockerfile -t auth-service:latest .
docker build -f apps/auth-frontend/Dockerfile -t auth-frontend:latest .
docker-auth-up: docker-up
@echo "Starting auth services..."
@echo "Waiting for Keycloak to be ready..."
@timeout=60; \
while ! curl -s -f -o /dev/null "http://localhost:8180/health/ready"; do \
if [ $$timeout -le 0 ]; then \
echo "Timeout waiting for Keycloak"; \
exit 1; \
fi; \
echo "Waiting for Keycloak... ($$timeout seconds remaining)"; \
sleep 5; \
timeout=$$((timeout - 5)); \
done
@echo "Keycloak is ready. Running setup script..."
./scripts/setup-keycloak.sh || echo "Keycloak might already be configured"
$(DOCKER_COMPOSE) up -d auth-service auth-frontend
@echo "Auth services are running:"
@echo " Auth Service API: http://localhost:3334/api"
@echo " Auth Frontend: http://localhost:4200"
@echo " Keycloak Admin: http://localhost:8180"