-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
289 lines (245 loc) · 12.6 KB
/
Copy pathdocker-compose.yml
File metadata and controls
289 lines (245 loc) · 12.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
###############################################################################
# Multi-Version Microservice Demo — Full Kubernetes (MicroShift)
#
# One command brings up MicroShift, builds Java images, loads them into the
# cluster, and deploys Kafka + MongoDB + Schema Registry + Dapr + versioned
# consumer services — all as native Kubernetes pods.
#
# Usage:
# docker compose up --detach
# export KUBECONFIG=$(pwd)/microshift-docker-compose/kubeconfig
# kubectl -n versioned-demo get pods # check status
# kubectl -n versioned-demo logs -l app=producer -f # watch producer
# docker compose down -v # full teardown
#
# Standalone (no K8s, pure Docker):
# docker compose -f docker-compose.standalone.yml up --build
###############################################################################
# Include the MicroShift submodule's compose file, which provides:
# lvm-setup, microshift, kubeconfig, cluster-setup, openshift-console
# volumes: microshift-data, console-data
include:
- path: ./microshift-docker-compose/docker-compose.yml
services:
# =========================================================================
# Override MicroShift: more memory + dashboard NodePort
# =========================================================================
microshift:
mem_limit: 16g
memswap_limit: 16g
ports:
- "6443:6443"
- "9000:9000"
- "30501:30501" # NodePort for dashboard (http://localhost:30501)
# =========================================================================
# Phase 1: Build custom Java images and load into MicroShift's CRI-O
# =========================================================================
image-builder:
image: docker:27-cli
container_name: demo-image-builder
depends_on:
microshift:
condition: service_healthy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./producer:/workspace/producer:ro
- ./consumer-service:/workspace/consumer-service:ro
- ./dashboard:/workspace/dashboard:ro
- ./lattice:/workspace/lattice:ro
entrypoint: /bin/sh
command:
- -c
- |
set -e
echo "============================================"
echo " Phase 1: Building & loading images"
echo "============================================"
echo ""
echo "--- Building document-producer ---"
docker build -t document-producer:latest /workspace/producer
echo ""
echo "--- Building document-consumer ---"
docker build -t document-consumer:latest /workspace/consumer-service
echo ""
echo "--- Building dashboard ---"
docker build -t demo-dashboard:latest /workspace/dashboard
echo ""
echo "--- Pre-pulling infrastructure images ---"
docker pull confluentinc/cp-zookeeper:7.5.0
docker pull confluentinc/cp-kafka:7.5.0
docker pull confluentinc/cp-schema-registry:7.5.0
docker pull mongo:7.0
docker pull daprio/placement:1.12.4
docker pull daprio/daprd:1.12.4
docker pull provectuslabs/kafka-ui:latest
echo ""
echo "--- Loading ALL images into MicroShift (podman -> CRI-O) ---"
for img in \
document-producer:latest \
document-consumer:latest \
demo-dashboard:latest \
confluentinc/cp-zookeeper:7.5.0 \
confluentinc/cp-kafka:7.5.0 \
confluentinc/cp-schema-registry:7.5.0 \
mongo:7.0 \
daprio/placement:1.12.4 \
daprio/daprd:1.12.4 \
provectuslabs/kafka-ui:latest; do
echo " Loading $$img..."
docker save "$$img" | docker exec -i microshift podman load
done
echo ""
echo "--- Building & loading lattice-functions ---"
docker build -t dev.local/lattice-functions:v1 /workspace/lattice/functions
docker save dev.local/lattice-functions:v1 | docker exec -i microshift podman load
echo ""
echo "--- Verifying images in MicroShift ---"
docker exec microshift crictl images | grep -E "document|confluent|mongo|dapr|kafka-ui"
echo ""
echo "Phase 1 complete."
# =========================================================================
# Phase 2: Deploy everything to the MicroShift Kubernetes cluster
# =========================================================================
cluster-deploy:
image: bitnami/kubectl:latest
container_name: demo-cluster-deploy
user: "0:0"
depends_on:
image-builder:
condition: service_completed_successfully
volumes:
- microshift-data:/var/lib/microshift:ro
- ./k8s:/k8s:ro
entrypoint: /bin/sh
command:
- -c
- |
set -e
export KUBECONFIG=/var/lib/microshift/resources/kubeadmin/microshift/kubeconfig
echo "============================================"
echo " Phase 2: Deploying to MicroShift"
echo "============================================"
# Wait for the API server to be fully responsive (not just kubeconfig file existing)
echo ""
echo "[0/6] Waiting for API server..."
for i in $$(seq 1 30); do
if kubectl get nodes >/dev/null 2>&1; then
echo "API server ready."
break
fi
echo " Attempt $$i/30 - API server not ready yet, waiting 10s..."
sleep 10
done
kubectl get nodes
# --- Namespace (with permissive pod security for demo) ---
echo ""
echo "[1/6] Creating namespace and configuring security..."
kubectl apply -f /k8s/namespace.yaml
kubectl label namespace versioned-demo \
pod-security.kubernetes.io/enforce=privileged \
pod-security.kubernetes.io/warn=privileged \
--overwrite
# Grant the default SA the privileged SCC so infrastructure images
# (Confluent, Mongo) can run as root or their expected UIDs
echo "Binding privileged SCC to default service account..."
kubectl patch scc privileged --type='json' \
-p='[{"op":"add","path":"/users/-","value":"system:serviceaccount:versioned-demo:default"}]' 2>/dev/null || true
kubectl patch scc anyuid --type='json' \
-p='[{"op":"add","path":"/users/-","value":"system:serviceaccount:versioned-demo:default"}]' 2>/dev/null || true
# Brief pause for SCC admission cache to update
sleep 5
# --- Dapr placement service + component ConfigMap ---
echo ""
echo "[2/6] Deploying Dapr placement service..."
kubectl apply -f /k8s/dapr/
# --- Infrastructure (Kafka + ZooKeeper + Schema Registry + MongoDB) ---
echo ""
echo "[3/6] Deploying infrastructure..."
kubectl apply -f /k8s/infrastructure/
echo "Waiting for ZooKeeper..."
kubectl -n versioned-demo wait --for=condition=available deployment/zookeeper --timeout=600s
echo "Waiting for Kafka..."
kubectl -n versioned-demo wait --for=condition=available deployment/kafka --timeout=600s
echo "Waiting for Schema Registry..."
kubectl -n versioned-demo wait --for=condition=available deployment/schema-registry --timeout=600s
echo "Waiting for MongoDB..."
kubectl -n versioned-demo wait --for=condition=available deployment/mongodb --timeout=600s
echo "Infrastructure ready."
# --- Producer ---
echo ""
echo "[4/6] Deploying producer..."
kubectl apply -f /k8s/services/producer.yaml
# --- Consumer (handles all schema versions) ---
echo ""
echo "[5/7] Deploying consumer (handles all schema versions)..."
kubectl apply -f /k8s/services/consumer.yaml
# --- Dashboard ---
echo ""
echo "[6/7] Deploying dashboard..."
kubectl apply -f /k8s/services/dashboard.yaml
# --- Wait for everything ---
echo ""
echo "[7/7] Waiting for all services to be ready..."
kubectl -n versioned-demo wait --for=condition=available deployment/producer --timeout=300s
kubectl -n versioned-demo wait --for=condition=available deployment/consumer --timeout=300s
kubectl -n versioned-demo wait --for=condition=available deployment/dashboard --timeout=300s
# --- Knative Serving + Kourier + Eventing + Kafka Broker (v1.22) ---
echo ""
echo "[8/9] Installing Knative..."
# SCC: kourier gateway (runAsUser 65534) and kafka data plane
# (runAsUser 1001) use fixed non-root UIDs outside restricted-v2's
# namespace UID range; nonroot-v2 allows any non-root UID.
kubectl patch scc nonroot-v2 --type=json \
-p='[{"op":"add","path":"/users/-","value":"system:serviceaccount:kourier-system:default"}]' 2>/dev/null || true
kubectl patch scc nonroot-v2 --type=json \
-p='[{"op":"add","path":"/users/-","value":"system:serviceaccount:knative-eventing:knative-kafka-broker-data-plane"}]' 2>/dev/null || true
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.22.1/serving-crds.yaml
kubectl wait --for=condition=Established crd/services.serving.knative.dev --timeout=120s
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.22.1/serving-core.yaml
kubectl apply -f https://github.com/knative-extensions/net-kourier/releases/download/knative-v1.22.1/kourier.yaml
kubectl patch configmap/config-network -n knative-serving --type merge \
-p '{"data":{"ingress-class":"kourier.ingress.networking.knative.dev"}}'
kubectl patch configmap/config-deployment -n knative-serving --type merge \
-p '{"data":{"registries-skipping-tag-resolving":"dev.local"}}'
kubectl patch configmap/config-domain -n knative-serving --type merge \
-p '{"data":{"svc.cluster.local":""}}'
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.22.2/eventing-crds.yaml
kubectl wait --for=condition=Established crd/brokers.eventing.knative.dev --timeout=120s
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.22.2/eventing-core.yaml
kubectl apply -f https://github.com/knative-extensions/eventing-kafka-broker/releases/download/knative-v1.22.2/eventing-kafka-controller.yaml
kubectl apply -f https://github.com/knative-extensions/eventing-kafka-broker/releases/download/knative-v1.22.2/eventing-kafka-broker.yaml
echo "Waiting for Knative deployments..."
kubectl -n knative-serving wait --for=condition=available deployment --all --timeout=600s
kubectl -n kourier-system wait --for=condition=available deployment --all --timeout=600s
kubectl -n knative-eventing wait --for=condition=available deployment --all --timeout=600s
# --- Lattice demo (manifests owned by lattice track) ---
echo ""
echo "[9/9] Deploying lattice demo..."
# Staged apply: one kubectl apply can only create ONE ksvc revision,
# so v1 templates go first (wait Ready), then v2 templates + traffic
# split, then triggers. File order/names are load-bearing.
kubectl apply -f /k8s/lattice/00-namespace.yaml
kubectl apply -f /k8s/lattice/01-broker-config.yaml
kubectl apply -f /k8s/lattice/02-broker.yaml
kubectl -n lattice-demo wait --for=condition=Ready broker/lattice --timeout=300s
kubectl apply -f /k8s/lattice/10-order-gen-v1.yaml
kubectl apply -f /k8s/lattice/20-enricher-v1.yaml
kubectl apply -f /k8s/lattice/30-archiver.yaml
kubectl -n lattice-demo wait --for=condition=Ready ksvc/order-gen ksvc/enricher ksvc/archiver --timeout=300s
kubectl apply -f /k8s/lattice/11-order-gen-v2.yaml
kubectl apply -f /k8s/lattice/21-enricher-v2.yaml
kubectl -n lattice-demo wait --for=condition=Ready ksvc/order-gen ksvc/enricher --timeout=300s
kubectl apply -f /k8s/lattice/40-triggers.yaml
kubectl apply -f /k8s/lattice/dashboard-rbac.yaml
kubectl -n lattice-demo wait --for=condition=Ready trigger --all --timeout=300s
echo ""
echo "============================================"
echo " All services deployed successfully!"
echo "============================================"
echo ""
kubectl -n versioned-demo get pods
echo ""
echo "To watch logs:"
echo " export KUBECONFIG=\$$(pwd)/microshift-docker-compose/kubeconfig"
echo " kubectl -n versioned-demo logs -l app=producer -f"
echo " kubectl -n versioned-demo logs -l app=consumer -f"