-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (103 loc) · 4.23 KB
/
nameguard-api-lambda-deploy.yml
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: NameGuard API - Lambda Deploy
on:
push:
branches:
- main
paths:
- 'api/**'
- '.github/workflows/nameguard_api_cicd.yml'
env:
NODE_VERSION: "18.16.0"
TS_VERSION: "4.2.3"
TS_NODE_VERSION: "10.0.0"
permissions:
id-token: write
contents: write
jobs:
build-image-deploy-serverless:
runs-on: ubuntu-20.04
env:
SERVICE_NAME: nameguard
steps:
- name: Checkout this repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup git
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email ''
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE}}
aws-region: us-east-1
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: Build and deploy lambda
run: |
cp ../LICENSE .
npm install -g [email protected]
npm install serverless-prune-plugin
serverless deploy --stage prod --param="PROVIDER_URI_MAINNET=${{secrets.PROVIDER_URI_MAINNET}}" --param="PROVIDER_URI_SEPOLIA=${{secrets.PROVIDER_URI_SEPOLIA}}" --param="ALCHEMY_URI_MAINNET=${{secrets.ALCHEMY_URI_MAINNET}}" --param="ALCHEMY_URI_SEPOLIA=${{secrets.ALCHEMY_URI_SEPOLIA}}" --param="ENS_SUBGRAPH_URL_MAINNET=${{secrets.ENS_SUBGRAPH_URL_MAINNET}}" --param="ENS_SUBGRAPH_URL_SEPOLIA=${{secrets.ENS_SUBGRAPH_URL_SEPOLIA}}"
working-directory: api
- name: Delete old images from ECR
env:
ECR_REPO: serverless-oss-nameguard-prod
run: |
ALL_IMAGES_TO_DELETE=$(aws ecr describe-images --repository-name $ECR_REPO --query 'sort_by(imageDetails,& imagePushedAt)[*].imageDigest' --filter "tagStatus=UNTAGGED" --output json )
len=`echo $ALL_IMAGES_TO_DELETE | jq length`
IMAGES_TO_DELETE=$(aws ecr describe-images --repository-name $ECR_REPO --query 'sort_by(imageDetails,& imagePushedAt)[*].imageDigest' --filter "tagStatus=UNTAGGED" --output json | jq '.[0]')
if [[ $len > 5 ]]; then aws ecr batch-delete-image --repository-name $ECR_REPO --image-ids imageDigest=$IMAGES_TO_DELETE; fi
working-directory: api
notify:
name: Send Slack deployment event notification
if: ${{ needs.build-image-deploy-serverless.result != 'skipped' && always() }}
needs: [build-image-deploy-serverless]
runs-on: ubuntu-20.04
steps:
- name: Output status on deployment success
if: ${{ needs.build-image-deploy-serverless.result == 'success'}}
run: |
echo "STATUS=Success :rocket:" >> $GITHUB_ENV
echo "TEXT=Lambda NameGuard deployed successfully! :white_check_mark:" >> $GITHUB_ENV
- name: Output status on deployment failed
if: ${{ needs.build-image-deploy-serverless.result == 'failure' }}
run: |
echo "STATUS=Failure :x:" >> $GITHUB_ENV
echo "TEXT=Lambda NameGuard deployment failed! :rotating_light:" >> $GITHUB_ENV
- name: Send deployment status Slack notification
uses: 8398a7/action-slack@v3
with:
status: custom
fields: commit,workflow,repo
custom_payload: |
{
attachments: [{
color: '${{ needs.build-image-deploy-serverless.result }}' === 'success' ? 'good' : '${{ needs.build-image-deploy-serverless.result }}' === 'failure' ? 'danger' : 'warning',
title: 'Lambda NameGuard deployment.',
text: '${{ env.TEXT }}',
fields: [
{
title: 'Repository',
value: `${process.env.AS_REPO}`,
short: true
},
{
title: 'Status',
value: '${{ env.STATUS }}',
short: true
},
{
title: 'Workflow',
value: `${process.env.AS_WORKFLOW}`,
short: true
}
]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL}}