Skip to content

Commit 4ae40bc

Browse files
authored
Update actions around ephemeral instances to new api surface (#31)
1 parent e6a1e5c commit 4ae40bc

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

.github/workflows/ephemeral.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ jobs:
1919
"state-backend": "ephemeral",
2020
"state-action": "start",
2121
"skip-ephemeral-stop": "true",
22-
"preview-cmd": ${{ toJSON(env.PREVIEW_CMD) }}
22+
"preview-cmd": ${{ toJSON(env.PREVIEW_CMD) }},
23+
"lifetime": 5,
2324
}
2425
env:
2526
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
@@ -28,9 +29,25 @@ jobs:
2829
awslocal s3 mb s3://test-bucket
2930
awslocal sqs create-queue --queue-name=test-queue
3031
echo "Deploy is done."
32+
EXTENSION_AUTO_INSTALL: "localstack-extension-mailhog"
33+
34+
- name: Assertion step
35+
run: |
36+
sudo apt-get install jq jo
37+
response=$(curl ${AWS_ENDPOINT_URL}/_localstack/extensions/list)
38+
match=$(echo "$response" | jq -r '.[] | select(.distribution.name == "localstack-extension-mailhog") | .distribution.name')
39+
if [ "$match" == "localstack-extension-mailhog" ]; then
40+
echo "Match found: localstack-extension-mailhog"
41+
else
42+
echo "No match found"
43+
echo $response
44+
exit 1
45+
fi
46+
3147
3248
# We want explicit shutdown
3349
- name: Shutdown ephemeral instance
50+
if: ${{ always() }}
3451
uses: jenseng/dynamic-uses@v1
3552
with:
3653
uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }}

action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ inputs:
6868
state-name:
6969
description: 'Name of the state artifact (without extension)'
7070
required: false
71+
auto-load-pod:
72+
description: 'The pod to load on startup of LocalStack, the env var AUTO_LOAD_POD'
73+
required: false
74+
default: ''
75+
extension-auto-install:
76+
description: 'The extension(s) to automatically install on startup of LocalStack, the env var EXTENSION_AUTO_INSTALL'
77+
required: false
78+
default: ''
79+
lifetime:
80+
description: 'The lifetime of the ephemeral instance, how long the instance should be available for'
81+
required: false
82+
default: '30'
7183

7284
runs:
7385
using: "composite"

ephemeral/shutdown/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ runs:
3131
3232
response=$(curl -X DELETE \
3333
-H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
34-
-H "authorization: token ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
3534
-H "content-type: application/json" \
36-
https://api.localstack.cloud/v1/previews/$previewName)
35+
https://api.localstack.cloud/v1/compute/instances/$previewName)
3736
if [[ "$response" != "{}" ]]; then
3837
# In case the deletion fails, e.g. if the instance cannot be found, we raise a proper error on the platform
3938
echo "Unable to delete preview environment. API response: $response"

ephemeral/startup/action.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ inputs:
1515
description: 'The pod to load on startup of LocalStack, the env var AUTO_LOAD_POD'
1616
required: false
1717
default: ''
18+
extension-auto-install:
19+
description: 'The extension(s) to automatically install on startup of LocalStack, the env var EXTENSION_AUTO_INSTALL'
20+
required: false
21+
default: ''
22+
lifetime:
23+
description: 'The lifetime of the ephemeral instance, how long the instance should be available for'
24+
required: false
25+
default: '30'
26+
1827

1928
runs:
2029
using: composite
@@ -53,11 +62,14 @@ runs:
5362
# TODO: make preview name configurable!
5463
previewName=preview-$prId
5564
56-
response=$(curl -X POST -d "{\"auto_load_pod\": \"${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}\"}" \
65+
autoLoadPod="${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}"
66+
extensionAutoInstall="${EXTENSION_AUTO_INSTALL:-${{ inputs.extension-auto-install }}}"
67+
lifetime="${{ inputs.lifetime }}"
68+
69+
response=$(curl -X POST -d "{\"instance_name\": \"${previewName}\", \"lifetime\": ${lifetime} ,\"env_vars\": {\"AUTO_LOAD_POD\": \"${autoLoadPod}\", \"EXTENSION_AUTO_INSTALL\": \"${extensionAutoInstall}\"}}"\
5770
-H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
58-
-H "authorization: token ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
5971
-H "content-type: application/json" \
60-
https://api.localstack.cloud/v1/previews/$previewName)
72+
https://api.localstack.cloud/v1/compute/instances)
6173
endpointUrl=$(echo "$response" | jq -r .endpoint_url)
6274
if [ "$endpointUrl" = "null" ] || [ "$endpointUrl" = "" ]; then
6375
echo "Unable to create preview environment. API response: $response"

0 commit comments

Comments
 (0)