|
| 1 | +name: Wait for Control Plane workload health |
| 2 | +description: >- |
| 3 | + Polls the workload's status endpoint with curl and exits success when the |
| 4 | + HTTP response status is in the accepted list. Fails non-zero (and reports |
| 5 | + `healthy=false`) once retries are exhausted. |
| 6 | +
|
| 7 | +inputs: |
| 8 | + workload_name: |
| 9 | + description: Workload to query (e.g. `rails`). |
| 10 | + required: true |
| 11 | + app_name: |
| 12 | + description: GVC / Control Plane app name the workload belongs to. |
| 13 | + required: true |
| 14 | + org: |
| 15 | + description: Control Plane organization. |
| 16 | + required: true |
| 17 | + max_retries: |
| 18 | + description: Number of attempts before giving up. |
| 19 | + required: false |
| 20 | + default: "24" |
| 21 | + interval_seconds: |
| 22 | + description: Seconds to sleep between attempts. |
| 23 | + required: false |
| 24 | + default: "15" |
| 25 | + accepted_statuses: |
| 26 | + description: >- |
| 27 | + Space-separated list of HTTP status codes considered healthy. The default |
| 28 | + `200 301 302` accepts redirects because curl is invoked without `-L`, so a |
| 29 | + root path that auth-redirects looks like a redirect, not a failure. |
| 30 | + required: false |
| 31 | + default: "200 301 302" |
| 32 | + curl_max_time: |
| 33 | + description: Per-request curl timeout, seconds. |
| 34 | + required: false |
| 35 | + default: "10" |
| 36 | + |
| 37 | +outputs: |
| 38 | + healthy: |
| 39 | + description: '"true" once a healthy response was observed; "false" otherwise.' |
| 40 | + value: ${{ steps.poll.outputs.healthy }} |
| 41 | + |
| 42 | +runs: |
| 43 | + using: composite |
| 44 | + steps: |
| 45 | + - name: Poll workload endpoint |
| 46 | + id: poll |
| 47 | + shell: bash |
| 48 | + env: |
| 49 | + CPFLOW_WORKLOAD_NAME: ${{ inputs.workload_name }} |
| 50 | + CPFLOW_APP_NAME: ${{ inputs.app_name }} |
| 51 | + CPFLOW_ORG: ${{ inputs.org }} |
| 52 | + CPFLOW_MAX_RETRIES: ${{ inputs.max_retries }} |
| 53 | + CPFLOW_INTERVAL_SECONDS: ${{ inputs.interval_seconds }} |
| 54 | + CPFLOW_ACCEPTED_STATUSES: ${{ inputs.accepted_statuses }} |
| 55 | + CPFLOW_CURL_MAX_TIME: ${{ inputs.curl_max_time }} |
| 56 | + run: | |
| 57 | + set -euo pipefail |
| 58 | +
|
| 59 | + read -r -a accepted_statuses <<< "${CPFLOW_ACCEPTED_STATUSES}" |
| 60 | +
|
| 61 | + for attempt in $(seq 1 "${CPFLOW_MAX_RETRIES}"); do |
| 62 | + echo "Health check attempt ${attempt}/${CPFLOW_MAX_RETRIES}" |
| 63 | +
|
| 64 | + endpoint="$(cpln workload get "${CPFLOW_WORKLOAD_NAME}" --gvc "${CPFLOW_APP_NAME}" --org "${CPFLOW_ORG}" -o json | jq -r '.status.endpoint // empty')" |
| 65 | + if [[ -n "${endpoint}" ]]; then |
| 66 | + http_status="$(curl -s -o /dev/null -w '%{http_code}' --max-time "${CPFLOW_CURL_MAX_TIME}" "${endpoint}" 2>/dev/null || echo 000)" |
| 67 | + echo "Endpoint: ${endpoint}, HTTP status: ${http_status}" |
| 68 | +
|
| 69 | + for accepted in "${accepted_statuses[@]}"; do |
| 70 | + if [[ "${http_status}" == "${accepted}" ]]; then |
| 71 | + echo "healthy=true" >> "$GITHUB_OUTPUT" |
| 72 | + exit 0 |
| 73 | + fi |
| 74 | + done |
| 75 | + fi |
| 76 | +
|
| 77 | + if [[ "${attempt}" -lt "${CPFLOW_MAX_RETRIES}" ]]; then |
| 78 | + sleep "${CPFLOW_INTERVAL_SECONDS}" |
| 79 | + fi |
| 80 | + done |
| 81 | +
|
| 82 | + echo "healthy=false" >> "$GITHUB_OUTPUT" |
| 83 | + exit 1 |
0 commit comments