Skip to content

Commit

Permalink
feat: add dynamic startup
Browse files Browse the repository at this point in the history
  • Loading branch information
lakkeger committed May 15, 2024
1 parent 2780efb commit ce258da
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 34 deletions.
50 changes: 16 additions & 34 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,23 @@ inputs:
runs:
using: "composite"
steps:
- name: Initial PR comment
# TODO: potentially replace with Action version number over time
uses: LocalStack/setup-localstack/prepare@main
if: inputs.ci-project && inputs.github-token
with:
github-token: ${{ inputs.github-token }}
ci-project: ${{ inputs.ci-project }}

- name: Start LocalStack
run: |
pip install pyopenssl -U
if [ "$USE_PRO" = true ]; then
docker pull localstack/localstack-pro:"$IMAGE_TAG" &
CONFIGURATION="$CONFIGURATION DNS_ADDRESS=127.0.0.1"
else
docker pull localstack/localstack:"$IMAGE_TAG" &
fi
pip install localstack
if [ "$INSTALL_AWSLOCAL" = true ]; then
pip install awscli-local[ver1]
fi
export CI_PROJECT=${{ inputs.ci-project }}
eval "${CONFIGURATION} localstack start -d"
localstack wait -t 30
shell: bash
# - name: Initial PR comment
# # TODO: potentially replace with Action version number over time
# uses: LocalStack/setup-localstack/prepare@main
# if: inputs.ci-project && inputs.github-token
# with:
# github-token: ${{ inputs.github-token }}
# ci-project: ${{ inputs.ci-project }}

- name: Start Localstack
uses: jenseng/dynamic-uses@v1
env:
IMAGE_TAG: "${{ inputs.image-tag }}"
INSTALL_AWSLOCAL: "${{ inputs.install-awslocal }}"
USE_PRO: "${{ inputs.use-pro }}"
CONFIGURATION: "${{ inputs.configuration }}"
action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }}
with:
# now you can use expressions 🥳
uses: LocalStack/setup-localstack/startup@${{ env.action-version }}
# the `with` needs to be converted to a valid json string
with: "${{ toJSON(inputs) }}"

# TODO: potentially add an additional step here to create preview envs, and add a switch to
# enable/disable the "Start LocalStack" action above. This way we could make this action
Expand Down
67 changes: 67 additions & 0 deletions startup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: 'Start up Localstack'

inputs:
image-tag:
description: 'Tag of the LocalStack Docker image to use'
required: true
default: 'latest'
install-awslocal:
description: 'Whether to install the `awslocal` CLI into the environment'
required: true
default: 'true'
use-pro:
description: 'Whether to use LocalStack Pro (requires a valid API key)'
required: false
default: 'false'
configuration:
description: 'Configuration variables to use for LocalStack'
required: false
default: ''
ci-project:
description: 'Name of the CI project to track in LocalStack Cloud'
required: false
default: ''

runs:
using: "composite"
steps:
# - name: Initial PR comment
# # TODO: potentially replace with Action version number over time
# uses: LocalStack/setup-localstack/prepare@main
# if: inputs.ci-project && inputs.github-token
# with:
# github-token: ${{ inputs.github-token }}
# ci-project: ${{ inputs.ci-project }}

- name: Start LocalStack
run: |
pip install pyopenssl -U
if [ "$USE_PRO" = true ]; then
docker pull localstack/localstack-pro:"$IMAGE_TAG" &
CONFIGURATION="$CONFIGURATION DNS_ADDRESS=127.0.0.1"
else
docker pull localstack/localstack:"$IMAGE_TAG" &
fi
pip install localstack
if [ "$INSTALL_AWSLOCAL" = true ]; then
pip install awscli-local[ver1]
fi
export CI_PROJECT=${{ inputs.ci-project }}
eval "${CONFIGURATION} localstack start -d"
localstack wait -t 30
shell: bash
env:
IMAGE_TAG: "${{ inputs.image-tag }}"
INSTALL_AWSLOCAL: "${{ inputs.install-awslocal }}"
USE_PRO: "${{ inputs.use-pro }}"
CONFIGURATION: "${{ inputs.configuration }}"

# TODO: potentially add an additional step here to create preview envs, and add a switch to
# enable/disable the "Start LocalStack" action above. This way we could make this action
# the single entry point which then delegates to sub-actions in this repo, based on the
# user-provided configuration...

0 comments on commit ce258da

Please sign in to comment.