Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code #17

Merged
merged 31 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
571f254
feat: add dynamic startup
lakkeger May 14, 2024
23c69e1
feat: add new variables and logic
lakkeger May 15, 2024
4c796da
feat: Add local state management
lakkeger May 15, 2024
5f892cb
feat(startup): add warning if use-pro used but no key provided
lakkeger May 15, 2024
f97de5c
feat(startup): add skip wait
lakkeger May 15, 2024
39f4048
style(startup): remove unnecessary quotes
lakkeger May 15, 2024
36ffc44
feat: add skips
lakkeger May 15, 2024
b413119
feat(tools): add action to install tools
lakkeger May 15, 2024
0fc578e
feat(ci): add local state test
lakkeger May 15, 2024
98771bf
docs: Update README.md
lakkeger May 16, 2024
bb86923
fix(cloud-pods): ensure pod load not prompts for user input
lakkeger May 16, 2024
0165a01
feat(preview): allow env variables to control pod load
lakkeger May 16, 2024
63a7484
chore(ci): exclude pipeline trigger for docs
lakkeger May 16, 2024
e188543
feat: add app preview management
lakkeger May 16, 2024
c5cab2f
docs: add app preview options
lakkeger May 16, 2024
da81a10
docs: add default value for include-preview
lakkeger May 16, 2024
4e0068a
feat: tweak logic for preview ci
lakkeger May 16, 2024
f046bca
fix: fix sub-action versions
lakkeger May 16, 2024
8ef5699
fix(startup): fix test condition syntax
lakkeger May 16, 2024
a1b36da
fix(preview): fix variable expansions
lakkeger May 17, 2024
1a99576
fix(ci): update ephemeral ci with version fix
lakkeger May 17, 2024
4b05efe
Merge branch 'main' into refactor_default_action
lakkeger May 17, 2024
0f2479b
fix(ci): update ephemeral ci with version fix
lakkeger May 17, 2024
9b85434
Merge branch 'refactor_default_action' of github.com:localstack/setup…
lakkeger May 17, 2024
28455d4
docs: add ephemeral examples
lakkeger May 17, 2024
2c432c9
docs: fix nits for docs, add preview-cmd to preview for better unders…
lakkeger May 29, 2024
100e48b
feat: change order of preview and state management for possible state…
lakkeger May 29, 2024
2a0c82f
refactor: change env variable names
lakkeger May 29, 2024
5b47bda
refactor(ci): refactor ternary logic
lakkeger May 29, 2024
a835beb
fix: save state without skip-start switch
lakkeger May 30, 2024
6b8e991
refactor: rename preview to ephemeral/startup, rename related options
lakkeger May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 79 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
name: LocalStack Test
on:
push:
paths-ignore:
- ./*.md
- LICENSE
pull_request:
paths-ignore:
- ./*.md
- LICENSE
workflow_dispatch:
schedule:
- cron: '48 23 * * 0'
Expand All @@ -13,15 +19,22 @@ jobs:
steps:
- uses: actions/checkout@v3

# We must hack the action call as remote to be able to use the relative paths
# Could it break with different CWD? 🤔
- name: Start LocalStack
uses: ./
uses: jenseng/dynamic-uses@v1
with:
image-tag: 'latest'
install-awslocal: 'true'
configuration: DEBUG=1
use-pro: 'true'
uses: LocalStack/setup-localstack@${{ env.action-version }}
with: |-
{
"image-tag": "latest",
"install-awslocal": "true",
"configuration": "DEBUG=1",
"use-pro": "true",
}
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }}
lakkeger marked this conversation as resolved.
Show resolved Hide resolved

- name: Run Tests against LocalStack
run: |
Expand All @@ -37,23 +50,77 @@ jobs:
uses: actions/checkout@v3

- name: Start LocalStack
uses: ./
uses: jenseng/dynamic-uses@v1
with:
image-tag: 'latest'
install-awslocal: 'true'
use-pro: 'true'
uses: LocalStack/setup-localstack@${{ env.action-version }}
with: |-
{
"image-tag": "latest",
"install-awslocal": "true",
"configuration": "DEBUG=1",
"use-pro": "true",
}
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }}
lakkeger marked this conversation as resolved.
Show resolved Hide resolved

- name: Run AWS commands
run: |
awslocal s3 mb s3://test
awslocal sqs create-queue --queue-name test-queue

- name: Save the Cloud Pod
uses: LocalStack/setup-localstack/cloud-pods@main
uses: jenseng/dynamic-uses@v1
with:
name: cloud-pods-test
action: save
uses: LocalStack/setup-localstack@${{ env.action-version }}
with: |-
{
"state-name": "cloud-pods-test",
"state-action": "save",
"skip-startup": "true",
}
lakkeger marked this conversation as resolved.
Show resolved Hide resolved
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }}

local-state-test:
name: 'Test Local State Action'
runs-on: ubuntu-latest
steps:
- name: ⚡️ Checkout the repository
uses: actions/checkout@v3

- name: Start LocalStack
uses: jenseng/dynamic-uses@v1
with:
uses: LocalStack/setup-localstack@${{ env.action-version }}
with: |-
{
"image-tag": "latest",
"install-awslocal": "true",
"configuration": "DEBUG=1",
"use-pro": "true",
}
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }}

- name: Run AWS commands
run: |
awslocal s3 mb s3://test
awslocal sqs create-queue --queue-name test-queue

- name: Save the Cloud Pod
uses: jenseng/dynamic-uses@v1
with:
uses: LocalStack/setup-localstack@${{ env.action-version }}
with: |-
{
"state-name": "cloud-pods-test",
"state-action": "save",
"state-backend": "local",
"skip-startup": "true",
}
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }}
30 changes: 24 additions & 6 deletions .github/workflows/ephemeral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@ jobs:
- uses: actions/checkout@v3

- name: Deploy Preview
uses: ./preview
uses: jenseng/dynamic-uses@v1
with:
localstack-api-key: ${{ secrets.LOCALSTACK_API_KEY }}
github-token: ${{ secrets.GITHUB_TOKEN }}
uses: LocalStack/setup-localstack@${{ env.action-version }}
with: |-
{
"github-token": "${{ secrets.GITHUB_TOKEN }}",
"state-backend": "preview",
lukqw marked this conversation as resolved.
Show resolved Hide resolved
"state-action": "start",
"skip-preview-stop": "true"
}
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }}

# We want explicit shutdown
- name: Shutdown ephemeral instance
uses: ./ephemeral/shutdown
uses: jenseng/dynamic-uses@v1
with:
localstack-api-key: ${{ secrets.LOCALSTACK_API_KEY }}
github-token: ${{ secrets.GITHUB_TOKEN }}
uses: LocalStack/setup-localstack@${{ env.action-version }}
with: |-
{
"github-token": "${{ secrets.GITHUB_TOKEN }}",
"state-backend": "preview",
"state-action": "stop"
}
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
action-version: ${{ fromJSON(format('["{0}","{1}"]', github.ref_name, github.head_ref))[github.event_name == 'pull_request'] }}
118 changes: 108 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,118 @@ A GitHub Action to setup [LocalStack](https://github.com/localstack/localstack)
- Pulling a specific version of the LocalStack Docker Image into the GitHub Action runner.
- Configuring the [LocalStack CLI](https://docs.localstack.cloud/get-started/#localstack-cli) to launch the Docker container with an optional API token for pro usage.
- Installing [LocalStack AWS CLI](https://github.com/localstack/awscli-local), a thin wrapper around the `aws` command line interface for use with LocalStack to run integration tests over AWS services.
- Export/import [LocalStack state](https://docs.localstack.cloud/user-guide/state-management/export-import-state/) as an artifact
- Save/load [LocalStack Cloud Pods](https://docs.localstack.cloud/user-guide/state-management/cloud-pods/)
- Start/stop a [LocalStack Ephemeral Instance](https://docs.localstack.cloud/user-guide/cloud-sandbox/application-previews/) _(EXPERIMENTAL)_

## Usage

To get started, you can use this minimal example:
### Get started minimal example
lakkeger marked this conversation as resolved.
Show resolved Hide resolved

```yml
- name: Start LocalStack
uses: LocalStack/setup-localstack@v0.1.2
uses: LocalStack/setup-localstack@v0.2.0
with:
image-tag: 'latest'
install-awslocal: 'true'
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
```
> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set if `use-pro` is set to `true`.
If the key is not found LocalStack by default falls back to the CE edition and displays a warning.

### Inputs
### Install only CLIs and startup later
```yml
- name: Install LocalStack CLIs
uses: LocalStack/setup-localstack@v0.2.0
with:
skip-startup: 'true'
install-awslocal: 'true'

...

- name: Start LocalStack
uses: LocalStack/setup-localstack@v0.2.0
with:
image-tag: 'latest'
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
```

### Save a state later on in the pipeline
```yml
- name: Save LocalStack State
uses: LocalStack/setup-localstack@v0.2.0
with:
install-awslocal: 'true'
skip-startup: 'true'
state-backend: cloud-pods
state-action: save
state-name: my-cloud-pod
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
```
> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to save/load LocalStack's state either as a Cloud Pod or an artifact.
lakkeger marked this conversation as resolved.
Show resolved Hide resolved

### Load an already saved state
```yml
- name: Start LocalStack and Load State
uses: LocalStack/setup-localstack@v0.2.0
with:
install-awslocal: 'true'
state-backend: cloud-pods
state-action: load
state-name: my-cloud-pod
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
```
> **NOTE**: To load a **local state** from a different GitHub Actions workflow, one must set the `WORKFLOW_ID` environment variable.

> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set to **save/load** LocalStack's state either as a Cloud Pod or an artifact.
lakkeger marked this conversation as resolved.
Show resolved Hide resolved

### Manage App Preview
```yml
uses: LocalStack/setup-localstack@$v0.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
state-backend: preview
lukqw marked this conversation as resolved.
Show resolved Hide resolved
state-action: start
skip-preview-stop: 'true' # Adding this option prevents
lakkeger marked this conversation as resolved.
Show resolved Hide resolved
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}

...

with:
uses: LocalStack/setup-localstack@${{ env.action-version }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
state-backend: preview
state-action: stop
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
```

## Inputs

| Input | Description | Default |
| ------------------ | -------------------------------------------------------------------------------- | -------- |
| `ci-project` | Name of the CI project to track in LocalStack Cloud | |
| `configuration` | Configuration variables to use while starting LocalStack container | `None` |
| `github-token` | Github token used to create PR comments | |
| `image-tag` | Tag of the LocalStack Docker image to use | `latest` |
| `include-preview` | Whether to include the created preview URL in the PR comment | `false` |
| `install-awslocal` | Whether to install the `awslocal` CLI into the build environment | `true` |
| `configuration` | Configuration variables to use while starting LocalStack container | `None` |
| `preview-cmd` | Command(s) used to create a preview of the PR (can use $AWS_ENDPOINT_URL) | |
lakkeger marked this conversation as resolved.
Show resolved Hide resolved
| `skip-preview-stop` | Skip stopping LocalStack Ephemeral Instance | `false` |
| `skip-startup` | Explicitly prevent LocalStack start up, only installs CLI(s). Recommended to manage state later on in the pipeline or start up an ephemeral instance. | `false` |
| `skip-wait` | Skip wait for LocalStack to start up | `false` |
lakkeger marked this conversation as resolved.
Show resolved Hide resolved
| `state-action` | Valid values are `load`, `save`, `start`, `stop`, `` (empty, don't manage state). Values `start`/`stop` only usable with app previews. | `` |
| `state-backend` | Either store the state of LocalStack locally or as a cloud pod. Valid values are `cloud-pods`, `preview` or `local`. Use this option in unison with `state-action` to control behaviour. | `cloud-pods` |
| `state-name` | Name of the state artifact (without extension) | `false` |
| `use-pro` | Whether to use the Pro version of LocalStack (requires API key to be configured) | `false` |

> **NOTE**: The `LOCALSTACK_API_KEY` environment variable is required to be set if `use-pro` is set to `true`.

### Example workflow

## Example workflow
```yml
name: LocalStack Test
on: [ push, pull_request ]
Expand All @@ -48,20 +132,34 @@ jobs:
- uses: actions/checkout@v3

- name: Start LocalStack
uses: LocalStack/setup-localstack@v0.1.2
uses: LocalStack/setup-localstack@v0.2.0
with:
image-tag: 'latest'
install-awslocal: 'true'
configuration: DEBUG=1
use-pro: 'true'
state-backend: cloud-pods
state-action: load
state-name: my-cloud-pod
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}

- name: Run Tests against LocalStack
run: |
awslocal s3 mb s3://test
awslocal s3 ls
echo "Test Execution complete!"
echo "Test Execution complete!"

- name: Save LocalStack State
uses: LocalStack/setup-localstack@v0.2.0
with:
skip-startup: 'true'
state-backend: local
state-action: save
state-name: my-ls-state-artifact
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
WORKFLOW_ID: ${{ env.MY_GOLDEN_LS_STATE }}
```

## License
Expand Down
Loading
Loading