From a41658f9f016ee3eebd750dde9581575af165f97 Mon Sep 17 00:00:00 2001 From: BanaSeba Date: Mon, 7 Oct 2024 15:16:48 +0200 Subject: [PATCH 1/5] Addes staging env for lambda-dpeloy --- .github/workflows/nameguard-api-lambda-deploy.yml | 12 ++++++++++-- api/package.json | 3 ++- api/serverless.yml | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/nameguard-api-lambda-deploy.yml b/.github/workflows/nameguard-api-lambda-deploy.yml index f6718f89a..16dc658f6 100644 --- a/.github/workflows/nameguard-api-lambda-deploy.yml +++ b/.github/workflows/nameguard-api-lambda-deploy.yml @@ -4,7 +4,7 @@ on: push: branches: - main - - ci + - staging paths: - "api/**" - ".github/workflows/nameguard-api-lambda-deploy.yml" @@ -65,7 +65,15 @@ jobs: 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 }} - run: pnpm run deploy:prod + run: | + if [[ ${{ github.ref }} == 'refs/heads/main' ]]; then + pnpm run deploy:prod + elif [[ ${{ github.ref }} == 'refs/heads/staging' ]]; then + pnpm run deploy:staging + else + echo "Deployment is only supported for main and staging branches" + exit 1 + fi working-directory: api - name: Delete old images from ECR diff --git a/api/package.json b/api/package.json index 785ecb9d2..bbea6051a 100644 --- a/api/package.json +++ b/api/package.json @@ -17,7 +17,8 @@ "NameHash" ], "scripts": { - "deploy:prod": "DOCKER_CONFIG=./.docker serverless deploy --stage prod" + "deploy:prod": "DOCKER_CONFIG=./.docker serverless deploy --stage prod", + "deploy:staging": "DOCKER_CONFIG=./.docker serverless deploy --stage staging" }, "dependencies": { "serverless": "3.39.0" diff --git a/api/serverless.yml b/api/serverless.yml index b0fe38f3e..999e3e1e5 100644 --- a/api/serverless.yml +++ b/api/serverless.yml @@ -2,7 +2,7 @@ service: oss-nameguard custom: stage: ${opt:stage} - apiDomain: api.nameguard.io + apiDomain: ${{ self:custom.stage == 'prod' ? 'api.nameguard.io' : 'api-staging.nameguard.io' }} hostedZoneName: nameguard.io. hostedZoneId: Z00825691ZLCWE2VKJQW0 prune: From 14c672c872b193cc85b0f2363cb3b9fb88187536 Mon Sep 17 00:00:00 2001 From: BanaSeba Date: Mon, 7 Oct 2024 15:29:43 +0200 Subject: [PATCH 2/5] Remove condition from yaml --- api/serverless.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/serverless.yml b/api/serverless.yml index 999e3e1e5..628223439 100644 --- a/api/serverless.yml +++ b/api/serverless.yml @@ -1,8 +1,14 @@ service: oss-nameguard +stages: + staging: + alias: api-staging.nameguard.io + prod: + alias: api.nameguard.io + custom: stage: ${opt:stage} - apiDomain: ${{ self:custom.stage == 'prod' ? 'api.nameguard.io' : 'api-staging.nameguard.io' }} + apiDomain: ${self:stages.${self:custom.stage}.alias} hostedZoneName: nameguard.io. hostedZoneId: Z00825691ZLCWE2VKJQW0 prune: From 0618f2ba4e4209c53ae91bf1c76a5fee3401549b Mon Sep 17 00:00:00 2001 From: BanaSeba Date: Mon, 7 Oct 2024 15:38:02 +0200 Subject: [PATCH 3/5] FIxed CF resource initialization --- api/serverless.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/serverless.yml b/api/serverless.yml index 628223439..9c89a5746 100644 --- a/api/serverless.yml +++ b/api/serverless.yml @@ -3,8 +3,12 @@ service: oss-nameguard stages: staging: alias: api-staging.nameguard.io + lambda-role: DefaultNameGuardRoleStaging + lambda-policy-name: NameGuardPolicyStaging prod: alias: api.nameguard.io + lambda-role: DefaultNameGuardRole + lambda-policy-name: NameGuardPolicy custom: stage: ${opt:stage} @@ -55,7 +59,7 @@ resources: Type: AWS::IAM::Role Properties: Path: /my/default/path/ - RoleName: DefaultNameGuardRole # required if you want to use 'serverless deploy --function' later on + RoleName: ${self:stages.${self:custom.stage}.lambda-role} AssumeRolePolicyDocument: Version: "2012-10-17" Statement: @@ -65,7 +69,7 @@ resources: - lambda.amazonaws.com Action: sts:AssumeRole Policies: - - PolicyName: NameGuardPolicy + - PolicyName: ${self:stages.${self:custom.stage}.lambda-policy-name} PolicyDocument: Version: "2012-10-17" Statement: From 798bf36d12ce88b477adee8cd29b77a7a507b650 Mon Sep 17 00:00:00 2001 From: BanaSeba Date: Mon, 7 Oct 2024 16:37:43 +0200 Subject: [PATCH 4/5] Added check before merging to staging --- .github/workflows/nameguard-api-lint.yml | 2 +- .github/workflows/nameguard-api-unit-tests.yml | 1 + .github/workflows/nameguard-end-to-end-tests.yml | 4 ++-- .../workflows/typescript-packages-changesets-npm-release.yml | 2 +- .github/workflows/typescript-packages-unit-tests.yml | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/nameguard-api-lint.yml b/.github/workflows/nameguard-api-lint.yml index 179ee6aa9..23efac281 100644 --- a/.github/workflows/nameguard-api-lint.yml +++ b/.github/workflows/nameguard-api-lint.yml @@ -4,7 +4,7 @@ on: branches: - main pull_request: - branches: ["main"] + branches: ["main", "staging"] jobs: lint: runs-on: ubuntu-latest diff --git a/.github/workflows/nameguard-api-unit-tests.yml b/.github/workflows/nameguard-api-unit-tests.yml index cd64087cd..0b732a4a8 100644 --- a/.github/workflows/nameguard-api-unit-tests.yml +++ b/.github/workflows/nameguard-api-unit-tests.yml @@ -8,6 +8,7 @@ on: pull_request: branches: - main + - staging paths: - "api/**" diff --git a/.github/workflows/nameguard-end-to-end-tests.yml b/.github/workflows/nameguard-end-to-end-tests.yml index 48091bb40..edadf13ca 100644 --- a/.github/workflows/nameguard-end-to-end-tests.yml +++ b/.github/workflows/nameguard-end-to-end-tests.yml @@ -4,7 +4,7 @@ on: push: branches: - main - - ci + - staging paths: - "packages/nameguard-sdk/**" - "api/nameguard/**" @@ -12,7 +12,7 @@ on: pull_request: branches: - main - - ci + - staging paths: - "packages/nameguard-sdk/**" - "api/nameguard/**" diff --git a/.github/workflows/typescript-packages-changesets-npm-release.yml b/.github/workflows/typescript-packages-changesets-npm-release.yml index aed21f35b..7b411e64b 100644 --- a/.github/workflows/typescript-packages-changesets-npm-release.yml +++ b/.github/workflows/typescript-packages-changesets-npm-release.yml @@ -4,7 +4,7 @@ on: push: branches: - main - - ci + - staging paths: - "packages/**" workflow_dispatch: diff --git a/.github/workflows/typescript-packages-unit-tests.yml b/.github/workflows/typescript-packages-unit-tests.yml index f72e02ed4..8d90af908 100644 --- a/.github/workflows/typescript-packages-unit-tests.yml +++ b/.github/workflows/typescript-packages-unit-tests.yml @@ -4,13 +4,13 @@ on: push: branches: - main - - ci + - staging paths: - "packages/**" pull_request: branches: - main - - ci + - staging paths: - "packages/**" From 60fd229e3cb2fa27873c574b510790482d39c69e Mon Sep 17 00:00:00 2001 From: "lightwalker.eth" <126201998+lightwalker-eth@users.noreply.github.com> Date: Mon, 14 Oct 2024 00:50:19 +0300 Subject: [PATCH 5/5] Restrict changesets only to main branch --- .github/workflows/typescript-packages-changesets-npm-release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/typescript-packages-changesets-npm-release.yml b/.github/workflows/typescript-packages-changesets-npm-release.yml index 4f6a8ba0a..c20504bba 100644 --- a/.github/workflows/typescript-packages-changesets-npm-release.yml +++ b/.github/workflows/typescript-packages-changesets-npm-release.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - staging paths: - "packages/**"