-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
93 lines (88 loc) · 3.41 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Deploy Scaleway Serverless Container
description: Allows you to deploy your Docker containers to Scaleway Serverless containers.
author: Tim Perry
branding:
icon: 'grid'
color: 'purple'
inputs:
container_id:
description: |
The UUID of the container.
This Action does not create containers, only update existing ones. You therefore need a container to be created initially, and take the ID from that.
The ID can be found in the URL, or the API.
required: true
secret_key:
description: |
The secret API key used to access Scaleway.
This is generated from the Credentials page.
This key must be for the right Organization.
The key must have access to the Container Registry and theServerless
Note that Access Key is not used,
required: true
registry_image_url:
description: |
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
required: true
api_version:
description: |
The version of the API to compare against.
required: false
default: 'v1beta1'
region:
description: |
Scaleway region ID (one of `fr-par`, `nl-ams`, `pl-waw`).
required: false
default: 'fr-par'
timeout_seconds:
description: 'Timeout in seconds for the deployment'
required: false
default: '120'
runs:
using: "composite"
steps:
- name: Update container with new image version
shell: bash
run: |
echo "Updating container image to ${{ inputs.registry_image_url }}"
curl --silent --fail -o /dev/null -w "Response: %{http_code}\n" \
--request PATCH \
--header "X-Auth-Token: ${{ inputs.secret_key }}" \
--data '{"redeploy": true, "registry_image": "${{ inputs.registry_image_url }}"}' \
https://api.scaleway.com/containers/${{ inputs.api_version }}/regions/${{ inputs.region }}/containers/${{ inputs.container_id }}
- name: Redeploy container
shell: bash
run: |
curl --silent --fail -o /dev/null -w "Response: %{http_code}\n" \
--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
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"
if [ "$status" = "pending" ]; then
sleep 1
elif [ "$status" = "ready" ]; then
break
else
echo "Failed to deploy container - $status: $error_message"
exit 1
fi
done