Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [sc-25983] Prepare NameRank for transition into Monorepo #513

Merged
merged 10 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/nameguard-api-lambda-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ jobs:
cd terraform
chmod +x ./deploy_lambda.sh
./deploy_lambda.sh $STAGE $AWS_REGION $DOMAIN_NAME $CERTIFICATE_NAME $HOSTED_ZONE_NAME

working-directory: apps/api.nameguard.io

notify:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/nameguard-python-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: NameGuard Python - Lint
on:
push:
branches:
- main
paths:
- "packages/nameguard-python/**"
pull_request:
branches: ["main", "staging"]
paths:
- "packages/nameguard-python/**"

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout NameKit repo
uses: actions/checkout@v4

- name: Ruff Check
uses: chartboost/ruff-action@v1
with:
version: 0.6.7
src: "./packages/nameguard-python"

- name: Ruff Format
uses: chartboost/ruff-action@v1
with:
version: 0.6.7
args: "format --check"
src: "./packages/nameguard-python"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: NameGuard API - PyPI Package Release
name: NameGuard Python - PyPI Package Release

on:
release:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nameguard-python-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: NameGuard API - Unit Tests
name: NameGuard Python - Unit Tests
on:
schedule:
- cron: '0 5 * * 0'
Expand Down
138 changes: 138 additions & 0 deletions .github/workflows/namerank-api-lambda-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: NameRank API - Lambda Deploy

on:
push:
branches:
- main
- staging
paths:
- "packages/namerank-python/**"
- "apps/api.namerank.io/**"
- ".github/workflows/namerank-api-lambda-deploy.yml"
workflow_dispatch:

permissions:
# `id-token: write` is required for the auth to AWS
id-token: write
contents: read

concurrency:
group: ${{ github.workflow }}
# `cancel-in-progress: false` creates a queue for workflow runs, such that
# only one instance of this workflow runs at a time.
cancel-in-progress: false

