forked from dream-horizon-org/darwin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
Β·334 lines (294 loc) Β· 12.7 KB
/
start.sh
File metadata and controls
executable file
Β·334 lines (294 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
#!/bin/sh
set -e
# Get the project root directory (same as setup.sh and start-cluster.sh)
# This ensures config.env is always read from the same location
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$SCRIPT_DIR"
CONFIG_ENV="$PROJECT_ROOT/.setup/config.env"
# Parse command line arguments
CI_TEST=false
while [ $# -gt 0 ]; do
case "$1" in
--ci-test)
CI_TEST=true
shift
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --ci-test CI test mode: uses minimal test configurations"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Deploy Darwin platform normally"
echo " $0 --ci-test # Deploy in CI test mode (only ci-test-service)"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--ci-test] [-h|--help]"
exit 1
;;
esac
done
# Support CI_TEST_MODE environment variable also for backward compatibility
if [ "${CI_TEST_MODE:-}" = "true" ]; then
CI_TEST=true
fi
# Check for init configuration (skip this check in CI_TEST mode)
if [ "$CI_TEST" != "true" ]; then
ENABLED_SERVICES_FILE=".setup/enabled-services.yaml"
if [ ! -f "$ENABLED_SERVICES_FILE" ]; then
echo "β No configuration found at $ENABLED_SERVICES_FILE"
echo " Please run ./init.sh first to configure which services to enable."
exit 1
fi
echo "β
Found configuration: $ENABLED_SERVICES_FILE"
else
# In CI test mode, use test configuration
echo "π¬ CI test mode enabled - using minimal test configuration"
ENABLED_SERVICES_FILE=".github/ci-configs/test-enabled-services.yaml"
fi
# Source the config.env file
if [ ! -f "$CONFIG_ENV" ]; then
echo "β config.env not found at $CONFIG_ENV"
echo " Please run ./setup.sh first to create config.env"
exit 1
fi
set -o allexport
. "$CONFIG_ENV"
set +o allexport
echo "π§ Setting up KUBECONFIG: $KUBECONFIG"
# Verify cluster connectivity
if kubectl version >/dev/null 2>&1; then
echo "β
Cluster is accessible"
kubectl get nodes
else
echo "β Cluster is not reachable. Please run setup.sh first."
exit 1
fi
echo "βοΈ Setting up Kubernetes dependencies..."
./k8s-setup.sh
echo "π Starting Darwin Platform deployment..."
# ============================================================================
# BUILD HELM OVERRIDES FROM CONFIG
# ============================================================================
HELM_OVERRIDES=""
if [ "$CI_TEST" != "true" ]; then
echo "π Reading service configuration..."
# Function to map application name to helm path
get_helm_path() {
local app_name="$1"
case "$app_name" in
"ci-test-service") echo "services.services.ci-test-service.enabled" ;;
"darwin-ofs-v2") echo "services.services.feature-store.enabled" ;;
"darwin-ofs-v2-admin") echo "services.services.feature-store-admin.enabled" ;;
"darwin-ofs-v2-consumer") echo "services.services.feature-store-consumer.enabled" ;;
"darwin-mlflow") echo "services.services.mlflow-lib.enabled" ;;
"darwin-mlflow-app") echo "services.services.mlflow-app.enabled" ;;
"chronos") echo "services.services.chronos.enabled" ;;
"chronos-consumer") echo "services.services.chronos-consumer.enabled" ;;
"darwin-compute") echo "services.services.compute.enabled" ;;
"darwin-cluster-manager") echo "services.services.cluster-manager.enabled" ;;
"darwin-workspace") echo "services.services.workspace.enabled" ;;
"darwin-workflow") echo "services.services.workflow.enabled" ;;
"ml-serve-app") echo "services.services.ml-serve-app.enabled" ;;
"artifact-builder") echo "services.services.artifact-builder.enabled" ;;
"darwin-catalog") echo "services.services.catalog.enabled" ;;
*) echo "" ;;
esac
}
# Read applications from config and build --set flags
echo " Processing applications..."
for app_name in $(yq eval '.applications | keys | .[]' "$ENABLED_SERVICES_FILE"); do
enabled=$(yq eval ".applications.\"$app_name\"" "$ENABLED_SERVICES_FILE")
helm_path=$(get_helm_path "$app_name")
if [ -n "$helm_path" ]; then
HELM_OVERRIDES="$HELM_OVERRIDES --set $helm_path=$enabled"
echo " $app_name -> $helm_path=$enabled"
fi
done
# Read datastores from config and build --set flags (direct mapping)
echo " Processing datastores..."
for ds_name in $(yq eval '.datastores | keys | .[]' "$ENABLED_SERVICES_FILE"); do
enabled=$(yq eval ".datastores.\"$ds_name\"" "$ENABLED_SERVICES_FILE")
# Skip busybox - it's not a helm-managed datastore
if [ "$ds_name" = "busybox" ]; then
continue
fi
helm_path="datastores.$ds_name.enabled"
HELM_OVERRIDES="$HELM_OVERRIDES --set $helm_path=$enabled"
echo " $ds_name -> $helm_path=$enabled"
done
else
echo "π CI test mode: Using test helm values files (no overrides needed)"
fi
echo ""
echo "π¦ Installing Darwin Platform with configuration overrides..."
# Install Darwin Platform umbrella chart with overrides
echo " Deploying helm chart (with --wait for all pods)..."
echo " This may take several minutes..."
if [ "$CI_TEST" = "true" ]; then
# CI test mode: use minimal test values files (no additional overrides)
echo " Using CI test helm values files..."
helm upgrade --install darwin ./helm/darwin \
--namespace darwin \
--create-namespace \
--wait \
--timeout 600s \
-f .github/ci-configs/test-helm-values/services-values.yaml \
-f .github/ci-configs/test-helm-values/datastores-values.yaml
else
# Normal mode: use configuration overrides
helm upgrade --install darwin ./helm/darwin \
--namespace darwin \
--create-namespace \
--wait \
--timeout 600s \
$HELM_OVERRIDES
fi
HELM_EXIT_CODE=$?
if [ $HELM_EXIT_CODE -ne 0 ]; then
echo "β Helm deployment failed with exit code $HELM_EXIT_CODE!"
echo ""
echo "Checking deployment status..."
helm status darwin -n darwin 2>/dev/null || echo " (helm release not found)"
echo ""
echo "Checking pods..."
kubectl get pods -n darwin 2>/dev/null || echo " (no pods found)"
echo ""
echo "Checking helm release history..."
helm history darwin -n darwin 2>/dev/null || echo " (no history found)"
exit 1
fi
echo "β
Helm chart deployed (all pods ready via --wait)"
# ============================================================================
# UPLOAD KUBECONFIG TO S3 (for darwin-cluster-manager)
# ============================================================================
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo " UPLOADING KUBECONFIG TO S3"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Check if both localstack and darwin-cluster-manager are enabled
LOCALSTACK_ENABLED=$(yq eval '.datastores.localstack // false' "$ENABLED_SERVICES_FILE")
CLUSTER_MANAGER_ENABLED=$(yq eval '.applications.darwin-cluster-manager // false' "$ENABLED_SERVICES_FILE")
if [ "$LOCALSTACK_ENABLED" = "true" ] && [ "$CLUSTER_MANAGER_ENABLED" = "true" ]; then
if [ -f "$KUBECONFIG" ]; then
echo "π¦ Uploading kubeconfig to S3 for darwin-cluster-manager..."
# Create a temporary file with the server address updated for in-cluster use
KUBECONFIG_TEMP=$(mktemp)
cp "$KUBECONFIG" "$KUBECONFIG_TEMP"
# Update the server address to use in-cluster DNS name
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' 's|server: https://127\.0\.0\.1:[0-9]*|server: https://kubernetes.default.svc|' "$KUBECONFIG_TEMP"
else
sed -i 's|server: https://127\.0\.0\.1:[0-9]*|server: https://kubernetes.default.svc|' "$KUBECONFIG_TEMP"
fi
# Wait for LocalStack to be accessible via port-forward
echo " Setting up port-forward to LocalStack..."
kubectl port-forward svc/darwin-localstack -n darwin 4566:4566 &
PF_PID=$!
sleep 3
# Upload to S3 using AWS CLI
set +e
AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test aws s3 \
--endpoint-url=http://localhost:4566 \
cp "$KUBECONFIG_TEMP" s3://darwin/mlp/cluster_manager/configs/kind 2>&1
UPLOAD_EXIT_CODE=$?
set -e
# Cleanup
kill $PF_PID 2>/dev/null || true
rm -f "$KUBECONFIG_TEMP"
if [ $UPLOAD_EXIT_CODE -eq 0 ]; then
echo "β
Kubeconfig uploaded to S3 successfully"
else
echo "β Failed to upload kubeconfig to S3 (exit code: $UPLOAD_EXIT_CODE)"
echo "β οΈ darwin-cluster-manager may not be able to access kubeconfig"
fi
else
echo "β οΈ Kubeconfig not found at $KUBECONFIG"
echo " darwin-cluster-manager may not work correctly"
fi
else
if [ "$LOCALSTACK_ENABLED" != "true" ]; then
echo "βοΈ Skipping kubeconfig upload (LocalStack disabled)"
else
echo "βοΈ Skipping kubeconfig upload (darwin-cluster-manager disabled)"
fi
fi
echo "β
Deployment completed!"
# ============================================================================
# REGISTER DARWIN SDK RUNTIME
# ============================================================================
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo " REGISTERING DARWIN SDK RUNTIME"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Check if BOTH darwin-sdk-runtime AND darwin-compute are enabled
SDK_ENABLED=$(yq eval '.darwin-sdk-runtime.enabled // false' "$ENABLED_SERVICES_FILE")
COMPUTE_ENABLED=$(yq eval '.applications.darwin-compute // false' "$ENABLED_SERVICES_FILE")
if [ "$SDK_ENABLED" = "true" ] && [ "$COMPUTE_ENABLED" = "true" ]; then
echo "π¦ Registering darwin-sdk runtime as '1.0'..."
# Wait for darwin-compute to be ready via ingress
echo " Waiting for darwin-compute to be ready..."
sleep 5
# Register the runtime via ingress (localhost/compute)
# Add timeout to prevent hanging in CI
set +e
RESPONSE=$(curl -s --max-time 30 -X POST http://localhost/compute/runtime/v2/create \
-H "Content-Type: application/json" \
-d '{
"runtime": "1.0",
"class": "CPU",
"type": "Ray and Spark",
"image": "localhost:5000/ray:2.37.0-darwin-sdk",
"user": "Darwin",
"spark_connect": false,
"spark_auto_init": true
}' 2>&1)
CURL_EXIT_CODE=$?
set -e
# Check response
if [ $CURL_EXIT_CODE -eq 0 ] && echo "$RESPONSE" | grep -q '"status":"SUCCESS"'; then
echo " β
Darwin SDK runtime '1.0' registered successfully"
else
echo " β οΈ Runtime registration failed or incomplete (curl exit: $CURL_EXIT_CODE)"
echo " β οΈ Response: $RESPONSE"
echo " β οΈ This is non-critical, continuing..."
fi
elif [ "$SDK_ENABLED" != "true" ]; then
echo "βοΈ Skipping darwin-sdk runtime registration (darwin-sdk-runtime disabled)"
else
echo "βοΈ Skipping darwin-sdk runtime registration (darwin-compute disabled)"
fi
# Show darwin-cli activation reminder if it was installed
DARWIN_CLI_ENABLED=$(yq eval '.cli-tools.darwin-cli // false' "$ENABLED_SERVICES_FILE" 2>/dev/null || echo "false")
if [ "$DARWIN_CLI_ENABLED" = "true" ]; then
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo " DARWIN CLI"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
echo " darwin-cli was installed during setup.sh"
echo ""
echo " To activate and use darwin-cli:"
echo ""
echo " 1. Activate the virtual environment:"
echo " source .venv/bin/activate"
echo ""
echo " 2. Configure the environment (first time only):"
echo " darwin config set --env darwin-local"
echo ""
echo " 3. Verify installation:"
echo " darwin --help"
echo ""
echo " Example commands:"
echo " darwin compute list"
echo " darwin workflow list"
echo " darwin serve list"
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
fi