Skip to content

Commit 284e539

Browse files
authored
revamp the application ci & makefile (#4)
* revamp the application ci & makefile * fix auth token makefile * extra steps to report failure and show logs * add proper tests using pytest * add a keepalive workflow * stupid fix * reformat * rename the workflow
1 parent 2dc98a3 commit 284e539

File tree

7 files changed

+805
-16
lines changed

7 files changed

+805
-16
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy on LocalStack
1+
name: Setup infrastructure using CDK
22

33
on:
44
push:
@@ -16,7 +16,7 @@ on:
1616

1717
jobs:
1818
cdk:
19-
name: Setup infrastructure using CDK
19+
name: Run Integration Tests
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Checkout
@@ -25,12 +25,12 @@ jobs:
2525
- name: Setup Node.js
2626
uses: actions/setup-node@v3
2727
with:
28-
node-version: 20
28+
node-version: 22
2929

3030
- name: Install Python
3131
uses: actions/setup-python@v4
3232
with:
33-
python-version: '3.10'
33+
python-version: '3.11'
3434

3535
- name: Install CDK
3636
run: |
@@ -55,4 +55,35 @@ jobs:
5555
5656
- name: Run tests
5757
run: |
58-
make run
58+
make test
59+
60+
- name: Show LocalStack logs
61+
if: always()
62+
run: |
63+
make logs
64+
cat logs.txt
65+
66+
- name: Send a Slack notification
67+
if: failure() || github.event_name != 'pull_request'
68+
uses: ravsamhq/notify-slack-action@v2
69+
with:
70+
status: ${{ job.status }}
71+
token: ${{ secrets.GITHUB_TOKEN }}
72+
notification_title: "{workflow} has {status_message}"
73+
message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>"
74+
footer: "Linked Repo <{repo_url}|{repo}> | <{run_url}|View Workflow run>"
75+
notify_when: "failure"
76+
env:
77+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
78+
79+
- name: Generate a Diagnostic Report
80+
if: failure()
81+
run: |
82+
curl -s localhost:4566/_localstack/diagnose | gzip -cf > diagnose.json.gz
83+
84+
- name: Upload the Diagnostic Report
85+
if: failure()
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: diagnose.json.gz
89+
path: ./diagnose.json.gz

.github/workflows/keepalive.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Keep Alive
2+
on:
3+
schedule:
4+
- cron: "0 0 * * *"
5+
jobs:
6+
main-job:
7+
name: Main Job
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
workflow-keepalive:
12+
if: github.event_name == 'schedule'
13+
runs-on: ubuntu-latest
14+
permissions:
15+
actions: write
16+
steps:
17+
- uses: liskin/gh-workflow-keepalive@v1

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
.venv/
22
volume/
3+
cdk.out
4+
dms_sample
5+
__pycache__/
6+
cdk.local.out/

Makefile

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
SHELL := /bin/bash
2+
13
VENV_BIN ?= python3 -m venv
24
VENV_DIR ?= .venv
35
PIP_CMD ?= pip3
@@ -33,28 +35,44 @@ $(VENV_ACTIVATE):
3335

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

36-
start:
37-
$(LOCAL_ENV) docker compose up --build --detach --wait
38+
check: ## Check if all required prerequisites are available
39+
@command -v docker > /dev/null 2>&1 || { echo "Docker is not installed."; exit 1; }
40+
@command -v localstack > /dev/null 2>&1 || { echo "LocalStack is not installed."; exit 1; }
41+
@command -v python > /dev/null 2>&1 || { echo "Python is not installed."; exit 1; }
42+
@command -v cdk > /dev/null 2>&1 || { echo "AWS CDK is not installed."; exit 1; }
43+
@command -v cdklocal > /dev/null 2>&1 || { echo "CDK Local is not installed."; exit 1; }
44+
@echo "All required prerequisites are available."
45+
46+
start: ## Start localstack
47+
$(LOCAL_ENV) LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN) docker compose up --build --detach --wait
3848

39-
install: venv
49+
install: venv ## Install dependencies
4050
$(VENV_RUN); $(PIP_CMD) install -r requirements.txt
4151

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

46-
deploy-aws:
56+
deploy-aws: ## Deploy the stack on AWS
4757
$(VENV_RUN); $(CLOUD_ENV) cdk bootstrap
4858
$(VENV_RUN); $(CLOUD_ENV) cdk deploy --require-approval never
4959

50-
destroy:
60+
stop: ## Stop LocalStack
5161
docker-compose down
5262

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

56-
run:
66+
run: ## Run the application on LocalStack
5767
$(VENV_RUN); $(LOCAL_ENV) python run.py
5868

59-
run-aws:
69+
run-aws: ## Run the application on AWS
6070
$(VENV_RUN); $(CLOUD_ENV) python run.py
71+
72+
test: ## Test the application on LocalStack
73+
$(VENV_RUN); $(LOCAL_ENV) pytest tests/test_infra.py
74+
75+
logs: ## Show logs from LocalStack
76+
@docker logs localstack-main > logs.txt
77+
78+
.PHONY: usage install start deploy test logs stop deploy-aws test-aws destroy-aws

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from dms_sample.stack import DmsSampleStack
55

6-
STACK_NAME = os.getenv("STACK_NAME", "")
6+
STACK_NAME = os.getenv("STACK_NAME", "DMsSampleSetupStack")
77

88
app = cdk.App()
99
DmsSampleStack(app, STACK_NAME)

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ aws-cdk-lib==2.138.0
22
boto3==1.34.96
33
constructs>=10.0.0,<11.0.0
44
cryptography==42.0.5
5-
pymysql==1.1.0
5+
pymysql==1.1.0
6+
pytest

0 commit comments

Comments
 (0)