diff --git a/README.md b/README.md index 9c42de5..d45c3e0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ and extends them by: * Monitoring the deploy after it's started, and waiting until it's completed successfully * Exposing a v1 tag to allow easy tracking & referencing of the latest version -* Adding a `timeout` option to fail if the container doesn't start in time +* Adding a `timeout_seconds` option to fail if the container doesn't start in time ## Usage @@ -40,7 +40,7 @@ In your workflow use this action like so, filling in the arguments with your own | `registry_image_url` | The URL for the registry, image, and version to use in the container, e.g: `rg.fr-par.scw.cloud/example-registry/example-image:latest` | ✔️ | N/A | | `region` | Scaleway region ID (one of `fr-par`, `nl-ams`, `pl-waw`) | ❌ | fr-par | | `api_version` | The version of the API to compare against | ❌ | v1beta1 | -| `timeout` | How long to wait (in minutes) for the container to become ready | ❌ | 2 | +| `timeout_seconds` | How long to wait (in seconds) for the container to become ready | ❌ | 120 | ## License diff --git a/action.yml b/action.yml index bac17e9..810e98c 100644 --- a/action.yml +++ b/action.yml @@ -33,16 +33,16 @@ inputs: Scaleway region ID (one of `fr-par`, `nl-ams`, `pl-waw`). required: false default: 'fr-par' - timeout: - description: 'Timeout in minutes for the deployment' + timeout_seconds: + description: 'Timeout in seconds for the deployment' required: false - default: '2' + default: '120' runs: using: "composite" steps: - name: Update container with new image version shell: bash - run: > + run: | echo "Updating container image to ${{ inputs.registry_image_url }}" curl \ --request PATCH \ @@ -51,7 +51,7 @@ runs: https://api.scaleway.com/containers/${{ inputs.api_version }}/regions/${{ inputs.region }}/containers/${{ inputs.container_id }} - name: Redeploy container shell: bash - run: > + run: | curl \ --request POST \ --header "X-Auth-Token:${{ inputs.secret_key }}" \ @@ -59,17 +59,25 @@ runs: https://api.scaleway.com/containers/${{ inputs.api_version }}/regions/${{ inputs.region }}/containers/${{ inputs.container_id }}/deploy - name: Wait for deploy to be successful shell: bash - timeout-minutes: ${{ inputs.timeout }} - run: > - echo "Waiting for container to report as ready..." + run: | + SECONDS=0 + TIMEOUT=${{ inputs.timeout_seconds }} + + echo "Waiting up to $TIMEOUT seconds for container to report as ready..." sleep 1 while true; do + if [ $SECONDS -ge $TIMEOUT ]; then + echo "Deployment timed out after $TIMEOUT seconds" + exit 1 + fi + container=$(curl --silent \ --request GET \ --header "X-Auth-Token:${{ inputs.secret_key }}" \ https://api.scaleway.com/containers/${{ inputs.api_version }}/regions/${{ inputs.region }}/containers/${{ inputs.container_id }} \ ) + status=$(echo $container | jq -r '.status') error_message=$(echo $container | jq -r '.error_message') echo "Container status: $status"