Skip to content

Commit

Permalink
Fix timeout (timeout-minutes not supported in composite actions)
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Aug 20, 2024
1 parent 5c2d61d commit 0362ab4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
24 changes: 16 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -51,25 +51,33 @@ 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 }}" \
--data '{}' \
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"
Expand Down

0 comments on commit 0362ab4

Please sign in to comment.