From 218180dd0f46aeff6502632cc4fcb5ae838eb90e Mon Sep 17 00:00:00 2001 From: KONFeature Date: Tue, 28 May 2024 23:56:44 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Use=20sst=20secrets=20within=20t?= =?UTF-8?q?he=20ponder.config,=20use=20prebuilt=20docker=20image=20from?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-submodule.yml | 61 -------------------------- .github/workflows/deploy.yml | 52 +++++++++++++++++----- Dockerfile.prebuilt | 7 +++ ponder.config.ts | 26 ++++++++--- sst-env.d.ts | 1 + sst.config.ts | 5 ++- 6 files changed, 71 insertions(+), 81 deletions(-) delete mode 100644 .github/workflows/deploy-submodule.yml create mode 100644 Dockerfile.prebuilt create mode 100644 sst-env.d.ts diff --git a/.github/workflows/deploy-submodule.yml b/.github/workflows/deploy-submodule.yml deleted file mode 100644 index 0989113..0000000 --- a/.github/workflows/deploy-submodule.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: "🚀 Deploy submodule" - -on: - workflow_call: - inputs: - runner-label: - required: false - type: string - pr-sha: - required: true - type: string - ref: - required: true - type: string - stage-override: - required: false - type: string - -jobs: - deploy-aws: - runs-on: ${{ inputs.runner-label || 'ubuntu-latest' }} - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ inputs.pr-sha }} - - uses: oven-sh/setup-bun@v1 - - - name: "🔨 Install dependencies" - run: bun install --frozen-lockfile - - - name: "👥 Configure AWS Credentials" - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: arn:aws:iam::262732185023:role/github-action-deploy-role - aws-region: eu-west-1 - retry-max-attempts: 5 - - - name: "👥 Login to Amazon ECR" - id: login-ecr - uses: aws-actions/amazon-ecr-login@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: "🔨 Prebuild docker dependencies" - uses: docker/build-push-action@v5 - with: - context: . - platforms: linux/arm64 - push: true - tags: 262732185023.dkr.ecr.eu-west-1.amazonaws.com/indexer-cache:latest - - - name: "🚀 SST Deploy" - env: - STAGE_OVERRIDE: ${{ inputs.stage-override }} - run: | - echo "Deploying with stage: prod" - bun sst deploy --stage prod diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 358ee35..05d1f90 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,15 +23,43 @@ defaults: shell: bash jobs: - # Independent step, deploying all the tools infrastructure - deploy-indexer: - name: "🚀 Deploy Indexer" - uses: ./.github/workflows/deploy-submodule.yml - secrets: inherit - with: - # Need a custom ami image id since it's needing docker for the build process - #ami-image-id: ami-0e2a787a966f10c15 - #instance-type: t4g.small - runner-label: "ubuntu-latest" - pr-sha: ${{ github.event.pull_request.head.sha }} - ref: ${{ github.ref }} + deploy: + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + - uses: oven-sh/setup-bun@v1 + + - name: "🔨 Install dependencies" + run: bun install --frozen-lockfile + + - name: "👥 Configure AWS Credentials" + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::262732185023:role/github-action-deploy-role + aws-region: eu-west-1 + retry-max-attempts: 5 + + - name: "👥 Login to Amazon ECR" + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: "🔨 Prebuild docker dependencies" + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/arm64 + push: true + tags: 262732185023.dkr.ecr.eu-west-1.amazonaws.com/indexer-cache:latest + + - name: "🚀 SST Deploy" + run: | + echo "Deploying with stage: prod" + bun sst deploy --stage prod diff --git a/Dockerfile.prebuilt b/Dockerfile.prebuilt new file mode 100644 index 0000000..09154bd --- /dev/null +++ b/Dockerfile.prebuilt @@ -0,0 +1,7 @@ +# Prebuilt docker file from the CI worklow +FROM 262732185023.dkr.ecr.eu-west-1.amazonaws.com/indexer-cache:latest + +# run the app +USER bun +EXPOSE 42069/tcp +ENTRYPOINT [ "bun", "run", "start" ] \ No newline at end of file diff --git a/ponder.config.ts b/ponder.config.ts index 78ebde9..541bee4 100644 --- a/ponder.config.ts +++ b/ponder.config.ts @@ -1,4 +1,5 @@ import { createConfig } from "@ponder/core"; +import { Config } from "sst/node/config"; import { http } from "viem"; import { erc20ABI } from "./abis/erc20ABI"; import { multiWebAuthNValidatorV2Abi } from "./abis/multiWebAuthNValidatorABI"; @@ -8,33 +9,46 @@ const pollingConfig = { maxRequestsPerSecond: 1, } as const; +function getConfigOrEnv(key: keyof typeof Config): string | undefined { + try { + return Config[key] ?? process.env[key] ?? undefined; + } catch { + console.error(`Failed to get config for key: ${key}`); + } + return process.env[key] ?? undefined; +} + export default createConfig({ + database: { + kind: "postgres", + connectionString: getConfigOrEnv("DATABASE_URL"), + }, networks: { // Mainnets arbitrum: { chainId: 42161, - transport: http(process.env.PONDER_RPC_URL_ARB), + transport: http(getConfigOrEnv("PONDER_RPC_URL_ARB")), ...pollingConfig, }, base: { chainId: 8453, - transport: http(process.env.PONDER_RPC_URL_BASE), + transport: http(getConfigOrEnv("PONDER_RPC_URL_BASE")), ...pollingConfig, }, optimism: { chainId: 10, - transport: http(process.env.PONDER_RPC_URL_OPTIMISM), + transport: http(getConfigOrEnv("PONDER_RPC_URL_OPTIMISM")), ...pollingConfig, }, polygon: { chainId: 137, - transport: http(process.env.PONDER_RPC_URL_POLYGON), + transport: http(getConfigOrEnv("PONDER_RPC_URL_POLYGON")), ...pollingConfig, }, // Testnets arbitrumSepolia: { chainId: 421614, - transport: http(process.env.PONDER_RPC_URL_ARB_SEPOLIA), + transport: http(getConfigOrEnv("PONDER_RPC_URL_ARB_SEPOLIA")), ...pollingConfig, }, }, @@ -44,7 +58,7 @@ export default createConfig({ abi: erc20ABI, network: "arbitrumSepolia", address: "0x9584A61F70cC4BEF5b8B5f588A1d35740f0C7ae2", - startBlock: 29562417 + startBlock: 29562417, }, // The WebAuthN validator to index WebAuthNValidator: { diff --git a/sst-env.d.ts b/sst-env.d.ts new file mode 100644 index 0000000..3e23343 --- /dev/null +++ b/sst-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/sst.config.ts b/sst.config.ts index 38eb7ea..ecd47c0 100644 --- a/sst.config.ts +++ b/sst.config.ts @@ -1,6 +1,6 @@ import { Port, SecurityGroup } from "aws-cdk-lib/aws-ec2"; import type { SSTConfig } from "sst"; -import { Service, type StackContext, Config } from "sst/constructs"; +import { Config, Service, type StackContext } from "sst/constructs"; export default { config(_input) { @@ -48,11 +48,12 @@ function IndexerStack({ stack }: StackContext) { new Config.Secret(stack, "PONDER_RPC_URL_POLYGON"), // Testnet RPCs new Config.Secret(stack, "PONDER_RPC_URL_ARB_SEPOLIA"), - ] + ]; // The service itself const indexerService = new Service(stack, "IndexerService", { path: "./", + file: "Dockerfile.prebuilt", port: 42069, // Domain mapping customDomain: {