Skip to content

Commit 9e5d0f3

Browse files
feat: [sc-25979] Migrate NameGuard from serverless to Terraform deployment (#492)
* Migrated from serverless to terraform * Updated pnpm lock file for serverless removal * Fixed pnpm install and added enhanced timeout --------- Co-authored-by: lightwalker.eth <[email protected]>
1 parent 927f339 commit 9e5d0f3

File tree

10 files changed

+635
-3917
lines changed

10 files changed

+635
-3917
lines changed

.github/workflows/nameguard-api-lambda-deploy.yml

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,33 @@ concurrency:
2323
cancel-in-progress: false
2424

2525
jobs:
26-
build-image-deploy-serverless:
26+
build-image-deploy:
2727
name: Build and deploy NameGuard API Lambda
2828
runs-on: ubuntu-latest
2929
steps:
30-
- name: Checkout NameKit repo
30+
- name: Checkout this repo
3131
uses: actions/checkout@v4
3232

33-
- name: Setup pnpm
34-
uses: pnpm/action-setup@v4
35-
36-
- name: Install Node.js
37-
uses: actions/setup-node@v4
33+
- name: Configure AWS credentials
34+
uses: aws-actions/configure-aws-credentials@v4
3835
with:
39-
node-version-file: .nvmrc
40-
cache: "pnpm"
41-
42-
- name: Install npm dependencies
43-
# We're installing pnpm / node dependencies to make use
44-
# of the Serverless framework when we build and deploy the lambda.
45-
run: pnpm install --frozen-lockfile
46-
36+
role-to-assume: ${{ secrets.AWS_ROLE}}
37+
aws-region: ${{ secrets.AWS_REGION }}
38+
4739
- name: Set up QEMU
48-
# This GitHub action runs on x86_64, but we want to build the lambda
49-
# for arm64 for increased cost savings in AWS when we deploy it.
5040
uses: docker/setup-qemu-action@v3
5141
with:
5242
platforms: arm64
53-
54-
- name: Assume AWS Role
55-
# Uses GitHub OIDC provider to assume AWS role
56-
uses: aws-actions/configure-aws-credentials@v4
43+
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Setup Terraform
48+
uses: hashicorp/setup-terraform@v2
5749
with:
58-
role-to-assume: ${{ secrets.AWS_ROLE}}
59-
aws-region: us-east-1
50+
terraform_version: "1.5.7"
51+
terraform_wrapper: false
52+
6053

6154
- name: Build and deploy lambda
6255
env:
@@ -66,49 +59,47 @@ jobs:
6659
ALCHEMY_URI_SEPOLIA: ${{ secrets.ALCHEMY_URI_SEPOLIA }}
6760
ENS_SUBGRAPH_URL_MAINNET: ${{ secrets.ENS_SUBGRAPH_URL_MAINNET }}
6861
ENS_SUBGRAPH_URL_SEPOLIA: ${{ secrets.ENS_SUBGRAPH_URL_SEPOLIA }}
62+
AWS_REGION: ${{ secrets.AWS_REGION }}
63+
CERTIFICATE_NAME: ${{ secrets.CERTIFICATE_NAME }}
64+
HOSTED_ZONE_NAME: ${{ secrets.HOSTED_ZONE_NAME }}
6965
run: |
7066
if [[ ${{ github.ref }} == 'refs/heads/main' ]]; then
71-
pnpm run deploy:prod
67+
STAGE="prod"
68+
DOMAIN_NAME=${{ secrets.PROD_DOMAIN_NAME }}
7269
elif [[ ${{ github.ref }} == 'refs/heads/staging' ]]; then
73-
pnpm run deploy:staging
70+
STAGE="staging"
71+
DOMAIN_NAME=${{ secrets.STAGING_DOMAIN_NAME }}
7472
else
7573
echo "Deployment is only supported for main and staging branches"
7674
exit 1
7775
fi
78-
working-directory: apps/api.nameguard.io
79-
80-
- name: Delete old images from ECR
81-
env:
82-
ECR_REPO: serverless-oss-nameguard-prod
83-
run: |
84-
ALL_IMAGES_TO_DELETE=$(aws ecr describe-images --repository-name $ECR_REPO --query 'sort_by(imageDetails,& imagePushedAt)[*].imageDigest' --filter "tagStatus=UNTAGGED" --output json )
85-
len=`echo $ALL_IMAGES_TO_DELETE | jq length`
86-
IMAGES_TO_DELETE=$(aws ecr describe-images --repository-name $ECR_REPO --query 'sort_by(imageDetails,& imagePushedAt)[*].imageDigest' --filter "tagStatus=UNTAGGED" --output json | jq '.[0]')
87-
if [[ $len > 5 ]]; then aws ecr batch-delete-image --repository-name $ECR_REPO --image-ids imageDigest=$IMAGES_TO_DELETE; fi
76+
cd terraform
77+
chmod +x ./deploy_lambda.sh
78+
./deploy_lambda.sh $STAGE $AWS_REGION $DOMAIN_NAME $CERTIFICATE_NAME $HOSTED_ZONE_NAME
8879
8980
working-directory: apps/api.nameguard.io
9081

9182
notify:
9283
name: Send Slack deployment event notification
93-
needs: [build-image-deploy-serverless]
84+
needs: [build-image-deploy]
9485
runs-on: ubuntu-latest
9586
steps:
9687
- name: Output status on deployment success
97-
if: ${{ needs.build-image-deploy-serverless.result == 'success'}}
88+
if: ${{ needs.build-image-deploy.result == 'success'}}
9889
run: |
9990
echo "STATUS=Success :rocket:" >> $GITHUB_ENV
10091
echo "TEXT=Lambda NameGuard deployed successfully! :white_check_mark:" >> $GITHUB_ENV
10192
echo "COLOR=good" >> $GITHUB_ENV
10293
10394
- name: Output status on deployment failed
104-
if: ${{ needs.build-image-deploy-serverless.result == 'failure' }}
95+
if: ${{ needs.build-image-deploy.result == 'failure' }}
10596
run: |
10697
echo "STATUS=Failure :x:" >> $GITHUB_ENV
10798
echo "TEXT=Lambda NameGuard deployment failed! :rotating_light:" >> $GITHUB_ENV
10899
echo "COLOR=danger" >> $GITHUB_ENV
109100
110101
- name: Output status on deployment cancellation
111-
if: ${{ needs.build-image-deploy-serverless.result == 'cancelled' }}
102+
if: ${{ needs.build-image-deploy.result == 'cancelled' }}
112103
run: |
113104
echo "STATUS=Cancelled :no_entry_sign:" >> $GITHUB_ENV
114105
echo "TEXT=Lambda NameGuard deployment was cancelled. :warning:" >> $GITHUB_ENV

apps/api.nameguard.io/package.json

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
backend "s3" {} # Will be configured via deploy script
3+
}

0 commit comments

Comments
 (0)