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

promote main dpid resolver #26

Merged
merged 39 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bd15b3d
add test cases for attestation routing
kadamidev Jun 13, 2024
e3aaacd
config changes for easier debugging
kadamidev Jun 14, 2024
5e189bf
fix dpid resolver returning vNaN for an invalid version string, or hi…
kadamidev Jun 14, 2024
b33716a
Merge pull request #23 from desci-labs/attestation-routing
hubsmoke Jun 21, 2024
6ab8d04
modernize project config
m0ar Jun 14, 2024
1022f7c
Add sanityCheckEnv merge hook
m0ar Jun 19, 2024
e9d75ce
Upgrade node and dependencies
m0ar Jun 20, 2024
2466f39
Optimise docker image
m0ar Jun 20, 2024
3d96cc0
Switch nodemon for tsx, generate sourcemaps, use dumb-init in k8s
m0ar Jun 20, 2024
e9dfa20
separate vault secrets per env
m0ar Jun 25, 2024
7ef3c1d
support codex + alias resolution
m0ar Jun 25, 2024
8deaff5
Add fallback resolver envvar, tidy
m0ar Jun 25, 2024
68f608b
[wip] borky json bodies
m0ar Jun 26, 2024
4b991ac
add discovery & history endpoints
m0ar Jun 26, 2024
6f251be
fixes after rebase, fix port collision in test suite, add attestation…
m0ar Jun 26, 2024
6a134c1
fixes after rebase, fix port collision in test suite, add attestation…
m0ar Jun 26, 2024
0fa7e35
Merge pull request #24 from desci-labs/m0ar/enable-codex
hubsmoke Jun 27, 2024
ee0a24d
patch fallback check
m0ar Jun 28, 2024
cc0b235
Merge pull request #25 from desci-labs/m0ar/patch-fallback-check
m0ar Jun 28, 2024
d30e9ae
fix buid
hubsmoke Jul 10, 2024
5009132
Optional version query params on direct dpid/codex resolution handlers
m0ar Jul 23, 2024
514233b
remove logfile accumulation, respond on incorrect dpid, add healthcheck
m0ar Jul 29, 2024
a08df7e
Fix env loading, dynamic legacy fallback on wildcard resolution route
m0ar Jul 30, 2024
4cf4fef
make all resolvers return full history, history accepts single query …
m0ar Jul 30, 2024
b98e27b
reorder healthcheck route to avoid hitting the wildcard
m0ar Jul 27, 2024
7308307
add CI test workflow
m0ar Aug 14, 2024
cbccc1a
pick base image with .nvmrc
m0ar Aug 14, 2024
84d4129
Fix build workflow, add docker build args
m0ar Aug 14, 2024
8b2402d
Merge pull request #27 from desci-labs/m0ar/improve-direct-resolution
m0ar Aug 19, 2024
b60d145
Fix regex calling anything containing at least 1 digit a DPID
m0ar Aug 21, 2024
3e8b376
Merge pull request #28 from desci-labs/m0ar/hotfix-dpid-regex
m0ar Aug 21, 2024
56c3902
bump contracts pkg to use correct latest local dev contract address
kadamidev Sep 3, 2024
13fa3ee
use redis to cache commits, dpid mappings, and legacy history
m0ar Sep 16, 2024
52da0e6
use redis.isReady to skip when connection is pending
m0ar Sep 16, 2024
7dc3cf1
refresh commit ttl on load
m0ar Sep 17, 2024
1931b7c
Merge pull request #30 from desci-labs/m0ar/resolver-redis-cache
m0ar Sep 17, 2024
6c1f4d1
fix workflow not applying kubernetes declarations
m0ar Sep 17, 2024
7fd318c
Merge pull request #31 from desci-labs/m0ar/fix-resolver-workflow
m0ar Sep 17, 2024
5df1f0c
Merge pull request #29 from desci-labs/bump-contracts-pkg
hubsmoke Sep 18, 2024
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
9 changes: 8 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.git
.gitignore
.husky
.env
.github/
.vscode/
dist/
node_modules/
test/
kubernetes/
node_modules/
35 changes: 34 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
PORT=5460
SUPABASE_URL=
SUPABASE_KEY=
DPID_ENV=dev

