Skip to content

Commit 231d4b6

Browse files
Added Github Actions CI pipeline
1 parent 3663fbc commit 231d4b6

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

‎.github/workflows/deploy.yml‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Deploy Portfolio to AWS
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
AWS_REGION: ap-south-1
10+
11+
jobs:
12+
terraform:
13+
name: Provision Infrastructure
14+
run-on: ubuntu-latest
15+
outpust:
16+
api_gateway_url: ${{ steps.tf_outputs.outputs.api_gateway_url }}
17+
s3_bucket_name: ${{ steps.tf_outputs.ouputs.s3_bucket_name }}
18+
lambda_function_name: ${{ steps.tf_outputs.outputs.lambda_function_name }}
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Configure AWS Credentials
25+
uses: aws-actions/configure-aws-credentials@v4
26+
with:
27+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
28+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
29+
aws-region: ${{ env.AWS_REGION }}
30+
31+
- name: Setup Terraform
32+
uses: hashicorp/setup-terraform@v3
33+
with:
34+
terraform_wrapper: false
35+
36+
- name: Terraform Init
37+
working-directory: infrastructure
38+
run: terraform init
39+
40+
- name: Terraform Apply
41+
working-directory: infrastructure
42+
run: |
43+
terraform apply -auto-approve \
44+
-var="sender_email=${{ secrets.SENDER_EMAIL }}" \
45+
-var="recipient_email=${{ secrets.RECIPIENT_EMAIL }}"
46+
47+
- name: Capture Terraform outputs
48+
id: tf_outputs
49+
working-directory: infrastructure
50+
run: |
51+
echo "api_gateway_url=$(terraform output -raw api_gateway_url)" >> $GITHUB_OUTPUT
52+
echo "s3_bucket_name=$(terraform output -raw s3_bucket_name)" >> $GITHUB_OUTPUT
53+
echo "lambda_function_name=$(terraform output -raw lambda_function_name)" >> $GITHUB_OUTPUT
54+
55+
deploy-frontend:
56+
name: Build and Deploy Frontend
57+
runs-on: ubuntu-latest
58+
needs: terraform
59+
60+
steps:
61+
- name: Checkout code
62+
uses: actions/checkout@v4
63+
64+
- name: Configure AWS Credentials
65+
uses: aws-actions/configure-aws-credentials@v4
66+
with:
67+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
68+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
69+
aws-region: ${{ secrets.AWS_REGION }}
70+
71+
- name: Setup Node.js
72+
uses: actions/setup-node@v4
73+
with:
74+
node-version: '20'
75+
76+
- name: Install dependencies
77+
working-directory: client
78+
run: npm ci
79+
80+
- name: Build Next.js static export
81+
env:
82+
NEXT_PUBLIC_API_URL: ${{ needs.terraform.outputs.api_gateway_url }}
83+
run: npm run build
84+
85+
- name: Sync to S3
86+
run: |
87+
aws s3 sync client/out/ s3://${{ needs. terraform.outputs.s3_bucket_name }}/ --delete
88+
89+
deploy-lambda:
90+
name: Deploy Lambda Function
91+
runs-on: ubuntu-latest
92+
needs: terraform
93+
94+
steps:
95+
- name: Checkout code
96+
uses: actions/checkout@v4
97+
98+
- name: Configure AWS Credentials
99+
uses: aws-actions/configure-aws-credentials@v4
100+
with:
101+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
102+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
103+
aws-region: ${{ secrets.AWS_REGION }}
104+
105+
- name: Package Lambda Function
106+
run: zip -j lambda.zip lambda/handler.py
107+
108+
- name: Deploy Lambda Function
109+
run: |
110+
aws lambda update-function-code \
111+
--function-name ${{ needs.terraform.outputs.lambda_function_name }} \
112+
--zip-file fileb://lambda.zip

0 commit comments

Comments
 (0)