Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
105 changes: 105 additions & 0 deletions .github/workflows/cloudpod_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
on:
workflow_dispatch:
inputs:
release-tag:
type: string
required: true
description: This will be the version of the release, but will also be used as 'tag' for the localstack docker image
push:
paths-ignore:
- 'README.md'
branches:
- main

permissions:
contents: write

name: Create Release
jobs:
release:
name: Create Release for Cloud Pod
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install CDK
run: |
npm install -g aws-cdk-local aws-cdk
cdklocal --version

- name: Install dependencies
run: |
yarn

- name: Start LocalStack
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
DNS_ADDRESS: 0
run: |
export SQS_QUEUE="sqs-fargate-queue"
export NETWORK_NAME="localstack-shared-net"
docker network create $NETWORK_NAME
pip install localstack awscli-local[ver1]
pip install terraform-local
docker pull localstack/localstack-pro:${{ inputs.release-tag || 'latest'}}
# Start LocalStack in the background
LS_LOG=trace LAMBDA_DOCKER_NETWORK=$NETWORK_NAME DOCKER_FLAGS="--network $NETWORK_NAME" DEBUG=1 localstack start -d
# Wait 30 seconds for the LocalStack container to become ready before timing out
echo "Waiting for LocalStack startup..."
localstack wait -t 15
echo "Startup complete"

- name: Deploy using CDK
run: |
docker build -t go-fargate .
cd cdk
npm install
cdklocal bootstrap aws://000000000000/us-east-1
cdklocal deploy --require-approval never

# TODO run tests

- name: Add some Dummy Data
run: |
echo "Send message to the sqs queue that should be stored in the db"
SQS_QUEUE="sqs-fargate-queue"
awslocal sqs send-message --queue $SQS_QUEUE --message-body '{"message": "hello world"}'

echo "waiting to process the message..."
sleep 3
awslocal dynamodb scan --table-name sqs-fargate-ddb-table

- name: Save the Cloud Pod
uses: HarshCasper/cloud-pod-save@v0.1.0
with:
name: 'release-pod.zip'
location: 'disk'

- name: Prepare Release Notes
run: |
echo "This release includes the Cloud Pod of the sample created with LocalStack Version \`${{ inputs.release-tag || 'latest'}}\`." > Release.txt
echo "Please be aware, that your running LocalStack instance need to be started with \`LAMBDA_DOCKER_NETWORK\`and \`DOCKER_FLAGS\`: " >> Release.txt
echo " * the network must have the name 'localstack-shared-net', e.g.: \`NETWORK_NAME=\"localstack-shared-net\"\`" >> Release.txt
echo " * start LocalStack using: \`docker network create $NETWORK_NAME 2> /dev/null; LAMBDA_DOCKER_NETWORK=\$NETWORK_NAME DOCKER_FLAGS="--network \$NETWORK_NAME" DEBUG=1 localstack start -d\`" >> Release.txt
echo " * use the SQS_QUEUE=\"sqs-fargate-queue\" to send further messages that will be written to DynamoDb" >> Release.txt
echo "" >> Release.txt
echo "You can download the \`release-pod.zip\` and inject it manually by running \`localstack pod load file://release-pod.zip\`, or use the Cloud Pods Launchpad." >> Release.txt
echo "### Cloud Pods Launchpad" >> Release.txt
echo "You can click the Launchpad to inject the the pod into your running LocalStack instance using the WebUI:" >> Release.txt
echo "[![LocalStack Pods Launchpad](https://localstack.cloud/gh/launch-pod-badge.svg)](https://app.localstack.cloud/launchpad?url=https://github.com/$GITHUB_REPOSITORY/releases/download/${{ inputs.release-tag || 'latest'}}/release-pod.zip)" >> Release.txt

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: "${{ inputs.release-tag || 'latest'}}"
name: "Cloud Pod for LocalStack Version '${{ inputs.release-tag || 'latest'}}'"
body_path: ./Release.txt
files: |
./release-pod.zip
136 changes: 136 additions & 0 deletions .github/workflows/test_cloudpods.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Test Released Cloud Pods

