Skip to content
Merged
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
41 changes: 36 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy on LocalStack
name: Setup infrastructure using CDK

on:
push:
Expand All @@ -16,7 +16,7 @@ on:

jobs:
cdk:
name: Setup infrastructure using CDK
name: Run Integration Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -25,12 +25,12 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20
node-version: 22

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'

- name: Install CDK
run: |
Expand All @@ -55,4 +55,35 @@ jobs:

- name: Run tests
run: |
make run
make test

- name: Show LocalStack logs
if: always()
run: |
make logs
cat logs.txt

- 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: Generate a Diagnostic Report
if: failure()
run: |
curl -s localhost:4566/_localstack/diagnose | gzip -cf > diagnose.json.gz

- name: Upload the Diagnostic Report
if: failure()
uses: actions/upload-artifact@v4
with:
name: diagnose.json.gz
path: ./diagnose.json.gz
17 changes: 17 additions & 0 deletions .github/workflows/keepalive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Keep Alive
on:
schedule:
- cron: "0 0 * * *"
jobs:
main-job:
name: Main Job
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
workflow-keepalive:
if: github.event_name == 'schedule'
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- uses: liskin/gh-workflow-keepalive@v1
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
.venv/
volume/
cdk.out
dms_sample
__pycache__/
cdk.local.out/
36 changes: 27 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SHELL := /bin/bash

VENV_BIN ?= python3 -m venv
VENV_DIR ?= .venv
PIP_CMD ?= pip3
Expand Down Expand Up @@ -33,28 +35,44 @@ $(VENV_ACTIVATE):

venv: $(VENV_ACTIVATE) ## Create a new (empty) virtual environment

start:
$(LOCAL_ENV) docker compose up --build --detach --wait
check: ## Check if all required prerequisites are available
@command -v docker > /dev/null 2>&1 || { echo "Docker is not installed."; exit 1; }
@command -v localstack > /dev/null 2>&1 || { echo "LocalStack is not installed."; exit 1; }
@command -v python > /dev/null 2>&1 || { echo "Python is not installed."; exit 1; }
@command -v cdk > /dev/null 2>&1 || { echo "AWS CDK is not installed."; exit 1; }
@command -v cdklocal > /dev/null 2>&1 || { echo "CDK Local is not installed."; exit 1; }
@echo "All required prerequisites are available."

start: ## Start localstack
$(LOCAL_ENV) LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) docker compose up --build --detach --wait

install: venv
install: venv ## Install dependencies
$(VENV_RUN); $(PIP_CMD) install -r requirements.txt

deploy:
deploy: ## Deploy the stack on LocalStack
$(VENV_RUN); $(LOCAL_ENV) cdklocal bootstrap --output ./cdk.local.out
$(VENV_RUN); $(LOCAL_ENV) cdklocal deploy --require-approval never --output ./cdk.local.out

deploy-aws:
deploy-aws: ## Deploy the stack on AWS
$(VENV_RUN); $(CLOUD_ENV) cdk bootstrap
$(VENV_RUN); $(CLOUD_ENV) cdk deploy --require-approval never

destroy:
stop: ## Stop LocalStack
docker-compose down

destroy-aws: venv
destroy-aws: venv ## Destroy the stack on AWS
$(VENV_RUN); $(CLOUD_ENV) cdk destroy --require-approval never

run:
run: ## Run the application on LocalStack
$(VENV_RUN); $(LOCAL_ENV) python run.py

run-aws:
run-aws: ## Run the application on AWS
$(VENV_RUN); $(CLOUD_ENV) python run.py

test: ## Test the application on LocalStack
$(VENV_RUN); $(LOCAL_ENV) pytest tests/test_infra.py

logs: ## Show logs from LocalStack
@docker logs localstack-main > logs.txt

.PHONY: usage install start deploy test logs stop deploy-aws test-aws destroy-aws
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from dms_sample.stack import DmsSampleStack

STACK_NAME = os.getenv("STACK_NAME", "")
STACK_NAME = os.getenv("STACK_NAME", "DMsSampleSetupStack")

app = cdk.App()
DmsSampleStack(app, STACK_NAME)
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ aws-cdk-lib==2.138.0
boto3==1.34.96
constructs>=10.0.0,<11.0.0
cryptography==42.0.5
pymysql==1.1.0
pymysql==1.1.0
pytest
Loading