Skip to content

Commit 3bbda16

Browse files
authored
Merge pull request #4 from localstack/gh-actions
add github actions to run infrastructure create on LS
2 parents 3677f62 + 96fa3c2 commit 3bbda16

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

.github/workflows/ci.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Create Infra on LocalStack
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'README.md'
7+
branches:
8+
- master
9+
pull_request:
10+
branches:
11+
- master
12+
schedule:
13+
# “At 00:00 on Sunday.”
14+
- cron: "0 0 * * 0"
15+
workflow_dispatch:
16+
17+
jobs:
18+
infrastructure-check:
19+
name: Setup infrastructure using Terraform
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- name: Setup Python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.9'
29+
30+
- name: Set up JDK
31+
uses: actions/setup-java@v2
32+
with:
33+
distribution: 'temurin'
34+
java-version: '17'
35+
36+
- name: Set up Maven
37+
run: sudo apt-get install -y maven
38+
39+
- name: Install localstack & awslocal
40+
run: |
41+
pip install localstack
42+
pip install terraform-local
43+
pip install awscli-local
44+
45+
- name: Build project
46+
run: |
47+
cd shipment-picture-lambda-validator
48+
mvn clean package shade:shade
49+
50+
- name: Start LocalStack
51+
run: |
52+
docker pull localstack/localstack:latest
53+
# Start LocalStack in the background
54+
LS_LOG=trace localstack start -d
55+
# Wait 30 seconds for the LocalStack container to become ready before timing out
56+
echo "Waiting for LocalStack startup..."
57+
localstack wait -t 15
58+
echo "Startup complete"
59+
60+
- name: Run Terraform Config File
61+
run: |
62+
cd terraform
63+
bash run-tflocal.sh
64+
65+
- name: Check for Bucket
66+
run: |
67+
output=$(awslocal s3api list-buckets --query "Buckets[?contains(Name, 'shipment-picture-bucket')].Name" --output text)
68+
if [ -z "$output" ]; then
69+
echo "Created bucket not found."
70+
exit 1
71+
else echo "Bucket with random name was found: $output"
72+
fi
73+
74+
- name: Send a Slack notification
75+
if: failure() || github.event_name != 'pull_request'
76+
uses: ravsamhq/notify-slack-action@v2
77+
with:
78+
status: ${{ job.status }}
79+
token: ${{ secrets.GITHUB_TOKEN }}
80+
notification_title: "{workflow} has {status_message}"
81+
message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>"
82+
footer: "Linked Repo <{repo_url}|{repo}> | <{run_url}|View Workflow run>"
83+
notify_when: "failure"
84+
env:
85+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
86+
87+
- name: Generate a Diagnostic Report
88+
if: failure()
89+
run: |
90+
curl -s localhost:4566/_localstack/diagnose | gzip -cf > diagnose.json.gz
91+
92+
- name: Upload the Diagnostic Report
93+
if: failure()
94+
uses: actions/upload-artifact@v3
95+
with:
96+
name: diagnose.json.gz
97+
path: ./diagnose.json.gz

terraform/run-tflocal.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tflocal init
2+
tflocal plan
3+
tflocal apply --auto-approve

0 commit comments

Comments
 (0)