Skip to content

Commit

Permalink
Update actions around ephemeral instances to new api surface (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukqw authored Jul 17, 2024
1 parent e6a1e5c commit 4ae40bc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/ephemeral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
"state-backend": "ephemeral",
"state-action": "start",
"skip-ephemeral-stop": "true",
"preview-cmd": ${{ toJSON(env.PREVIEW_CMD) }}
"preview-cmd": ${{ toJSON(env.PREVIEW_CMD) }},
"lifetime": 5,
}
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
Expand All @@ -28,9 +29,25 @@ jobs:
awslocal s3 mb s3://test-bucket
awslocal sqs create-queue --queue-name=test-queue
echo "Deploy is done."
EXTENSION_AUTO_INSTALL: "localstack-extension-mailhog"

- name: Assertion step
run: |
sudo apt-get install jq jo
response=$(curl ${AWS_ENDPOINT_URL}/_localstack/extensions/list)
match=$(echo "$response" | jq -r '.[] | select(.distribution.name == "localstack-extension-mailhog") | .distribution.name')
if [ "$match" == "localstack-extension-mailhog" ]; then
echo "Match found: localstack-extension-mailhog"
else
echo "No match found"
echo $response
exit 1
fi
# We want explicit shutdown
- name: Shutdown ephemeral instance
if: ${{ always() }}
uses: jenseng/dynamic-uses@v1
with:
uses: LocalStack/setup-localstack@${{ env.GH_ACTION_VERSION }}
Expand Down
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ inputs:
state-name:
description: 'Name of the state artifact (without extension)'
required: false
auto-load-pod:
description: 'The pod to load on startup of LocalStack, the env var AUTO_LOAD_POD'
required: false
default: ''
extension-auto-install:
description: 'The extension(s) to automatically install on startup of LocalStack, the env var EXTENSION_AUTO_INSTALL'
required: false
default: ''
lifetime:
description: 'The lifetime of the ephemeral instance, how long the instance should be available for'
required: false
default: '30'

runs:
using: "composite"
Expand Down
3 changes: 1 addition & 2 deletions ephemeral/shutdown/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ runs:
response=$(curl -X DELETE \
-H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
-H "authorization: token ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
-H "content-type: application/json" \
https://api.localstack.cloud/v1/previews/$previewName)
https://api.localstack.cloud/v1/compute/instances/$previewName)
if [[ "$response" != "{}" ]]; then
# In case the deletion fails, e.g. if the instance cannot be found, we raise a proper error on the platform
echo "Unable to delete preview environment. API response: $response"
Expand Down
18 changes: 15 additions & 3 deletions ephemeral/startup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ inputs:
description: 'The pod to load on startup of LocalStack, the env var AUTO_LOAD_POD'
required: false
default: ''
extension-auto-install:
description: 'The extension(s) to automatically install on startup of LocalStack, the env var EXTENSION_AUTO_INSTALL'
required: false
default: ''
lifetime:
description: 'The lifetime of the ephemeral instance, how long the instance should be available for'
required: false
default: '30'


runs:
using: composite
Expand Down Expand Up @@ -53,11 +62,14 @@ runs:
# TODO: make preview name configurable!
previewName=preview-$prId
response=$(curl -X POST -d "{\"auto_load_pod\": \"${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}\"}" \
autoLoadPod="${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}"
extensionAutoInstall="${EXTENSION_AUTO_INSTALL:-${{ inputs.extension-auto-install }}}"
lifetime="${{ inputs.lifetime }}"
response=$(curl -X POST -d "{\"instance_name\": \"${previewName}\", \"lifetime\": ${lifetime} ,\"env_vars\": {\"AUTO_LOAD_POD\": \"${autoLoadPod}\", \"EXTENSION_AUTO_INSTALL\": \"${extensionAutoInstall}\"}}"\
-H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
-H "authorization: token ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \
-H "content-type: application/json" \
https://api.localstack.cloud/v1/previews/$previewName)
https://api.localstack.cloud/v1/compute/instances)
endpointUrl=$(echo "$response" | jq -r .endpoint_url)
if [ "$endpointUrl" = "null" ] || [ "$endpointUrl" = "" ]; then
echo "Unable to create preview environment. API response: $response"
Expand Down

0 comments on commit 4ae40bc

Please sign in to comment.