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