fix(kestra-init): use correct flows API endpoint and handle upsert
All checks were successful
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 32s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 1m4s
Build and Push Docker Images / Build Integrator (push) Successful in 56s
Build and Push Docker Images / Build Kestra Init (push) Successful in 31s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 0s

- POST /api/v1/flows with Content-Type: application/x-yaml (not the
  ZIP-based /import endpoint)
- On 409 (already exists), fall back to PUT /api/v1/flows/{ns}/{id}
  so redeployment updates existing flows rather than failing
- Print HTTP response body on error for easier debugging

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-24 15:10:09 +00:00
parent ec2d99446f
commit d5260cf8fc

View File

@@ -6,12 +6,36 @@ KESTRA_URL="${KESTRA_URL:-http://kestra:8080}"
echo "Importing flows into Kestra at ${KESTRA_URL}..." echo "Importing flows into Kestra at ${KESTRA_URL}..."
for f in /flows/*.yml; do for f in /flows/*.yml; do
echo " -> $(basename "$f")" name="$(basename "$f")"
curl -sf -X POST "${KESTRA_URL}/api/v1/flows/import" \ echo " -> $name"
-H "Content-Type: multipart/form-data" \
-F "fileUpload=@${f}" \ http_code=$(curl -s -o /tmp/kestra_resp -w "%{http_code}" \
|| { echo "Failed to import $(basename "$f")"; exit 1; } -X POST "${KESTRA_URL}/api/v1/flows" \
echo "" -H "Content-Type: application/x-yaml" \
--data-binary "@${f}")
if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then
echo " created"
elif [ "$http_code" = "409" ]; then
# Flow already exists — update it via PUT /api/v1/flows/{namespace}/{id}
ns=$(grep '^namespace:' "$f" | awk '{print $2}')
id=$(grep '^id:' "$f" | awk '{print $2}')
http_code2=$(curl -s -o /tmp/kestra_resp -w "%{http_code}" \
-X PUT "${KESTRA_URL}/api/v1/flows/${ns}/${id}" \
-H "Content-Type: application/x-yaml" \
--data-binary "@${f}")
if [ "$http_code2" = "200" ] || [ "$http_code2" = "201" ]; then
echo " updated"
else
echo " ERROR updating $name: HTTP $http_code2"
cat /tmp/kestra_resp; echo
exit 1
fi
else
echo " ERROR importing $name: HTTP $http_code"
cat /tmp/kestra_resp; echo
exit 1
fi
done done
echo "All flows imported." echo "All flows imported."