Skip to content

Commit b3ea577

Browse files
committed
fix get licenseid
1 parent eb9a20e commit b3ea577

File tree

2 files changed

+170
-6
lines changed

2 files changed

+170
-6
lines changed

.github/workflows/mlflow-ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,32 @@ jobs:
396396
env:
397397
REPLICATED_API_TOKEN: ${{ secrets.REPLICATED_PLATFORM_EXAMPLES_TOKEN }}
398398

399+
# Verify license file is valid
400+
- name: Verify License File
401+
run: |
402+
# Create a temporary file to check the license
403+
echo "Saving license file for validation..."
404+
LICENSE_FILE="/tmp/replicated/license-ci.yaml"
405+
mkdir -p /tmp/replicated
406+
407+
# Save the license content to a file
408+
cat << 'EOF' > $LICENSE_FILE
409+
${{ steps.download-license.outputs.license }}
410+
EOF
411+
412+
echo "License file content (first 10 lines):"
413+
head -n 10 $LICENSE_FILE
414+
415+
# Check if the license file is valid YAML
416+
echo "Validating license file..."
417+
yq eval . $LICENSE_FILE > /dev/null
418+
if [ $? -ne 0 ]; then
419+
echo "ERROR: License file is not valid YAML"
420+
exit 1
421+
else
422+
echo "✅ License file is valid YAML"
423+
fi
424+
399425
# Install using KOTS
400426
- name: KOTS Install
401427
uses: replicatedhq/replicated-actions/[email protected]
@@ -408,6 +434,8 @@ jobs:
408434
namespace: default
409435
wait-duration: 10m
410436
shared-password: 'replicatedmlflow'
437+
skip-preflights: true
438+
debug: true
411439

412440
# Set up port forwarding after KOTS installation is complete
413441
- name: Set up port forwarding

applications/mlflow/Taskfile.yml