jobs:
build-image-deploy:
name: Build and deploy NameRank API Lambda
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE}}
aws-region: ${{ secrets.AWS_REGION }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: "1.5.7"
terraform_wrapper: false


- name: Build and deploy lambda
env:
PROVIDER_URI_MAINNET: ${{ secrets.PROVIDER_URI_MAINNET }}
PROVIDER_URI_SEPOLIA: ${{ secrets.PROVIDER_URI_SEPOLIA }}
ALCHEMY_URI_MAINNET: ${{ secrets.ALCHEMY_URI_MAINNET }}
ALCHEMY_URI_SEPOLIA: ${{ secrets.ALCHEMY_URI_SEPOLIA }}
ENS_SUBGRAPH_URL_MAINNET: ${{ secrets.ENS_SUBGRAPH_URL_MAINNET }}
ENS_SUBGRAPH_URL_SEPOLIA: ${{ secrets.ENS_SUBGRAPH_URL_SEPOLIA }}
AWS_REGION: ${{ secrets.AWS_REGION }}
CERTIFICATE_NAME: ${{ secrets.NAMERANK_CERTIFICATE_NAME }}
HOSTED_ZONE_NAME: ${{ secrets.NAMERANK_HOSTED_ZONE_NAME }}
run: |
if [[ ${{ github.ref }} == 'refs/heads/main' ]]; then
STAGE="prod"
DOMAIN_NAME=${{ secrets.NAMERANK_PROD_DOMAIN_NAME }}
elif [[ ${{ github.ref }} == 'refs/heads/staging' ]]; then
STAGE="staging"
DOMAIN_NAME=${{ secrets.NAMERANK_STAGING_DOMAIN_NAME }}
else
echo "Deployment is only supported for main and staging branches"
exit 1
fi
cd terraform
chmod +x ./deploy_lambda.sh
./deploy_lambda.sh $STAGE $AWS_REGION $DOMAIN_NAME $CERTIFICATE_NAME $HOSTED_ZONE_NAME
working-directory: apps/api.namerank.io

notify:
name: Send Slack deployment event notification
needs: [build-image-deploy]
runs-on: ubuntu-latest
steps:
- name: Output status on deployment success
if: ${{ needs.build-image-deploy.result == 'success'}}
run: |
echo "STATUS=Success :rocket:" >> $GITHUB_ENV
echo "TEXT=Lambda NameRank deployed successfully! :white_check_mark:" >> $GITHUB_ENV
echo "COLOR=good" >> $GITHUB_ENV

- name: Output status on deployment failed
if: ${{ needs.build-image-deploy.result == 'failure' }}
run: |
echo "STATUS=Failure :x:" >> $GITHUB_ENV
echo "TEXT=Lambda NameRank deployment failed! :rotating_light:" >> $GITHUB_ENV
echo "COLOR=danger" >> $GITHUB_ENV

- name: Output status on deployment cancellation
if: ${{ needs.build-image-deploy.result == 'cancelled' }}
run: |
echo "STATUS=Cancelled :no_entry_sign:" >> $GITHUB_ENV
echo "TEXT=Lambda NameRank deployment was cancelled. :warning:" >> $GITHUB_ENV
echo "COLOR=warning" >> $GITHUB_ENV

- name: Send deployment status Slack notification
uses: 8398a7/action-slack@v3
with:
status: custom
fields: commit,workflow,repo
custom_payload: |
{
attachments: [{
color: '${{ env.COLOR }}',
title: 'Lambda NameRank 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}}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: NameGuard API - Lint
name: NameRank Python - Lint
on:
push:
branches:
- main
paths:
- "apps/api.namerank.io/**"
pull_request:
branches: ["main", "staging"]
paths:
- "apps/api.namerank.io/**"

jobs:
lint:
runs-on: ubuntu-latest
Expand All @@ -15,10 +20,12 @@ jobs:
- name: Ruff Check
uses: chartboost/ruff-action@v1
with:
version: 0.1.8
version: 0.6.7
src: "./apps/api.namerank.io"

- name: Ruff Format
uses: chartboost/ruff-action@v1
with:
version: 0.1.8
version: 0.6.7
args: "format --check"
src: "./apps/api.namerank.io"
44 changes: 44 additions & 0 deletions .github/workflows/namerank-python-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: NameRank Python - Unit Tests

on:
push:
branches:
- main
paths:
- "apps/api.namerank.io/**"
pull_request:
branches:
- main
- staging
paths:
- "apps/api.namerank.io/**"

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.10", "3.11", "3.12"]

steps:
- name: Checkout NameKit repo
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"

- name: Install dependencies
working-directory: ./apps/api.namerank.io
run: poetry install --extras "lambda"

- name: Run tests
working-directory: ./apps/api.namerank.io
run: poetry run pytest -vv
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ __pycache__
.turbo
.next
.vercel
.pytest_cache
.ruff_cache

*storybook.log
storybook-static
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ repos:
hooks:
- id: ruff
args: [ --fix ]
files: '^packages/nameguard-python/.*\.py'
files: '^(packages/nameguard-python|apps/api.namerank.io)/.*\.py'
- id: ruff-format
files: '^packages/nameguard-python/.*\.py'
files: '^(packages/nameguard-python|apps/api.namerank.io)/.*\.py'
3 changes: 3 additions & 0 deletions apps/api.namerank.io/.docker/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"credsStore": "ecr-login"
}
21 changes: 21 additions & 0 deletions apps/api.namerank.io/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Provider URIs (can be any Ethereum node, e.g. Infura, Alchemy, your own node, etc.).
# The following example values are rate limited.
# Sign up for your own node provider (e.g. Infura, Alchemy, etc.) to remove rate limits.
PROVIDER_URI_MAINNET=https://rpc.ankr.com/eth
PROVIDER_URI_SEPOLIA=https://rpc.ankr.com/eth_sepolia

# Alchemy API URIs (needed for their NFT API for NameGuard's fake ENS NFT checks)
# Replace [YOUR_ALCHEMY_API_KEY] with your actual Alchemy API key).
# Sign up for a free account at https://www.alchemy.com/
ALCHEMY_URI_MAINNET=https://eth-mainnet.g.alchemy.com/v2/[YOUR_ALCHEMY_API_KEY]
ALCHEMY_URI_SEPOLIA=https://eth-sepolia.g.alchemy.com/v2/[YOUR_ALCHEMY_API_KEY]

# ENS Subgraph URLs
# The following example values are rate limited.
# You're highly encouraged to sign up for your own API key.
# For more details, see:
# - https://docs.ens.domains/web/subgraph
# - https://discuss.ens.domains/t/ens-subgraph-migration-to-the-decentralised-version/19183
# - https://thegraph.com/explorer/subgraphs/5XqPmWe6gjyrJtFn9cLy237i4cWw2j9HcUJEXsP5qGtH?view=Query&chain=arbitrum-one
ENS_SUBGRAPH_URL_MAINNET=https://api.thegraph.com/subgraphs/name/ensdomains/ens
ENS_SUBGRAPH_URL_SEPOLIA=https://api.studio.thegraph.com/query/49574/enssepolia/version/latest
7 changes: 7 additions & 0 deletions apps/api.namerank.io/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM --platform=linux/arm64 public.ecr.aws/lambda/python:3.11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make sense to move the responsibility of setting arm64 to the deployment script.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we ever using any other platform than arm64? I would expect that any testing/deployment for this lambda will be done only for arm64

WORKDIR /app
RUN yum install gcc -y
COPY pyproject.toml poetry.lock LICENSE README.md ./
COPY namerank ./namerank/
RUN pip install --no-cache-dir .[lambda]
CMD [ "namerank.root_api.handler" ]
21 changes: 21 additions & 0 deletions apps/api.namerank.io/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 NameHash

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading