Skip to content

Commit 3eebe15

Browse files
authored
create a cloud pods workflow (#10)
* create a cloud pods workflow * fix * fix * last fix * run the workflow only on pushes * add a note about cloud pods in README
1 parent 191b6c6 commit 3eebe15

File tree

4 files changed

+176
-2
lines changed

4 files changed

+176
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ jobs:
8080
- name: Run tests
8181
run: |
8282
pip3 install pytest pandas numpy
83-
pytest tests/
83+
make test

.github/workflows/cloud-pods.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: Create and Test Cloud Pods
2+
3+
on:
4+
schedule:
5+
# At 00:00 on Saturday.
6+
- cron: "0 0 * * 6"
7+
push:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: write
14+
actions: read
15+
16+
jobs:
17+
create-cloud-pod:
18+
name: Create Cloud Pods
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.12'
28+
29+
- name: Install Snow CLI
30+
run: |
31+
pip install snowflake-cli==3.7.2
32+
snow --version
33+
snow connection add \
34+
--connection-name localstack \
35+
--user test \
36+
--password test \
37+
--account test \
38+
--role test \
39+
--warehouse test \
40+
--database test \
41+
--schema test \
42+
--port 4566 \
43+
--host snowflake.localhost.localstack.cloud \
44+
--no-interactive
45+
snow connection list
46+
47+
- name: Install dependencies
48+
run: |
49+
make install
50+
51+
- name: Start LocalStack
52+
uses: LocalStack/setup-localstack@main
53+
with:
54+
image-tag: 'latest'
55+
use-pro: 'true'
56+
configuration: LS_LOG=trace
57+
install-awslocal: 'true'
58+
env:
59+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
60+
IMAGE_NAME: localstack/snowflake:latest
61+
62+
- name: Create Snowflake resources
63+
run: |
64+
make seed
65+
66+
- name: Create AWS resources
67+
run: |
68+
make aws
69+
make upload
70+
71+
- name: Run dbt models
72+
run: |
73+
make dbt
74+
75+
- name: Deploy Native App
76+
run: |
77+
make app
78+
79+
- name: Create Cloud Pod
80+
env:
81+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
82+
run: |
83+
message="Cloud Pod created: smart-factory-app on $(date) with workflow run id: ${{ github.run_id }}"
84+
localstack pod save smart-factory-app --message "$message"
85+
86+
- name: Show LocalStack Logs
87+
if: always()
88+
run: |
89+
localstack logs
90+
91+
test-cloud-pod:
92+
name: Test Cloud Pod
93+
needs: create-cloud-pod
94+
runs-on: ubuntu-latest
95+
steps:
96+
- name: Checkout Code
97+
uses: actions/checkout@v4
98+
99+
- name: Start LocalStack
100+
uses: LocalStack/setup-localstack@main
101+
with:
102+
use-pro: 'true'
103+
install-awslocal: 'true'
104+
env:
105+
DEBUG: 1
106+
IMAGE_NAME: localstack/snowflake:latest
107+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
108+
109+
- name: Load Cloud Pod
110+
env:
111+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
112+
run: |
113+
localstack pod load smart-factory-app
114+
115+
- name: Install dependencies
116+
run: |
117+
make install
118+
119+
- name: Run Tests
120+
run: |
121+
pip3 install pytest pandas numpy snowflake-connector-python
122+
pytest tests/
123+
124+
- name: Show LocalStack Logs
125+
if: always()
126+
run: |
127+
localstack logs
128+
129+
- name: Generate a Diagnostic Report
130+
if: failure()
131+
run: |
132+
curl -s localhost:4566/_localstack/diagnose | gzip -cf > diagnose.json.gz
133+
134+
- name: Upload the Diagnostic Report
135+
if: failure()
136+
uses: actions/upload-artifact@v4
137+
with:
138+
name: diagnose.json.gz
139+
path: ./diagnose.json.gz

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export AWS_ACCESS_KEY_ID ?= test
22
export AWS_SECRET_ACCESS_KEY ?= test
33
export AWS_DEFAULT_REGION=us-east-1
4+
export DBT_WARN_ERROR_OPTIONS={"silence": ["UnusedResourceConfigPath", "NoNodesForSelectionCriteria"]}
45
SHELL := /bin/bash
56

67
# Flag to control which batch file to upload (default: false = use batch 1, true = use latest batch)
@@ -59,7 +60,7 @@ pipeline: ## Setup Dagster pipeline
5960

6061
dbt: ## Run dbt models
6162
@echo "Running dbt..."
62-
bash -c "source env/bin/activate && dbt build --profile localstack"
63+
bash -c "source env/bin/activate && dbt run --profile localstack"
6364
@echo "Dbt run successfully."
6465

6566
app: ## Run Snowflake Native App
@@ -70,6 +71,11 @@ app: ## Run Snowflake Native App
7071
@printf " └─ URL: \033[4;94mhttps://snowflake.localhost.localstack.cloud:4566/apps/test/test/FACTORY_APP_$$(whoami | tr '[:lower:]' '[:upper:]')/\033[0m\n"
7172
@echo ""
7273

74+
streamlit: ## Run Streamlit app
75+
@echo "Running Streamlit app..."
76+
cd app/src/module-ui/src && streamlit run ui.py
77+
@echo "Streamlit app run successfully."
78+
7379
deploy: ## Deploy the entire stack
7480
@echo "Deploying the entire stack..."
7581
make seed
@@ -95,6 +101,9 @@ alerts: ## Setup alerts
95101

96102
test: ## Run tests
97103
@echo "Running tests..."
104+
@echo "Running dbt tests..."
105+
bash -c "source env/bin/activate && dbt test --profile localstack"
106+
@echo "Running pytest integration tests..."
98107
bash -c "source env/bin/activate && pytest tests/"
99108
@echo "Tests run successfully."
100109

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,32 @@ This showcases:
201201
- Point-in-time recovery scenarios
202202
- Disaster recovery best practices
203203

204+
### Test Data Management with Cloud Pods
205+
206+
Cloud Pods enable persistent state snapshots of your LocalStack instance that can be easily stored, versioned, shared, and restored across development teams and CI/CD environments.
207+
208+
To save a Cloud Pod, run the following command:
209+
210+
```bash
211+
localstack pod save smart-factory-app
212+
```
213+
214+
To load a Cloud Pod, run the following command:
215+
216+
```bash
217+
# Restore the saved state in a fresh LocalStack instance
218+
localstack pod load smart-factory-app
219+
```
220+
221+
The key advantages are:
222+
223+
- Pre-seed CI environments with complex factory data, Snowflake schemas, and S3 assets in seconds
224+
- Share identical test scenarios across development teams for consistent debugging
225+
- Guarantee the same test data state across different pipeline runs and environments
226+
- Capture problematic states for collaborative debugging and issue reproduction
227+
228+
For automated Cloud Pods management in CI/CD pipelines, check out the sample workflow in [`.github/workflows/cloud-pods.yml`](.github/workflows/cloud-pods.yml).
229+
204230
## License
205231

206232
This project is licensed under the [Apache License 2.0](LICENSE).

0 commit comments

Comments
 (0)