Lines changed: 142 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,28 +316,87 @@ tasks:
316316
# Create a temporary directory for the license if it doesn't exist
317317
mkdir -p /tmp/replicated
318318
OUTPUT_FILE="/tmp/replicated/license-download-output.txt"
319+
LICENSE_FILE="/tmp/replicated/license.yaml"
319320
320-
# Run vendor-cli to download the customer license
321+
# Run vendor-cli to download the customer license to a temporary file first
321322
echo "Running vendor-cli to download license..."
323+
TMP_LICENSE_FILE=$(mktemp)
322324
set +e
323325
docker run --rm \
324326
-e REPLICATED_API_TOKEN=$REPLICATED_API_TOKEN \
325327
-e REPLICATED_APP={{.APP_NAME}} \
326328
replicated/vendor-cli:latest \
327-
customer download-license --customer "{{.CUSTOMER_NAME}}" > /tmp/replicated/license.yaml 2>$OUTPUT_FILE
329+
customer download-license --customer "{{.CUSTOMER_NAME}}" > "$TMP_LICENSE_FILE" 2>$OUTPUT_FILE
328330
DOWNLOAD_EXIT_CODE=$?
329331
set -e
330332
331333
if [ $DOWNLOAD_EXIT_CODE -ne 0 ]; then
332334
echo "ERROR: Failed to download license for customer {{.CUSTOMER_NAME}}"
333335
echo "Error output:"
334336
cat $OUTPUT_FILE
335-
rm -f $OUTPUT_FILE
337+
rm -f $OUTPUT_FILE "$TMP_LICENSE_FILE"
336338
exit 1
337339
fi
338340
339-
echo "License successfully downloaded to /tmp/replicated/license.yaml"
340-
rm -f $OUTPUT_FILE
341+
# Check if the file is empty
342+
if [ ! -s "$TMP_LICENSE_FILE" ]; then
343+
echo "ERROR: Downloaded license file is empty"
344+
cat $OUTPUT_FILE
345+
rm -f $OUTPUT_FILE "$TMP_LICENSE_FILE"
346+
exit 1
347+
fi
348+
349+
# Verify the license file is valid YAML
350+
if command -v yq >/dev/null 2>&1; then
351+
echo "Validating license file is proper YAML..."
352+
if ! yq eval . "$TMP_LICENSE_FILE" > /dev/null 2>&1; then
353+
echo "ERROR: Downloaded license file is not valid YAML"
354+
echo "License file content:"
355+
cat "$TMP_LICENSE_FILE"
356+
rm -f $OUTPUT_FILE "$TMP_LICENSE_FILE"
357+
exit 1
358+
fi
359+
else
360+
echo "WARNING: yq not found, skipping YAML validation"
361+
fi
362+
363+
# Remove any extra output or text before the YAML content
364+
# This extracts content between first '---' and the end of file
365+
if grep -q "^---" "$TMP_LICENSE_FILE"; then
366+
echo "License appears to be in YAML format with document marker, extracting YAML content..."
367+
sed -n '/^---/,$p' "$TMP_LICENSE_FILE" > "$LICENSE_FILE"
368+
else
369+
# If no '---' marker is found, check for '{' to identify JSON
370+
if grep -q "{" "$TMP_LICENSE_FILE"; then
371+
echo "License appears to be in JSON format, converting to YAML..."
372+
if command -v yq >/dev/null 2>&1; then
373+
cat "$TMP_LICENSE_FILE" | yq eval -P > "$LICENSE_FILE"
374+
else
375+
echo "ERROR: Cannot convert JSON to YAML without yq"
376+
cat "$TMP_LICENSE_FILE"
377+
rm -f $OUTPUT_FILE "$TMP_LICENSE_FILE"
378+
exit 1
379+
fi
380+
else
381+
# If neither YAML nor JSON markers are found, just copy the file
382+
echo "No YAML document marker or JSON found. Copying file as-is..."
383+
cat "$TMP_LICENSE_FILE" > "$LICENSE_FILE"
384+
fi
385+
fi
386+
387+
# Log some debug information
388+
echo "License file content (first 5 lines):"
389+
head -n 5 "$LICENSE_FILE"
390+
391+
# Verify file exists and has content
392+
if [ ! -s "$LICENSE_FILE" ]; then
393+
echo "ERROR: Final license file is empty after processing"
394+
rm -f $OUTPUT_FILE "$TMP_LICENSE_FILE"
395+
exit 1
396+
fi
397+
398+
echo "License successfully downloaded to $LICENSE_FILE"
399+
rm -f $OUTPUT_FILE "$TMP_LICENSE_FILE"
341400
342401
# Cleanup tasks
343402
clean:charts:
@@ -427,7 +486,84 @@ tasks:
427486
desc: Run KOTS installation test
428487
deps: [setup:namespaces]
429488
cmds:
430-
- echo "KOTS installation test not yet implemented"
489+
- echo "Running KOTS installation test..."
490+
- |
491+
if [ -z "$REPLICATED_LICENSE_ID" ]; then
492+
echo "ERROR: REPLICATED_LICENSE_ID environment variable must be set"
493+
exit 1
494+
fi
495+
496+
if [ -z "$REPLICATED_APP" ]; then
497+
echo "ERROR: REPLICATED_APP environment variable must be set"
498+
exit 1
499+
fi
500+
501+
if [ -z "$REPLICATED_CHANNEL" ]; then
502+
echo "ERROR: REPLICATED_CHANNEL environment variable must be set"
503+
exit 1
504+
fi
505+
506+
# Create directory for license file if it doesn't exist
507+
mkdir -p /tmp/replicated
508+
LICENSE_FILE="/tmp/replicated/license.yaml"
509+
510+
# Validate license file exists and has content
511+
if [ ! -f "$LICENSE_FILE" ] || [ ! -s "$LICENSE_FILE" ]; then
512+
echo "ERROR: License file does not exist or is empty at $LICENSE_FILE"
513+
echo "Please download the license file using the customer:download-license task first"
514+
exit 1
515+
fi
516+
517+
# Verify license file is valid YAML
518+
if command -v yq >/dev/null 2>&1; then
519+
echo "Validating license file is proper YAML before installation..."
520+
if ! yq eval . "$LICENSE_FILE" > /dev/null 2>&1; then
521+
echo "ERROR: License file is not valid YAML"
522+
echo "License file content:"
523+
cat "$LICENSE_FILE" | head -n 10
524+
exit 1
525+
else
526+
echo "✅ License file is valid YAML"
527+
fi
528+
else
529+
echo "WARNING: yq not found, skipping YAML validation"
530+
fi
531+
532+
echo "Installing latest KOTS version..."
533+
curl https://kots.io/install | bash
534+
535+
echo "License file at $LICENSE_FILE (first 5 lines):"
536+
head -n 5 "$LICENSE_FILE"
537+
538+
echo "Installing application from Replicated..."
539+
echo "App: $REPLICATED_APP"
540+
echo "Channel: $REPLICATED_CHANNEL"
541+
echo "Using license file: $LICENSE_FILE"
542+
543+
# Run KOTS install with detailed output
544+
set -x
545+
kubectl kots install $REPLICATED_APP/$REPLICATED_CHANNEL \
546+
--shared-password=replicatedmlflow \
547+
--license-file="$LICENSE_FILE" \
548+
--namespace=default \
549+
--wait-duration=10m \
550+
--skip-preflights
551+
set +x
552+
553+
# Check if installation succeeded
554+
if [ $? -ne 0 ]; then
555+
echo "❌ KOTS installation failed"
556+
echo "Checking app status:"
557+
kubectl get app -n default
558+
echo "Checking pods:"
559+
kubectl get pods -n default
560+
echo "Checking pod logs:"
561+
kubectl logs -n default -l app=kotsadm --tail=50
562+
exit 1
563+
fi
564+
565+
echo "✅ KOTS installation completed. Setting up port forwarding for testing..."
566+
- task: test:port-forward
431567

432568
test:port-forward:
433569
desc: Setup port forwarding to MLflow service for testing

0 commit comments

Comments
 (0)