Test the script

This commit is contained in:
dvirlabs 2025-06-22 15:45:35 +03:00
parent 963eeef5d6
commit 69ebd0af10

View File

@ -1,7 +1,7 @@
#!/bin/bash
set -e
# 📦 Install required tools (for debugging / local run)
# 📦 Install required tools (in pipeline step)
apk add --no-cache git bash curl yq jq
echo "🔍 Scanning for apps with cname.yaml..."
@ -28,7 +28,7 @@ git clone --depth=1 "$INFRA_REPO_URL" "$INFRA_CLONE"
ls -l .tmp-repos/
# === STEP 2: Extract Generated CNAMEs from sandbox ===
# === STEP 2: Generate ingress list from sandbox ===
echo "⚙️ Generating sandbox ingress list..."
cat <<EOF > "$GENERATED_FILE"
ingress: []
@ -41,10 +41,7 @@ find "$SANDBOX_CLONE/manifests" -name cname.yaml | while read -r cname_file; do
if [[ "$enabled" == "true" ]]; then
hostname=$(yq '.hostname' "$cname_file")
service="http://${app_name}.sandbox.svc.cluster.local:80"
echo "✅ Found $hostname$service"
# Append new entry
yq eval ".ingress += [{\"hostname\": \"$hostname\", \"service\": \"$service\"}]" -i "$GENERATED_FILE"
fi
done
@ -52,28 +49,26 @@ done
echo "📄 Generated Ingress:"
cat "$GENERATED_FILE"
# === STEP 3: Merge only ingress into existing cloudflared values.yaml ===
# === STEP 3: Merge into cloudflared values.yaml ===
echo "🔁 Merging new entries into: $ORIGINAL_FILE"
yq eval-all '
# File 0 = Original cloudflared values
# File 1 = Generated ingress block
(select(fileIndex == 0) as $orig | select(fileIndex == 1) as $new |
$orig * {
cloudflare: $orig.cloudflare * {
ingress: (
($orig.cloudflare.ingress + $new.ingress)
| unique_by(.hostname)
)
}
select(fileIndex == 0) as $base |
select(fileIndex == 1) as $new |
$base * {
cloudflare: $base.cloudflare * {
ingress: (
($base.cloudflare.ingress + $new.ingress)
| unique_by(.hostname)
)
}
)
}
' "$ORIGINAL_FILE" "$GENERATED_FILE" > "$MERGED_FILE"
echo "✅ Final merged values.yaml:"
cat "$MERGED_FILE"
# === STEP 4: Commit & Push ===
# === STEP 4: Git push ===
echo "📤 Pushing updated values.yaml to infra repo..."
cd "$INFRA_CLONE"