diff --git a/integrator/docker/kestra-init.sh b/integrator/docker/kestra-init.sh index 624a2ec..fd821d2 100644 --- a/integrator/docker/kestra-init.sh +++ b/integrator/docker/kestra-init.sh @@ -6,12 +6,36 @@ KESTRA_URL="${KESTRA_URL:-http://kestra:8080}" echo "Importing flows into Kestra at ${KESTRA_URL}..." for f in /flows/*.yml; do - echo " -> $(basename "$f")" - curl -sf -X POST "${KESTRA_URL}/api/v1/flows/import" \ - -H "Content-Type: multipart/form-data" \ - -F "fileUpload=@${f}" \ - || { echo "Failed to import $(basename "$f")"; exit 1; } - echo "" + name="$(basename "$f")" + echo " -> $name" + + http_code=$(curl -s -o /tmp/kestra_resp -w "%{http_code}" \ + -X POST "${KESTRA_URL}/api/v1/flows" \ + -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 echo "All flows imported."