-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
157 lines (137 loc) · 5.72 KB
/
Makefile
File metadata and controls
157 lines (137 loc) · 5.72 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
.PHONY: deploy deploy-from-source destroy build publish pull-images load-images status cluster db monitoring app \
compose-up compose-down compose-logs compose-build-up
CLUSTER_NAME := lab
APP_NAMESPACE := app
DB_NAMESPACE := db
MON_NAMESPACE := monitoring
HELM_CHART := ./helm/reference-app
KIND_CONFIG := ../infrastructure/kind/cluster-config.yaml
PROM_VALUES := ../infrastructure/helm/prometheus-lab-values.yaml
IMAGE_TAG := 1.0.0
REGISTRY := schoolofdevops
GIT_SHA := $(shell git rev-parse --short HEAD 2>/dev/null || echo "dev")
# --- Kubernetes (KIND) deployment ---
# One-command deploy: creates cluster, installs DB + monitoring, pulls pre-built images, deploys app
# Uses pre-built images from Docker Hub — no local Rust compilation required.
# To build from source instead: make deploy-from-source
deploy: cluster db monitoring pull-images load-images app
@echo ""
@echo "=== Deployment Complete ==="
@echo "Dashboard: http://localhost:30080"
@echo "Grafana: http://localhost:30090 (admin/admin)"
@echo "Prometheus: http://localhost:30091"
@echo ""
cluster:
@kind get clusters 2>/dev/null | grep -q "^$(CLUSTER_NAME)$$" || \
kind create cluster --config $(KIND_CONFIG)
db:
@helm repo add bitnami https://charts.bitnami.com/bitnami 2>/dev/null || true
@helm repo update bitnami
helm upgrade --install postgresql bitnami/postgresql \
--namespace $(DB_NAMESPACE) --create-namespace \
--set auth.username=refapp \
--set auth.password=refapp-lab-password \
--set auth.database=refapp \
--set primary.resources.requests.cpu=50m \
--set primary.resources.requests.memory=128Mi \
--wait --timeout 120s
monitoring:
@helm repo add prometheus-community https://prometheus-community.github.io/helm-charts 2>/dev/null || true
@helm repo update prometheus-community
helm upgrade --install monitoring prometheus-community/kube-prometheus-stack \
--namespace $(MON_NAMESPACE) --create-namespace \
-f $(PROM_VALUES) \
--wait --timeout 180s
# Pull pre-built images from Docker Hub (used by default deploy)
pull-images:
docker pull $(REGISTRY)/refapp-gateway:$(IMAGE_TAG)
docker pull $(REGISTRY)/refapp-catalog:$(IMAGE_TAG)
docker pull $(REGISTRY)/refapp-worker:$(IMAGE_TAG)
docker pull $(REGISTRY)/refapp-dashboard:$(IMAGE_TAG)
# Build from source (requires Rust toolchain — takes 5-10 min on first run)
deploy-from-source: cluster db monitoring build load-images app
@echo ""
@echo "=== Deployment Complete (built from source) ==="
@echo "Dashboard: http://localhost:30080"
@echo "Grafana: http://localhost:30090 (admin/admin)"
@echo "Prometheus: http://localhost:30091"
@echo ""
build:
docker build --build-arg GIT_SHA=$(GIT_SHA) \
-f services/api-gateway/Dockerfile \
-t $(REGISTRY)/refapp-gateway:$(IMAGE_TAG) \
-t $(REGISTRY)/refapp-gateway:latest .
docker build --build-arg GIT_SHA=$(GIT_SHA) \
-f services/catalog/Dockerfile \
-t $(REGISTRY)/refapp-catalog:$(IMAGE_TAG) \
-t $(REGISTRY)/refapp-catalog:latest .
docker build --build-arg GIT_SHA=$(GIT_SHA) \
-f services/worker/Dockerfile \
-t $(REGISTRY)/refapp-worker:$(IMAGE_TAG) \
-t $(REGISTRY)/refapp-worker:latest .
docker build \
-t $(REGISTRY)/refapp-dashboard:$(IMAGE_TAG) \
-t $(REGISTRY)/refapp-dashboard:latest \
dashboard/
publish: build
docker push $(REGISTRY)/refapp-gateway:$(IMAGE_TAG)
docker push $(REGISTRY)/refapp-gateway:latest
docker push $(REGISTRY)/refapp-catalog:$(IMAGE_TAG)
docker push $(REGISTRY)/refapp-catalog:latest
docker push $(REGISTRY)/refapp-worker:$(IMAGE_TAG)
docker push $(REGISTRY)/refapp-worker:latest
docker push $(REGISTRY)/refapp-dashboard:$(IMAGE_TAG)
docker push $(REGISTRY)/refapp-dashboard:latest
@echo ""
@echo "=== Published to Docker Hub ==="
@echo "$(REGISTRY)/refapp-gateway:$(IMAGE_TAG)"
@echo "$(REGISTRY)/refapp-catalog:$(IMAGE_TAG)"
@echo "$(REGISTRY)/refapp-worker:$(IMAGE_TAG)"
@echo "$(REGISTRY)/refapp-dashboard:$(IMAGE_TAG)"
load-images:
kind load docker-image $(REGISTRY)/refapp-gateway:$(IMAGE_TAG) --name $(CLUSTER_NAME)
kind load docker-image $(REGISTRY)/refapp-catalog:$(IMAGE_TAG) --name $(CLUSTER_NAME)
kind load docker-image $(REGISTRY)/refapp-worker:$(IMAGE_TAG) --name $(CLUSTER_NAME)
kind load docker-image $(REGISTRY)/refapp-dashboard:$(IMAGE_TAG) --name $(CLUSTER_NAME)
app:
helm upgrade --install reference-app $(HELM_CHART) \
--namespace $(APP_NAMESPACE) --create-namespace \
--wait --timeout 120s
status:
@echo "=== Pods ==="
@kubectl get pods -n $(APP_NAMESPACE) 2>/dev/null || echo "App namespace not found"
@kubectl get pods -n $(DB_NAMESPACE) 2>/dev/null || echo "DB namespace not found"
@kubectl get pods -n $(MON_NAMESPACE) 2>/dev/null || echo "Monitoring namespace not found"
destroy:
kind delete cluster --name $(CLUSTER_NAME)
# --- Docker Compose (no K8s required) ---
# Quick start: pulls pre-built images from Docker Hub
compose-up:
docker compose up -d
@echo ""
@echo "=== Docker Compose Deployment ==="
@echo "Dashboard: http://localhost:3000"
@echo "API Gateway: http://localhost:8080"
@echo "Catalog: http://localhost:8081"
@echo "Worker: http://localhost:8082"
@echo "PostgreSQL: localhost:5432"
@echo ""
@echo "Logs: make compose-logs"
@echo "Stop: make compose-down"
# Build from source, then start
compose-build-up:
GIT_SHA=$(GIT_SHA) \
docker compose -f docker-compose.yml -f docker-compose.build.yml up --build -d
@echo ""
@echo "=== Docker Compose (built from source) ==="
@echo "Dashboard: http://localhost:3000"
@echo "API Gateway: http://localhost:8080"
@echo "Catalog: http://localhost:8081"
@echo "Worker: http://localhost:8082"
@echo ""
@echo "Logs: make compose-logs"
@echo "Stop: make compose-down"
compose-down:
docker compose down
compose-logs:
docker compose logs -f