Fix script to append and not override
This commit is contained in:
parent
42dcc0b049
commit
40323a744b
@ -2,8 +2,6 @@
|
||||
set -e
|
||||
|
||||
# 📦 Install required tools (run via Woodpecker .woodpecker.yml)
|
||||
# Ensure apk installs: yq, jq, git, bash, curl
|
||||
|
||||
apk add --no-cache git bash curl yq jq
|
||||
|
||||
echo "🔍 Scanning for apps with cname.yaml..."
|
||||
@ -59,10 +57,10 @@ echo "🔁 Merging new entries into: $ORIGINAL_FILE"
|
||||
|
||||
TEMP_FILE=$(mktemp)
|
||||
|
||||
# Copy original ingress list
|
||||
# Extract original ingress
|
||||
yq eval '.cloudflare.ingress' "$ORIGINAL_FILE" > "$TEMP_FILE"
|
||||
|
||||
# Append new unique entries (skip existing hostnames)
|
||||
# Append new unique entries
|
||||
yq eval '.ingress' "$GENERATED_FILE" | yq eval -o=json '.' - | jq -c '.[]' | while read -r new_entry; do
|
||||
hostname=$(echo "$new_entry" | jq -r '.hostname')
|
||||
service=$(echo "$new_entry" | jq -r '.service')
|
||||
@ -77,19 +75,26 @@ yq eval '.ingress' "$GENERATED_FILE" | yq eval -o=json '.' - | jq -c '.[]' | whi
|
||||
fi
|
||||
done
|
||||
|
||||
# === STEP 4: Write merged file ===
|
||||
yq eval '
|
||||
.cloudflare.ingress = load("'"$TEMP_FILE"'") |
|
||||
.cloudflare.tunnelName = .cloudflare.tunnelName |
|
||||
.cloudflare.enableWarp = .cloudflare.enableWarp |
|
||||
.cloudflare.secretName = .cloudflare.secretName |
|
||||
.cloudflared = .cloudflared
|
||||
' "$ORIGINAL_FILE" > "$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")
|
||||
|
||||
# === STEP 5: Write final merged values ===
|
||||
echo "📝 Writing merged file to $MERGED_FILE"
|
||||
yq eval "
|
||||
.cloudflare.ingress = load(\"$TEMP_FILE\") |
|
||||
.cloudflare.tunnelName = \"$TUNNEL_NAME\" |
|
||||
.cloudflare.enableWarp = \"$ENABLE_WARP\" |
|
||||
.cloudflare.secretName = \"$SECRET_NAME\" |
|
||||
.cloudflared = $CLOUDFLARED_BLOCK
|
||||
" "$ORIGINAL_FILE" > "$MERGED_FILE"
|
||||
|
||||
echo "✅ Final merged values.yaml:"
|
||||
cat "$MERGED_FILE"
|
||||
|
||||
# === STEP 5: Optional push to Git ===
|
||||
# === STEP 6: Optional Git push ===
|
||||
echo "📤 Pushing updated values.yaml to infra repo..."
|
||||
|
||||
cd "$INFRA_CLONE"
|
||||
@ -97,7 +102,6 @@ git config user.name "woodpecker-bot"
|
||||
git config user.email "ci@dvirlabs.com"
|
||||
git remote set-url origin "https://${GIT_TOKEN}@git.dvirlabs.com/dvirlabs/infra.git"
|
||||
|
||||
# Only commit if there are changes
|
||||
if ! git diff --quiet manifests/cloudflared/values.yaml; then
|
||||
git add manifests/cloudflared/values.yaml
|
||||
git commit -m "chore(cloudflared): auto-merge CNAME entries from sandbox"
|
||||
@ -106,4 +110,3 @@ if ! git diff --quiet manifests/cloudflared/values.yaml; then
|
||||
else
|
||||
echo "ℹ️ No changes to commit."
|
||||
fi
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user