# Set these to run with a local redis instance, outside of the backend cluster
# REDIS_HOST=localhost
# REDIS_PORT=6379
# Short TTL's for tinkering with history loading
# CACHE_TTL_ANCHORED=60
# CACHE_TTL_PENDING=10

# If set to 1, the `/*` route will use the legacy handler
FALLBACK_RESOLVER=0

# Local
# DPID_ENV=local # TODO, app prob doesn't like this yet
# OPTIMISM_RPC_URL=http://localhost:8545
# CERAMIC_URL=https://localhost:7007
# IPFS_GATEWAY=http://localhost:8089/ipfs

# Dev & staging
DPID_ENV=dev
OPTIMISM_RPC_URL=https://reverse-proxy-dev.desci.com/rpc_opt_sepolia
CERAMIC_URL=https://ceramic-dev.desci.com
IPFS_GATEWAY=https://ipfs.desci.com/ipfs

# Staging
# DPID_ENV=staging
# OPTIMISM_RPC_URL=https://reverse-proxy-staging.desci.com/rpc_opt_sepolia
# CERAMIC_URL=https://ceramic-prod.desci.com
# IPFS_GATEWAY=https://ipfs.desci.com/ipfs

# Prod
# DPID_ENV=production
# OPTIMISM_RPC_URL=https://reverse-proxy-prod.desci.com/rpc_opt_sepolia
# CERAMIC_URL=https://ceramic-prod.desci.com
# IPFS_GATEWAY=https://ipfs.desci.com/ipfs
8 changes: 8 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Tests run code generating destination URLs using these variables, which
# would work locally too, but the code actually resolving manifest components
# or drive files does not as they rely on content of dpid 46 being pinned

DPID_ENV=dev
IPFS_GATEWAY=https://ipfs.desci.com/ipfs
OPTIMISM_RPC_URL=https://reverse-proxy-dev.desci.com/rpc_opt_sepolia
CERAMIC_URL=https://ceramic-dev.desci.com
22 changes: 11 additions & 11 deletions .github/workflows/build-dpid-resolver.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# build.yml
on:
push:
branches: # array of glob patterns matching against refs/heads. Optional; defaults to all
- main # triggers on pushes that contain changes
- develop

name: Build dpid-resolver

# https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
env:
AWS_DEFAULT_REGION: us-east-2
Expand All @@ -24,22 +21,21 @@ jobs:
timeout-minutes: 10
steps:
- name: Prepare testing env
uses: actions/checkout@v2
- uses: actions/setup-node@v2
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "18"
node-version-file: ".nvmrc"
check-latest: false
cache: npm
- run: npm ci
- name: Run tests
run: npm run test
- run: npm run test
build-and-push:
name: Build and deploy
runs-on: ubuntu-latest
# needs: test
timeout-minutes: 10
steps:
- uses: hashicorp/setup-terraform@v1
- name: Checkout
uses: actions/checkout@master
- uses: actions/checkout@v4

# Add steps here like linting, testing, minification, etc.
- id: install-aws-cli
Expand Down Expand Up @@ -70,6 +66,7 @@ jobs:
run: |
# Build and tag the image
docker build \
--build-arg NODE_VERSION=$(< .nvmrc) \
-t $CONTAINER_IMAGE-dev:latest \
-t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev \
.
Expand All @@ -79,6 +76,7 @@ jobs:
run: |
# Build and tag the image
docker build \
--build-arg NODE_VERSION=$(< .nvmrc) \
-t $CONTAINER_IMAGE:latest \
-t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE \
.
Expand Down Expand Up @@ -110,11 +108,13 @@ jobs:
# uses: steebchen/[email protected]
if: github.ref == 'refs/heads/develop'
run: | # defaults to latest kubectl binary version
kubectl apply -f kubernetes/deployment.dev.yaml
kubectl set image deployment/dpid-resolver-dev dpid-resolver-dev=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:${{ github.sha }} --record

