Skip to content

Commit

Permalink
👷 Use sst secrets within the ponder.config, use prebuilt docker image…
Browse files Browse the repository at this point in the history
… from
  • Loading branch information
KONFeature committed May 28, 2024
1 parent 767c1b3 commit 218180d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 81 deletions.
61 changes: 0 additions & 61 deletions .github/workflows/deploy-submodule.yml

This file was deleted.

52 changes: 40 additions & 12 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions Dockerfile.prebuilt
Original file line number Diff line number Diff line change
@@ -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" ]
26 changes: 20 additions & 6 deletions ponder.config.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
},
},
Expand All @@ -44,7 +58,7 @@ export default createConfig({
abi: erc20ABI,
network: "arbitrumSepolia",
address: "0x9584A61F70cC4BEF5b8B5f588A1d35740f0C7ae2",
startBlock: 29562417
startBlock: 29562417,
},
// The WebAuthN validator to index
WebAuthNValidator: {
Expand Down
1 change: 1 addition & 0 deletions sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="./.sst/types/index.ts" />
5 changes: 3 additions & 2 deletions sst.config.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 218180d

Please sign in to comment.