Skip to content

Commit a295496

Browse files
committed
ci: add GitHub Actions workflows for automated Lambda deployments
1 parent 772271a commit a295496

2 files changed

Lines changed: 116 additions & 0 deletions

File tree

.github/workflows/deploy-api.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Deploy API to Lambda
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'api/**'
9+
- '.github/workflows/deploy-api.yml'
10+
workflow_dispatch:
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Configure AWS credentials
21+
uses: aws-actions/configure-aws-credentials@v4
22+
with:
23+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
24+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
25+
aws-region: us-east-1
26+
27+
- name: Login to Amazon ECR
28+
id: login-ecr
29+
uses: aws-actions/amazon-ecr-login@v2
30+
31+
- name: Build and push Docker image
32+
env:
33+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
34+
ECR_REPOSITORY: devsper-registry-api
35+
IMAGE_TAG: ${{ github.sha }}
36+
run: |
37+
cd api
38+
docker buildx build --provenance=false --platform linux/arm64 \
39+
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
40+
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
41+
-f Dockerfile.lambda \
42+
--push .
43+
44+
- name: Update Lambda function
45+
env:
46+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
47+
ECR_REPOSITORY: devsper-registry-api
48+
IMAGE_TAG: ${{ github.sha }}
49+
run: |
50+
aws lambda update-function-code \
51+
--function-name devsper-registry-api \
52+
--image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
53+
54+
- name: Wait for function update to complete
55+
run: |
56+
aws lambda wait function-updated-v2 --function-name devsper-registry-api

.github/workflows/deploy-web.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Deploy Web to Lambda
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'web/**'
9+
- '.github/workflows/deploy-web.yml'
10+
workflow_dispatch:
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Configure AWS credentials
21+
uses: aws-actions/configure-aws-credentials@v4
22+
with:
23+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
24+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
25+
aws-region: us-east-1
26+
27+
- name: Login to Amazon ECR
28+
id: login-ecr
29+
uses: aws-actions/amazon-ecr-login@v2
30+
31+
- name: Build and push Docker image
32+
env:
33+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
34+
ECR_REPOSITORY: devsper-registry-web
35+
IMAGE_TAG: ${{ github.sha }}
36+
run: |
37+
cd web
38+
docker buildx build --provenance=false --platform linux/arm64 \
39+
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
40+
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
41+
-f Dockerfile.lambda \
42+
--push .
43+
44+
- name: Update Lambda function
45+
env:
46+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
47+
ECR_REPOSITORY: devsper-registry-web
48+
IMAGE_TAG: ${{ github.sha }}
49+
run: |
50+
aws lambda update-function-code \
51+
--function-name devsper-registry-web \
52+
--image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
53+
54+
- name: Wait for function update to complete
55+
run: |
56+
aws lambda wait function-updated-v2 --function-name devsper-registry-web
57+
58+
- name: Invalidate CloudFront cache
59+
run: |
60+
aws cloudfront create-invalidation --distribution-id E1OSV9Y9DPR3CY --paths "/*"

0 commit comments

Comments
 (0)