-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (66 loc) · 2.89 KB
/
main.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Deploy to AWS Lambda
on:
push:
branches:
- deploy
- develop
pull_request:
branches:
- deploy
- develop
workflow_dispatch:
branches:
- deploy
- develop
jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_IAM_ROLE_ARN: ${{ secrets.AWS_IAM_ROLE_ARN }}
OWNER_LAYER_ACCOUNT_ID: ${{ secrets.OWNER_LAYER_ACCOUNT_ID }}
steps:
- name: Check if it's a merge commit
run: |
if [ -n "$(git log -1 --merges --pretty=%B)" ]; then
echo "This is a merge commit. Skipping the workflow."
exit 78
fi
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-1
- name: Update Code
run: |
npm install
npm run prisma_gen
npm run build
cp src/prisma/ERD.svg dist/prisma/ERD.svg
cp src/prisma/schema.prisma dist/prisma/schema.prisma
cp -r src/prisma_modules dist/prisma_modules
zip -r code.zip dist
aws lambda update-function-code --function-name images-social-backend-service --zip-file fileb://code.zip
aws s3 cp ${GITHUB_WORKSPACE}/code.zip s3://image-social-backend-server-source/code.zip
- name: Update Node Modules
run: |
mkdir nodejs
cp package.json nodejs/package.json
cd nodejs
npm install --omit=dev
rm package.json package-lock.json
cd ..
zip -r ${GITHUB_WORKSPACE}/package-layer.zip nodejs
aws s3 cp ${GITHUB_WORKSPACE}/package-layer.zip s3://images-social-backend-service-package-layer/package-layer.zip
aws lambda publish-layer-version --layer-name arn:aws:lambda:ap-southeast-1:${OWNER_LAYER_ACCOUNT_ID}:layer:images-social-backend-service-package-layer --content S3Bucket=images-social-backend-service-package-layer,S3Key=package-layer.zip --compatible-runtimes nodejs16.x --compatible-architectures "arm64" "x86_64"
maxLayerVersion=$(aws lambda list-layer-versions --layer-name arn:aws:lambda:ap-southeast-1:${OWNER_LAYER_ACCOUNT_ID}:layer:images-social-backend-service-package-layer --query 'max_by(LayerVersions, &Version).LayerVersionArn' | sed 's/"//g')
aws lambda wait function-updated --function-name images-social-backend-service
aws lambda update-function-configuration --function-name images-social-backend-service --layers $maxLayerVersion