-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·358 lines (321 loc) · 12.7 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·358 lines (321 loc) · 12.7 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
#!/usr/bin/env bash
# Sets up the full local dev environment on a kind cluster.
# Assumes: kind cluster is running, kubectl context points to it.
set -euo pipefail
SKIP_TRINO=false
SKIP_GARAGE=false
for arg in "$@"; do
case "$arg" in
--skip-trino) SKIP_TRINO=true ;;
--skip-garage) SKIP_GARAGE=true ;;
*) echo "Unknown argument: $arg"; echo "Usage: $0 [--skip-trino] [--skip-garage]"; exit 1 ;;
esac
done
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
ENV_FILE="$PROJECT_DIR/.env.development"
echo "=== Stackable Cockpit dev environment setup ==="
if [[ "$SKIP_TRINO" == true ]]; then
echo "(Trino deployment skipped via --skip-trino)"
fi
if [[ "$SKIP_GARAGE" == true ]]; then
echo "(Garage deployment skipped via --skip-garage)"
fi
echo ""
# ------------------------------------------------------------------
# 1. Install npm dependencies if needed
# ------------------------------------------------------------------
if [ ! -d "$PROJECT_DIR/node_modules" ]; then
echo "Installing npm dependencies..."
(cd "$PROJECT_DIR" && npm install)
else
echo "npm dependencies already installed, skipping."
fi
# ------------------------------------------------------------------
# 2. Install Stackable operators
# ------------------------------------------------------------------
echo ""
if [[ "$SKIP_TRINO" == true ]]; then
echo "Installing Stackable operators (commons, listener, secret)..."
stackablectl operator install commons listener secret
else
echo "Installing Stackable operators (commons, listener, secret, trino)..."
stackablectl operator install commons listener secret trino
fi
# ------------------------------------------------------------------
# 3. Deploy Keycloak
# ------------------------------------------------------------------
echo ""
echo "Deploying Keycloak..."
kubectl apply -f "$SCRIPT_DIR/keycloak.yaml"
# ------------------------------------------------------------------
# 4. Wait for Keycloak and configure realm/client/users
# ------------------------------------------------------------------
echo ""
echo "Waiting for Keycloak deployment to be available..."
kubectl wait --for=condition=available deployment/keycloak --timeout=120s
POD=$(kubectl get pod -l app=keycloak -o jsonpath='{.items[0].metadata.name}')
NODE_IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')
if [ -z "$NODE_IP" ]; then
echo "ERROR: Could not detect kind node IP."
exit 1
fi
echo "Node IP: $NODE_IP"
# ------------------------------------------------------------------
# 5. Deploy Trino (after node IP is known, trino.yaml is a template)
# ------------------------------------------------------------------
if [[ "$SKIP_TRINO" == false ]]; then
echo ""
echo "Deploying Trino..."
sed "s/\${NODE_IP}/$NODE_IP/g" "$SCRIPT_DIR/trino.yaml" | kubectl apply -f -
fi
# ------------------------------------------------------------------
# 5b. Deploy Garage S3 (via Helm)
# ------------------------------------------------------------------
if [[ "$SKIP_GARAGE" == false ]]; then
echo ""
echo "Deploying Garage S3..."
helm upgrade --install garage "$SCRIPT_DIR/garage" \
--namespace default \
--wait \
--timeout 60s
fi
# On some local Kubernetes distributions (e.g. Rancher Desktop k3s), the node's
# InternalIP is not reachable from the host network, but NodePorts are exposed
# on localhost. Probe both and use the first reachable URL.
KEYCLOAK_BASE_URL=""
deadline=$(( $(date +%s) + 120 ))
while [ -z "$KEYCLOAK_BASE_URL" ] && [ "$(date +%s)" -lt "$deadline" ]; do
for base in "http://${NODE_IP}:30080" "http://127.0.0.1:30080" "http://localhost:30080"; do
if curl -sf --max-time 2 "${base}/realms/master" >/dev/null 2>&1; then
KEYCLOAK_BASE_URL="$base"
break
fi
done
[ -z "$KEYCLOAK_BASE_URL" ] && sleep 2
done
if [ -z "$KEYCLOAK_BASE_URL" ]; then
echo "ERROR: Could not reach Keycloak via NodePort 30080 within 120s."
echo "Tried: http://${NODE_IP}:30080, http://127.0.0.1:30080, http://localhost:30080"
exit 1
fi
echo "Keycloak URL: ${KEYCLOAK_BASE_URL}"
echo "Waiting for Keycloak to accept connections"
until curl -sf "${KEYCLOAK_BASE_URL}/realms/master" >/dev/null 2>&1; do
sleep 2
done
kcadm() {
kubectl exec "$POD" -- /opt/keycloak/bin/kcadm.sh "$@"
}
# Check if realm already exists
if kcadm get realms/stackable --fields realm 2>/dev/null | grep -q '"stackable"'; then
echo "Realm 'stackable' already exists, skipping Keycloak configuration."
# Still need to fetch the client secret
CLIENT_UUID=$(kcadm get clients -r stackable --fields id,clientId \
| grep -B1 '"stackable-cockpit"' | grep '"id"' | sed 's/.*: *"\(.*\)".*/\1/')
SECRET=$(kcadm get clients/"$CLIENT_UUID"/client-secret -r stackable --fields value \
| grep '"value"' | sed 's/.*: *"\(.*\)".*/\1/')
else
echo "Logging into Keycloak admin CLI..."
kcadm config credentials \
--server http://localhost:8080 \
--realm master \
--user admin \
--password admin
echo "Creating realm 'stackable'..."
kcadm create realms \
-s realm=stackable \
-s enabled=true
echo "Creating client 'stackable-cockpit'..."
CLIENT_UUID=$(kcadm create clients \
-r stackable \
-s clientId=stackable-cockpit \
-s enabled=true \
-s protocol=openid-connect \
-s publicClient=false \
-s standardFlowEnabled=true \
-s directAccessGrantsEnabled=false \
-s 'redirectUris=["*"]' \
-s 'webOrigins=["*"]' \
-i)
echo "Creating client 'trino'..."
kcadm create clients \
-r stackable \
-s clientId=trino \
-s enabled=true \
-s protocol=openid-connect \
-s publicClient=false \
-s standardFlowEnabled=true \
-s directAccessGrantsEnabled=false \
-s secret=trino-oidc-dev \
-s 'redirectUris=["*"]' \
-s 'webOrigins=["*"]'
create_user() {
local username=$1 password=$2 first=$3 last=$4
echo "Creating user '$username'..."
kcadm create users \
-r stackable \
-s username="$username" \
-s email="$username@example.com" \
-s firstName="$first" \
-s lastName="$last" \
-s enabled=true
kcadm set-password \
-r stackable \
--username "$username" \
--new-password "$password"
}
create_user alice alicealice Alice Example
create_user bob bobbob Bob Example
echo "Fetching client secret..."
SECRET=$(kcadm get clients/"$CLIENT_UUID"/client-secret -r stackable --fields value \
| grep '"value"' | sed 's/.*: *"\(.*\)".*/\1/')
fi
# ------------------------------------------------------------------
# 7. Initialise Garage S3 (create bucket + access key, write s3-config.json)
# ------------------------------------------------------------------
if [[ "$SKIP_GARAGE" == false ]]; then
echo ""
echo "Initialising Garage S3..."
GARAGE_ADMIN_PORT=30902
GARAGE_S3_PORT=30900
GARAGE_BASE_URL=""
deadline=$(( $(date +%s) + 60 ))
while [ -z "$GARAGE_BASE_URL" ] && [ "$(date +%s)" -lt "$deadline" ]; do
for base in "http://${NODE_IP}:${GARAGE_ADMIN_PORT}" "http://127.0.0.1:${GARAGE_ADMIN_PORT}" "http://localhost:${GARAGE_ADMIN_PORT}"; do
if curl -sf --max-time 2 -H "Authorization: Bearer stackable-cockpit-e2e-admin-token" "${base}/v2/ListBuckets" >/dev/null 2>&1; then
GARAGE_BASE_URL="$base"
break
fi
done
[ -z "$GARAGE_BASE_URL" ] && sleep 2
done
if [ -z "$GARAGE_BASE_URL" ]; then
echo "ERROR: Could not reach Garage admin API via NodePort ${GARAGE_ADMIN_PORT} within 60s."
echo "Tried: http://${NODE_IP}:${GARAGE_ADMIN_PORT}, http://127.0.0.1:${GARAGE_ADMIN_PORT}, http://localhost:${GARAGE_ADMIN_PORT}"
exit 1
fi
# Derive the matching S3 base URL from the same host
GARAGE_HOST=$(echo "$GARAGE_BASE_URL" | sed 's|http://||; s|:[0-9]*$||')
GARAGE_S3_URL="http://${GARAGE_HOST}:${GARAGE_S3_PORT}"
S3_SECRET_ACCESS_KEY=$(openssl rand -hex 32) \
GARAGE_ADMIN_TOKEN=stackable-cockpit-e2e-admin-token \
S3_ENDPOINT="$GARAGE_S3_URL" \
GARAGE_ADMIN_URL="$GARAGE_BASE_URL" \
S3_CONFIG_PATH="$PROJECT_DIR/s3-config.json" \
"$SCRIPT_DIR/../e2e/init-garage-s3.sh"
echo "Wrote s3-config.json (S3 endpoint: ${GARAGE_S3_URL})"
fi
# ------------------------------------------------------------------
# 8. Write .env.development
# ------------------------------------------------------------------
echo ""
SESSION_SECRET=$(openssl rand -hex 32)
if [ -f "$ENV_FILE" ]; then
echo "Backing up existing .env.development to .env.development.bak"
cp "$ENV_FILE" "$ENV_FILE.bak"
fi
if [[ "$SKIP_TRINO" == false ]]; then
TRINO_PORT=$(kubectl get svc trino-coordinator -o jsonpath='{.spec.ports[0].nodePort}')
# Probe Trino reachability the same way we did for Keycloak.
TRINO_BASE_URL=""
for base in "https://${NODE_IP}:${TRINO_PORT}" "https://127.0.0.1:${TRINO_PORT}" "https://localhost:${TRINO_PORT}"; do
if curl -sfk --max-time 2 "${base}/v1/info" >/dev/null 2>&1; then
TRINO_BASE_URL="$base"
break
fi
done
# Fall back to NODE_IP if none respond yet (Trino may still be starting).
TRINO_BASE_URL="${TRINO_BASE_URL:-https://${NODE_IP}:${TRINO_PORT}}"
fi
if [[ "$SKIP_TRINO" == false ]]; then
cat > "$ENV_FILE" <<EOF
STACKABLE_COCKPIT_OIDC_DISCOVERY_URL=${KEYCLOAK_BASE_URL}/realms/stackable/.well-known/openid-configuration
STACKABLE_COCKPIT_OIDC_CLIENT_ID=stackable-cockpit
STACKABLE_COCKPIT_OIDC_CLIENT_SECRET=${SECRET}
STACKABLE_COCKPIT_SESSION_SECRET=${SESSION_SECRET}
STACKABLE_COCKPIT_BASE_URL=http://localhost:5173
STACKABLE_COCKPIT_TRINO_URL=${TRINO_BASE_URL}
STACKABLE_COCKPIT_TRINO_AUTH_TYPE=basic
STACKABLE_COCKPIT_TRINO_AUTH_USERNAME=stackable-cockpit
STACKABLE_COCKPIT_TRINO_AUTH_PASSWORD=stackable-cockpit-dev
STACKABLE_COCKPIT_TRINO_TLS_INSECURE=true
STACKABLE_COCKPIT_STORAGE_BROWSER_ENABLED=true
STACKABLE_COCKPIT_TEXT_PREVIEW_BYTES=262144
STACKABLE_COCKPIT_IMAGE_PREVIEW_BYTES=5242880
STACKABLE_COCKPIT_PDF_PREVIEW_BYTES=26214400
STACKABLE_COCKPIT_FILE_PREVIEW_ROWS=250
STACKABLE_COCKPIT_FILE_PREVIEW_COLUMNS=50
PUBLIC_STACKABLE_COCKPIT_STORAGE_AUTO_CONNECT=true
PUBLIC_STACKABLE_COCKPIT_PAGE_SIZES=25,50,100
PUBLIC_STACKABLE_COCKPIT_DEFAULT_PAGE_SIZE=25
PUBLIC_STACKABLE_COCKPIT_MAX_RECENT_FILES=15
PUBLIC_STACKABLE_COCKPIT_UPLOAD_CONCURRENCY=3
EOF
else
cat > "$ENV_FILE" <<EOF
STACKABLE_COCKPIT_OIDC_DISCOVERY_URL=${KEYCLOAK_BASE_URL}/realms/stackable/.well-known/openid-configuration
STACKABLE_COCKPIT_OIDC_CLIENT_ID=stackable-cockpit
STACKABLE_COCKPIT_OIDC_CLIENT_SECRET=${SECRET}
STACKABLE_COCKPIT_SESSION_SECRET=${SESSION_SECRET}
STACKABLE_COCKPIT_BASE_URL=http://localhost:5173
STACKABLE_COCKPIT_STORAGE_BROWSER_ENABLED=true
STACKABLE_COCKPIT_TEXT_PREVIEW_BYTES=262144
STACKABLE_COCKPIT_IMAGE_PREVIEW_BYTES=5242880
STACKABLE_COCKPIT_PDF_PREVIEW_BYTES=26214400
STACKABLE_COCKPIT_FILE_PREVIEW_ROWS=250
STACKABLE_COCKPIT_FILE_PREVIEW_COLUMNS=50
PUBLIC_STACKABLE_COCKPIT_STORAGE_AUTO_CONNECT=true
PUBLIC_STACKABLE_COCKPIT_PAGE_SIZES=25,50,100
PUBLIC_STACKABLE_COCKPIT_DEFAULT_PAGE_SIZE=25
PUBLIC_STACKABLE_COCKPIT_MAX_RECENT_FILES=15
PUBLIC_STACKABLE_COCKPIT_UPLOAD_CONCURRENCY=3
EOF
fi
echo "Wrote $ENV_FILE"
# ------------------------------------------------------------------
# 9. Create Kubernetes Secret for the Helm chart
# ------------------------------------------------------------------
echo ""
echo "Creating stackable-cockpit-credentials Secret..."
kubectl delete secret stackable-cockpit-credentials --ignore-not-found
kubectl create secret generic stackable-cockpit-credentials \
--from-literal=oidc-client-secret="$SECRET" \
--from-literal=trino-auth-password=stackable-cockpit-dev
# ------------------------------------------------------------------
# 10. Wait for Trino to be ready
# ------------------------------------------------------------------
if [[ "$SKIP_TRINO" == false ]]; then
echo ""
echo "Waiting for Trino to be ready..."
kubectl rollout status statefulset/trino-coordinator-default --timeout=300s
echo "Trino endpoint: https://${NODE_IP}:${TRINO_PORT}"
fi
# ------------------------------------------------------------------
# Done
# ------------------------------------------------------------------
echo ""
echo "=== Setup complete ==="
echo ""
echo "Start the dev server with: npm run dev"
echo ""
echo "Keycloak: http://${NODE_IP}:30080"
echo " Admin: admin / admin"
echo ""
if [[ "$SKIP_TRINO" == false ]]; then
echo "Trino endpoint: https://${NODE_IP}:${TRINO_PORT}"
echo ""
echo "Trino connection is pre-configured via STACKABLE_COCKPIT_TRINO_* env vars."
echo ""
else
echo "Trino was skipped. Add STACKABLE_COCKPIT_TRINO_* vars to $ENV_FILE manually when ready."
echo ""
fi
if [[ "$SKIP_GARAGE" == false ]]; then
echo "Garage S3: http://${NODE_IP}:30900 (admin: http://${NODE_IP}:30902)"
echo " Credentials written to s3-config.json for E2E tests."
echo ""
fi
echo "Test users (OIDC):"
echo " alice / alicealice"
echo " bob / bobbob"