-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
220 lines (192 loc) · 9.66 KB
/
Copy pathMakefile
File metadata and controls
220 lines (192 loc) · 9.66 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
.PHONY: help setup dev-up dev-down build-images kind-setup kind-deploy kind-cleanup gke-setup gke-deploy clean
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
setup: ## Install dependencies and setup project
@echo "Setting up project..."
@echo "Installing frontend dependencies..."
cd frontend && npm install
@echo "Installing backend dependencies..."
cd backend && go mod download && go mod tidy
@echo "Verifying Go dependencies..."
cd backend && go mod verify
@echo "Creating necessary directories..."
mkdir -p docker/grafana/provisioning/datasources
mkdir -p docker/grafana/provisioning/dashboards
mkdir -p docker/grafana/dashboards
@echo "Setup complete!"
setup-observability: ## Setup observability stack configurations
@echo "Setting up observability configurations..."
@echo "Prometheus configuration: docker/prometheus.yml"
@echo "Grafana provisioning: docker/grafana/provisioning/"
@echo "Fluent Bit configuration: docker/fluent-bit.conf"
@echo "Observability setup complete!"
install-tools: ## Install required development tools
@echo "Installing development tools..."
@command -v docker >/dev/null 2>&1 || { echo "Docker is required but not installed. Please install Docker first."; exit 1; }
@command -v node >/dev/null 2>&1 || { echo "Node.js is required but not installed. Please install Node.js first."; exit 1; }
@command -v go >/dev/null 2>&1 || { echo "Go is required but not installed. Please install Go first."; exit 1; }
@command -v kubectl >/dev/null 2>&1 || { echo "kubectl is required but not installed. Please install kubectl first."; exit 1; }
@command -v helm >/dev/null 2>&1 || { echo "Helm is required but not installed. Please install Helm first."; exit 1; }
@command -v kind >/dev/null 2>&1 || { echo "Kind is required but not installed. Please install Kind first."; exit 1; }
@echo "All required tools are installed!"
verify-setup: ## Verify project setup and dependencies
@echo "Verifying project setup..."
@echo "Checking frontend dependencies..."
cd frontend && npm list --depth=0
@echo "Checking backend dependencies..."
cd backend && go list -m all
@echo "Checking Docker images..."
docker images | grep -E "(tutorial-frontend|tutorial-backend)" || echo "No tutorial images found (run 'make build-images' to build them)"
@echo "Verification complete!"
dev-up: ## Start development environment with docker-compose
@echo "Starting development environment with full observability stack..."
docker-compose up -d
@echo "Waiting for services to be ready..."
@sleep 10
@echo ""
@echo "🎉 Development environment started!"
@echo ""
@echo "📱 Application Services:"
@echo " Frontend: http://localhost:3000"
@echo " Backend API: http://localhost:8080"
@echo " GraphQL: http://localhost:8080/graphql"
@echo " Health Check: http://localhost:8080/health"
@echo " Metrics: http://localhost:9090/metrics"
@echo ""
@echo "📊 Observability Stack:"
@echo " Grafana: http://localhost:3001 (admin/admin123)"
@echo " Prometheus: http://localhost:9091"
@echo " Jaeger UI: http://localhost:16686"
@echo " Kibana: http://localhost:5601"
@echo " Elasticsearch: http://localhost:9200"
@echo ""
@echo "💾 Database:"
@echo " PostgreSQL: localhost:5432 (user/password)"
@echo ""
@echo "Use 'make dev-logs' to view logs or 'make dev-status' to check status"
dev-down: ## Stop development environment
@echo "Stopping development environment..."
docker-compose down
@echo "Development environment stopped!"
dev-logs: ## View logs from development environment
docker-compose logs -f
dev-status: ## Check status of development services
@echo "Development Environment Status:"
@echo "================================"
docker-compose ps
dev-restart: ## Restart development environment
@echo "Restarting development environment..."
docker-compose restart
@echo "Development environment restarted!"
dev-clean: ## Clean development environment (remove volumes)
@echo "Cleaning development environment..."
docker-compose down -v
docker-compose rm -f
@echo "Development environment cleaned!"
dev-rebuild: ## Rebuild and restart development environment
@echo "Rebuilding development environment..."
docker-compose down
docker-compose build --no-cache
docker-compose up -d
@echo "Development environment rebuilt and started!"
build-images: ## Build Docker images
@echo "Building optimized Docker images..."
docker build -f docker/Dockerfile.frontend -t tutorial-frontend:latest -t tutorial-frontend:dev .
docker build -f docker/Dockerfile.backend -t tutorial-backend:latest -t tutorial-backend:dev .
@echo "Docker images built successfully!"
build-images-no-cache: ## Build Docker images without cache
@echo "Building Docker images without cache..."
docker build --no-cache -f docker/Dockerfile.frontend -t tutorial-frontend:latest -t tutorial-frontend:dev .
docker build --no-cache -f docker/Dockerfile.backend -t tutorial-backend:latest -t tutorial-backend:dev .
@echo "Docker images built successfully!"
docker-setup: ## Run comprehensive Docker setup
@echo "Running comprehensive Docker setup..."
chmod +x scripts/docker-setup.sh
./scripts/docker-setup.sh
docker-setup-fast: ## Run Docker setup (skip pull and test)
@echo "Running fast Docker setup..."
chmod +x scripts/docker-setup.sh
./scripts/docker-setup.sh --skip-pull --skip-test
docker-cleanup: ## Clean up Docker resources
@echo "Cleaning up Docker resources..."
chmod +x scripts/docker-setup.sh
./scripts/docker-setup.sh --cleanup
docker system prune -f
@echo "Docker cleanup completed!"
test-images: ## Test Docker images
@echo "Testing Docker images..."
@echo "Testing backend image..."
docker run --rm tutorial-backend:latest --help 2>/dev/null || echo "Backend image ready (no --help flag)"
@echo "Testing frontend image..."
@timeout 10s docker run --rm -p 8888:80 tutorial-frontend:latest &
@sleep 3
@curl -f http://localhost:8888 >/dev/null 2>&1 && echo "Frontend image: ✅" || echo "Frontend image: ⚠️"
@docker stop $$(docker ps -q --filter ancestor=tutorial-frontend:latest) 2>/dev/null || true
kind-setup: ## Setup Kind cluster
@echo "Creating Kind cluster..."
kind create cluster --name tutorial-cluster --config scripts/kind-config.yaml
kubectl cluster-info --context kind-tutorial-cluster
@echo "Installing ingress controller..."
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=90s
kind-deploy: build-images ## Deploy to Kind cluster
@echo "Loading images to Kind..."
kind load docker-image tutorial-frontend:latest --name tutorial-cluster
kind load docker-image tutorial-backend:latest --name tutorial-cluster
@echo "Deploying with Helm..."
helm dependency update helm/tutorial-app
helm upgrade --install tutorial-app helm/tutorial-app --namespace tutorial-app --create-namespace
@echo "Deployment complete!"
@echo "Add '127.0.0.1 tutorial-app.local' to your /etc/hosts file"
@echo "Then visit: http://tutorial-app.local"
kind-cleanup: ## Cleanup Kind cluster
kind delete cluster --name tutorial-cluster
gke-setup: ## Setup GKE cluster with Terraform
cd terraform && terraform init && terraform plan && terraform apply -auto-approve
gke-deploy: build-images ## Deploy to GKE cluster
@echo "Deploying to GKE..."
# Get GKE credentials
gcloud container clusters get-credentials tutorial-app-cluster --zone us-central1-a
# Deploy application
helm dependency update helm/tutorial-app
helm upgrade --install tutorial-app helm/tutorial-app \
--namespace tutorial-production \
--create-namespace \
--values helm/tutorial-app/values-production.yaml \
--set image.frontend.repository=gcr.io/$(GCP_PROJECT_ID)/tutorial-frontend \
--set image.backend.repository=gcr.io/$(GCP_PROJECT_ID)/tutorial-backend \
--set image.frontend.tag=latest \
--set image.backend.tag=latest
observability-status: ## Check observability stack status
@echo "Checking observability stack status..."
kubectl get pods -n observability
kubectl get pods -n logging
kubectl get pods -n istio-system
kubectl get svc -n observability
kubectl get svc -n logging
kubectl get svc -n istio-system
observability-urls: ## Get observability dashboard URLs
@echo "Observability Dashboard URLs:"
@echo "Grafana: http://$$(kubectl get svc prometheus-grafana -n observability -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
@echo "Kibana: http://$$(kubectl get svc kibana-kibana -n logging -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):5601"
@echo "Jaeger: http://$$(kubectl get svc jaeger-query -n observability -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):16686"
@echo "Kiali: http://$$(kubectl get svc kiali -n istio-system -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):20001"
port-forward-observability: ## Port forward observability services for local access
@echo "Setting up port forwarding for observability services..."
kubectl port-forward svc/prometheus-grafana 3001:80 -n observability &
kubectl port-forward svc/kibana-kibana 5601:5601 -n logging &
kubectl port-forward svc/jaeger-query 16686:16686 -n observability &
kubectl port-forward svc/kiali 20001:20001 -n istio-system &
@echo "Port forwarding setup complete:"
@echo "Grafana: http://localhost:3001"
@echo "Kibana: http://localhost:5601"
@echo "Jaeger: http://localhost:16686"
@echo "Kiali: http://localhost:20001"
clean: ## Clean up local resources
docker-compose down -v
docker system prune -f
clean-gke: ## Clean up GKE resources
cd terraform && terraform destroy -auto-approve