- name: Deploy to EKS (PROD)
if: github.ref == 'refs/heads/main'
run: | # defaults to latest kubectl binary version
kubectl apply -f kubernetes/deployment.prod.yaml
kubectl set image deployment/dpid-resolver dpid-resolver=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE:${{ github.sha }} --record

- name: Verify EKS Deployment (DEV)
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
pull_request
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
check-latest: false
cache: npm

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm run test
1 change: 1 addition & 0 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bash sanityCheckEnv.sh
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
20.13.1
31 changes: 23 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
FROM node:16.17.0
ARG NODE_VERSION
FROM node:${NODE_VERSION}-alpine3.20 AS base
RUN apk update && apk add --no-cache bash dumb-init

WORKDIR /usr/src/app
COPY . ./
RUN npm install -g [email protected]
RUN npm ci --ignore-scripts
EXPOSE 5460
COPY .env.example .env
COPY package*.json ./

FROM base AS builder

RUN --mount=type=cache,target=/usr/src/app/.npm \
npm set cache /usr/src/app/.npm && \
npm ci
COPY . .
RUN npm run build
RUN apt-get install -y bash
CMD [ "npm", "run", "start" ]

FROM base AS prod

COPY --chown=node:node --from=builder /usr/src/app/dist dist/
COPY --chown=node:node --from=builder /usr/src/app/node_modules node_modules/
COPY --chown=node:node --from=builder /usr/src/app/.env.example .env

USER node
EXPOSE 5460

CMD [ "dumb-init", "node", "--no-warnings=ExperimentalWarning", "dist/index.js" ]
17 changes: 13 additions & 4 deletions kubernetes/deployment.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ spec:
vault.hashicorp.com/agent-inject-template-config: |
{{- with secret "secrets/dpid-resolver/dev" -}}
echo "appstart";
export NODE_ENV=production
export ENV=dev
export NODE_ENV={{ .Data.NODE_ENV }}
export SUPABASE_URL={{ .Data.SUPABASE_URL }}
export SUPABASE_KEY={{ .Data.SUPABASE_KEY }}
export DEBUG_TEST=0;

export DPID_ENV={{ .Data.DPID_ENV }}
export IPFS_GATEWAY={{ .Data.IPFS_GATEWAY}}
export OPTIMISM_RPC_URL={{ .Data.OPTIMISM_RPC_URL }}
export CERAMIC_URL={{ .Data.CERAMIC_URL }}
export FALLBACK_RESOLVER={{ .Data.FALLBACK_RESOLVER }}

export REDIS_HOST={{ .Data.REDIS_HOST }}
export REDIS_PORT={{ .Data.REDIS_PORT }}
export CACHE_TTL_ANCHORED={{ .Data.CACHE_TTL_ANCHORED }}
export CACHE_TTL_PENDING={{ .Data.CACHE_TTL_PENDING }}
echo "loaded"
{{- end -}}
labels:
Expand All @@ -40,7 +49,7 @@ spec:
name: dpid-resolver-dev
command: ["/bin/bash", "-c"]
args:
- echo "SOURCING ENV"; source /vault/secrets/config; NODE_PATH=./dist node ./dist/index.js;
- echo "SOURCING ENV"; source /vault/secrets/config; dumb-init node ./dist/index.js;
ports:
- containerPort: 5460
resources:
Expand Down
21 changes: 15 additions & 6 deletions kubernetes/deployment.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ spec:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/agent-inject-status: "update"
vault.hashicorp.com/role: app-vault-reader
vault.hashicorp.com/agent-inject-secret-config: secrets/dpid-resolver/dev
vault.hashicorp.com/agent-inject-secret-config: secrets/dpid-resolver/production
vault.hashicorp.com/agent-inject-template-config: |
{{- with secret "secrets/dpid-resolver/dev" -}}
{{- with secret "secrets/dpid-resolver/production" -}}
echo "appstart";
export NODE_ENV=production
export DPID_ENV=production
export NODE_ENV={{ .Data.NODE_ENV }}
export SUPABASE_URL={{ .Data.SUPABASE_URL }}
export SUPABASE_KEY={{ .Data.SUPABASE_KEY }}
export DEBUG_TEST=0;

