|
| 1 | +name: "Wait for services to be ready" |
| 2 | +description: "Polls store-front and order-service health endpoints until they respond, with optional kubectl diagnostics on failure." |
| 3 | + |
| 4 | +inputs: |
| 5 | + store-front-url: |
| 6 | + description: "Base URL of the store-front service (e.g., http://x.x.x.x)" |
| 7 | + required: true |
| 8 | + k8s-namespace: |
| 9 | + description: "Kubernetes namespace for kubectl diagnostics on failure. If empty, diagnostics are skipped." |
| 10 | + required: false |
| 11 | + default: "" |
| 12 | + max-attempts: |
| 13 | + description: "Maximum number of polling attempts per service" |
| 14 | + required: false |
| 15 | + default: "30" |
| 16 | + retry-interval: |
| 17 | + description: "Seconds to wait between polling attempts" |
| 18 | + required: false |
| 19 | + default: "10" |
| 20 | + stabilization-delay: |
| 21 | + description: "Seconds to wait after order-service responds before continuing" |
| 22 | + required: false |
| 23 | + default: "30" |
| 24 | + |
| 25 | +runs: |
| 26 | + using: "composite" |
| 27 | + steps: |
| 28 | + - name: Wait for services to be ready |
| 29 | + shell: bash |
| 30 | + env: |
| 31 | + STORE_FRONT_URL: ${{ inputs.store-front-url }} |
| 32 | + K8S_NAMESPACE: ${{ inputs.k8s-namespace }} |
| 33 | + MAX_ATTEMPTS: ${{ inputs.max-attempts }} |
| 34 | + RETRY_INTERVAL: ${{ inputs.retry-interval }} |
| 35 | + STABILIZATION_DELAY: ${{ inputs.stabilization-delay }} |
| 36 | + run: | |
| 37 | + echo "Waiting for store-front at ${STORE_FRONT_URL}..." |
| 38 | + STORE_FRONT_READY=false |
| 39 | + for i in $(seq 1 "$MAX_ATTEMPTS"); do |
| 40 | + if curl -sf "${STORE_FRONT_URL}" > /dev/null 2>&1; then |
| 41 | + echo "Store front is responding" |
| 42 | + STORE_FRONT_READY=true |
| 43 | + break |
| 44 | + fi |
| 45 | + echo "Attempt ${i}/${MAX_ATTEMPTS}: Store front not ready, waiting ${RETRY_INTERVAL}s..." |
| 46 | + sleep "$RETRY_INTERVAL" |
| 47 | + done |
| 48 | + if [ "$STORE_FRONT_READY" != "true" ]; then |
| 49 | + echo "::error::Store front failed to respond after ${MAX_ATTEMPTS} attempts" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + echo "Waiting for order-service to be ready via ${STORE_FRONT_URL}/api/orders/health..." |
| 54 | + ORDER_SERVICE_READY=false |
| 55 | + for i in $(seq 1 "$MAX_ATTEMPTS"); do |
| 56 | + HTTP_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "${STORE_FRONT_URL}/api/orders/health" 2>&1) || true |
| 57 | + if [ "$HTTP_RESPONSE" = "200" ]; then |
| 58 | + echo "Order service is responding (HTTP 200), waiting ${STABILIZATION_DELAY}s for all services to stabilize..." |
| 59 | + sleep "$STABILIZATION_DELAY" |
| 60 | + ORDER_SERVICE_READY=true |
| 61 | + break |
| 62 | + fi |
| 63 | + echo "Attempt ${i}/${MAX_ATTEMPTS}: Order service not ready (HTTP ${HTTP_RESPONSE}), waiting ${RETRY_INTERVAL}s..." |
| 64 | + sleep "$RETRY_INTERVAL" |
| 65 | + done |
| 66 | + if [ "$ORDER_SERVICE_READY" != "true" ]; then |
| 67 | + echo "::error::Order service failed to respond after ${MAX_ATTEMPTS} attempts" |
| 68 | + if [ -n "$K8S_NAMESPACE" ]; then |
| 69 | + echo "::group::Diagnostics - pod status" |
| 70 | + kubectl get pods -n "$K8S_NAMESPACE" -l app=order-service 2>&1 || true |
| 71 | + echo "--- order-service events ---" |
| 72 | + kubectl get events -n "$K8S_NAMESPACE" --field-selector involvedObject.kind=Pod --sort-by='.lastTimestamp' 2>&1 | grep order-service || true |
| 73 | + echo "--- order-service container status ---" |
| 74 | + kubectl get pods -n "$K8S_NAMESPACE" -l app=order-service -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{range .status.containerStatuses[*]} {.name}: ready={.ready}, restartCount={.restartCount}, state={.state}{"\n"}{end}{range .status.initContainerStatuses[*]} init/{.name}: ready={.ready}, state={.state}{"\n"}{end}{end}' 2>&1 || true |
| 75 | + echo "" |
| 76 | + echo "--- configmap keys (values redacted) ---" |
| 77 | + kubectl get configmap -n "$K8S_NAMESPACE" -l "kustomize.toolkit.fluxcd.io/name" -o jsonpath='{range .items[*]}ConfigMap: {.metadata.name}{"\n"}{range $k, $v := .data} {$k}=***{"\n"}{end}{end}' 2>&1 || true |
| 78 | + kubectl get configmap -n "$K8S_NAMESPACE" order-service -o jsonpath='{range $k, $v := .data}{$k}=***{"\n"}{end}' 2>&1 || true |
| 79 | + echo "::endgroup::" |
| 80 | + fi |
| 81 | + exit 1 |
| 82 | + fi |
0 commit comments