Test the script
This commit is contained in:
parent
56a850ca50
commit
d4b7d54dd6
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# 📦 Install required tools
|
# 📦 Install required tools (run via Woodpecker .woodpecker.yml)
|
||||||
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..."
|
||||||
@ -20,13 +20,15 @@ ORIGINAL_FILE="$INFRA_CLONE/manifests/cloudflared/values.yaml"
|
|||||||
MERGED_FILE="$INFRA_CLONE/manifests/cloudflared/values.yaml"
|
MERGED_FILE="$INFRA_CLONE/manifests/cloudflared/values.yaml"
|
||||||
|
|
||||||
# === STEP 1: Clone Repos ===
|
# === STEP 1: Clone Repos ===
|
||||||
echo "📦 Cloning sandbox..."
|
echo "📦 Cloning sandbox-apps..."
|
||||||
git clone --depth=1 "$SANDBOX_REPO_URL" "$SANDBOX_CLONE"
|
git clone --depth=1 "$SANDBOX_REPO_URL" "$SANDBOX_CLONE"
|
||||||
|
|
||||||
echo "📦 Cloning infra..."
|
echo "📦 Cloning infra..."
|
||||||
git clone --depth=1 "$INFRA_REPO_URL" "$INFRA_CLONE"
|
git clone --depth=1 "$INFRA_REPO_URL" "$INFRA_CLONE"
|
||||||
|
|
||||||
# === STEP 2: Generate new ingress entries ===
|
ls -l .tmp-repos/
|
||||||
|
|
||||||
|
# === STEP 2: Extract Generated CNAMEs from sandbox ===
|
||||||
echo "⚙️ Generating sandbox ingress list..."
|
echo "⚙️ Generating sandbox ingress list..."
|
||||||
cat <<EOF > "$GENERATED_FILE"
|
cat <<EOF > "$GENERATED_FILE"
|
||||||
ingress: []
|
ingress: []
|
||||||
@ -38,12 +40,11 @@ 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")
|
||||||
port=$(yq '.port // 80' "$cname_file") # default to 80 if not set
|
service="http://${app_name}.sandbox.svc.cluster.local:80"
|
||||||
service="http://${app_name}.sandbox.svc.cluster.local:$port"
|
|
||||||
|
|
||||||
echo "✅ Found $hostname → $service"
|
echo "✅ Found $hostname → $service"
|
||||||
|
|
||||||
# Append to ingress list
|
# Append new entry to generated ingress list
|
||||||
yq eval ".ingress += [{\"hostname\": \"$hostname\", \"service\": \"$service\"}]" -i "$GENERATED_FILE"
|
yq eval ".ingress += [{\"hostname\": \"$hostname\", \"service\": \"$service\"}]" -i "$GENERATED_FILE"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -51,12 +52,15 @@ done
|
|||||||
echo "📄 Generated Ingress:"
|
echo "📄 Generated Ingress:"
|
||||||
cat "$GENERATED_FILE"
|
cat "$GENERATED_FILE"
|
||||||
|
|
||||||
# === STEP 3: Merge ingress only ===
|
# === STEP 3: Merge with existing cloudflared values ===
|
||||||
echo "🔁 Merging ingress into: $ORIGINAL_FILE"
|
echo "🔁 Merging new entries into: $ORIGINAL_FILE"
|
||||||
|
|
||||||
TEMP_FILE=$(mktemp)
|
TEMP_FILE=$(mktemp)
|
||||||
|
|
||||||
|
# Extract original ingress
|
||||||
yq eval '.cloudflare.ingress' "$ORIGINAL_FILE" > "$TEMP_FILE"
|
yq eval '.cloudflare.ingress' "$ORIGINAL_FILE" > "$TEMP_FILE"
|
||||||
|
|
||||||
|
# Append new unique entries
|
||||||
yq eval '.ingress' "$GENERATED_FILE" | yq eval -o=json '.' - | jq -c '.[]' | while read -r new_entry; do
|
yq eval '.ingress' "$GENERATED_FILE" | yq eval -o=json '.' - | jq -c '.[]' | while read -r new_entry; do
|
||||||
hostname=$(echo "$new_entry" | jq -r '.hostname')
|
hostname=$(echo "$new_entry" | jq -r '.hostname')
|
||||||
service=$(echo "$new_entry" | jq -r '.service')
|
service=$(echo "$new_entry" | jq -r '.service')
|
||||||
@ -71,23 +75,26 @@ yq eval '.ingress' "$GENERATED_FILE" | yq eval -o=json '.' - | jq -c '.[]' | whi
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "📝 Writing merged file to $MERGED_FILE"
|
# === STEP 4: Load preserved values ===
|
||||||
|
TUNNEL_NAME=$(yq e '.cloudflare.tunnelName' "$ORIGINAL_FILE")
|
||||||
|
ENABLE_WARP=$(yq e '.cloudflare.enableWarp' "$ORIGINAL_FILE")
|
||||||
|
SECRET_NAME=$(yq e '.cloudflare.secretName' "$ORIGINAL_FILE")
|
||||||
|
CLOUDFLARED_BLOCK=$(yq e '.cloudflared' "$ORIGINAL_FILE")
|
||||||
|
|
||||||
# Merge ingress back into full file, preserving all existing fields
|
# === STEP 5: Write final merged values ===
|
||||||
yq eval-all '
|
echo "📝 Writing merged file to $MERGED_FILE"
|
||||||
select(fileIndex == 0) as $orig |
|
yq eval "
|
||||||
select(fileIndex == 1) as $newIngress |
|
.cloudflare.ingress = load(\"$TEMP_FILE\") |
|
||||||
$orig * {
|
.cloudflare.tunnelName = \"$TUNNEL_NAME\" |
|
||||||
cloudflare: $orig.cloudflare * {
|
.cloudflare.enableWarp = \"$ENABLE_WARP\" |
|
||||||
ingress: $newIngress
|
.cloudflare.secretName = \"$SECRET_NAME\" |
|
||||||
}
|
.cloudflared = $CLOUDFLARED_BLOCK
|
||||||
}
|
" "$ORIGINAL_FILE" > "$MERGED_FILE"
|
||||||
' "$ORIGINAL_FILE" "$TEMP_FILE" > "$MERGED_FILE"
|
|
||||||
|
|
||||||
echo "✅ Final merged values.yaml:"
|
echo "✅ Final merged values.yaml:"
|
||||||
cat "$MERGED_FILE"
|
cat "$MERGED_FILE"
|
||||||
|
|
||||||
# === STEP 4: Git Push ===
|
# === STEP 6: Optional 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