export DPID_ENV={{ .Data.DPID_ENV }}
export IPFS_GATEWAY={{ .Data.IPFS_GATEWAY}}
export OPTIMISM_RPC_URL={{ .Data.OPTIMISM_RPC_URL }}
export CERAMIC_URL={{ .Data.CERAMIC_URL }}
export FALLBACK_RESOLVER={{ .Data.FALLBACK_RESOLVER }}

export REDIS_HOST={{ .Data.REDIS_HOST }}
export REDIS_PORT={{ .Data.REDIS_PORT }}
export CACHE_TTL_ANCHORED={{ .Data.CACHE_TTL_ANCHORED }}
export CACHE_TTL_PENDING={{ .Data.CACHE_TTL_PENDING }}
echo "loaded"
{{- end -}}
labels:
Expand All @@ -40,7 +49,7 @@ spec:
name: dpid-resolver
command: ["/bin/bash", "-c"]
args:
- echo "SOURCING ENV"; source /vault/secrets/config; NODE_PATH=./dist node ./dist/index.js;
- echo "SOURCING ENV"; source /vault/secrets/config; dumb-init node ./dist/index.js;
ports:
- containerPort: 5460
resources:
Expand Down
22 changes: 15 additions & 7 deletions kubernetes/deployment.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,24 @@ spec:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/agent-inject-status: "update"
vault.hashicorp.com/role: app-vault-reader
vault.hashicorp.com/agent-inject-secret-config: secrets/dpid-resolver/dev
vault.hashicorp.com/agent-inject-secret-config: secrets/dpid-resolver/staging
vault.hashicorp.com/agent-inject-template-config: |
{{- with secret "secrets/dpid-resolver/dev" -}}
{{- with secret "secrets/dpid-resolver/staging" -}}
echo "appstart";
export NODE_ENV=production
export ENV=staging
export DPID_ENV=staging
export NODE_ENV={{ .Data.NODE_ENV }}
export SUPABASE_URL={{ .Data.SUPABASE_URL }}
export SUPABASE_KEY={{ .Data.SUPABASE_KEY }}
export DEBUG_TEST=0;

export DPID_ENV={{ .Data.DPID_ENV }}
export IPFS_GATEWAY={{ .Data.IPFS_GATEWAY }}
export OPTIMISM_RPC_URL={{ .Data.OPTIMISM_RPC_URL }}
export CERAMIC_URL={{ .Data.CERAMIC_URL }}
export FALLBACK_RESOLVER={{ .Data.FALLBACK_RESOLVER }}

export REDIS_HOST={{ .Data.REDIS_HOST }}
export REDIS_PORT={{ .Data.REDIS_PORT }}
export CACHE_TTL_ANCHORED={{ .Data.CACHE_TTL_ANCHORED }}
export CACHE_TTL_PENDING={{ .Data.CACHE_TTL_PENDING }}
echo "loaded"
{{- end -}}
labels:
Expand All @@ -77,7 +85,7 @@ spec:
name: dpid-resolver-staging
command: ["/bin/bash", "-c"]
args:
- echo "SOURCING ENV"; source /vault/secrets/config; NODE_PATH=./dist node ./dist/index.js;
- echo "SOURCING ENV"; source /vault/secrets/config; dumb-init node ./dist/index.js;
ports:
- containerPort: 5460
resources:
Expand Down
Empty file removed log/.gitkeep
Empty file.
Loading
Loading