on:
schedule:
# “At 00:00 on Saturday.”
- cron: "0 0 * * 6"
workflow_dispatch:
push: # TODO remove just for testing
paths-ignore:
- 'README.md'
branches:
- cloudpod_workflow
permissions:
contents: write

jobs:
get-releases:
name: Retrieve Released Cloud Pods
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
output=$(gh api repos/$GITHUB_REPOSITORY/releases | jq -r '[.[].tag_name]')
output=$(echo $output | tr '\n' ' ')
echo "matrix=$output" >> $GITHUB_OUTPUT

test-pod-release:
needs: get-releases
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tag: ${{ fromJson(needs.get-releases.outputs.matrix) }}
steps:
- name: Retrieve Pod
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# TODO the download url seems to follow the pattern $GITHUB_REPOSITORY/releases/download/{TAG}/{ASSET_NAME}
# alternatively we can query the asset-id, and browser_download_url, but it seems like an overhead
# asset_id=$(gh api repos/$GITHUB_REPOSITORY/releases/tags/latest | jq -r '.assets[]' | jq --arg DB $DB -c 'select(.name=="release-pod-\( $DB ).zip") | .id)
# download_url=$(gh api repos/$GITHUB_REPOSITORY/releases/assets/$asset_id | jq -r ".browser_download_url")
download_url="https://github.com/$GITHUB_REPOSITORY/releases/download/${{ matrix.tag }}/release-pod.zip"
curl -L $download_url --output release-pod.zip
ls -la

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Start LocalStack
env:
DEBUG: 1
POD_LOAD_CLI_TIMEOUT: 300
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
DNS_ADDRESS: 0
run: |
export SQS_QUEUE="sqs-fargate-queue"
export NETWORK_NAME="localstack-shared-net"
docker network create $NETWORK_NAME
pip install localstack awscli-local[ver1]
docker pull localstack/localstack-pro:${{ matrix.tag }}
# Start LocalStack in the background
LAMBDA_DOCKER_NETWORK=$NETWORK_NAME DOCKER_FLAGS="--network $NETWORK_NAME" DEBUG=1 localstack start -d
# Wait 30 seconds for the LocalStack container to become ready before timing out
echo "Waiting for LocalStack startup..."
localstack wait -t 30
echo "Startup complete"


- name: Inject Pod
run: |
localstack pod load file://release-pod.zip

# TODO run some tests
- name: Smoke Tests
run: |
# check restored item is still available
actual_count=$(awslocal dynamodb scan --table-name sqs-fargate-ddb-table | jq -r '.Count')
if [ "1" != ${actual_count} ]; then
echo "pod restore failed, expected 1 item in the database"
exit 1
fi

SQS_QUEUE="sqs-fargate-queue"
# try to add additional data
awslocal sqs send-message --queue $SQS_QUEUE --message-body '{"message": "my new message"}'
echo "waiting to process the message..."

# for debugging
echo "docker ps"
docker ps

i=0
actual_count=$(awslocal dynamodb scan --table-name sqs-fargate-ddb-table | jq -r '.Count')
while [ "2" != ${actual_count} ]; do
i=$(( $i+1 ))
if [ 10 -eq ${i} ]; then
echo "pod restore failed, expected 2 items in the database"
exit 1
fi
sleep 3
actual_count=$(awslocal dynamodb scan --table-name sqs-fargate-ddb-table | jq -r '.Count')
done
awslocal dynamodb scan --table-name sqs-fargate-ddb-table | jq -r '.Items[].message.S'

- name: Show Logs
if: always()
run: |
localstack logs

# - name: Send a Slack notification
# if: failure() || github.event_name != 'pull_request'
# uses: ravsamhq/notify-slack-action@v2
# with:
# status: ${{ job.status }}
# token: ${{ secrets.GITHUB_TOKEN }}
# notification_title: "{workflow} has {status_message}"
# message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>"
# footer: "Linked Repo <{repo_url}|{repo}> | <{run_url}|View Workflow run>"
# notify_when: "failure"
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

# - name: Prevent Workflows from getting Stale
# if: always()
# uses: gautamkrishnar/keepalive-workflow@v1
# with:
# this message should prevent automatic triggering of workflows
# see https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
# commit_message: "[skip ci] Automated commit by Keepalive Workflow to keep the repository active"