Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
79 changes: 79 additions & 0 deletions .github/workflows/build-indexer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build Indexer

on:
push:
branches: [develop, staging, main]
paths:
- 'apps/indexer/*'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
call-workflow-init:
uses: DistributedCollective/.github/.github/workflows/init.yml@v3_staging
with:
ref: ${{ github.ref }}
base_ref: ${{ github.base_ref }}

build:
needs: call-workflow-init
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
node-version: [24.x]

steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
run_install: false

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install Dependencies
run: pnpm install

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Login to registry ${{ needs.call-workflow-init.outputs.registry }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3.0.0
with:
registry: ${{ needs.call-workflow-init.outputs.registry }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5.0.0
with:
images: ${{ needs.call-workflow-init.outputs.registry }}/${{ needs.call-workflow-init.outputs.image_name }}

- name: Build indexer
run: pnpm nx build indexer

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v5.0.0
with:
context: .
file: ${{ needs.call-workflow-init.outputs.dockerfile_path }}/Dockerfile.indexer
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ needs.call-workflow-init.outputs.registry }}/${{ needs.call-workflow-init.outputs.image_name }}:${{ needs.call-workflow-init.outputs.KUBE_NAMESPACE }}
labels: ${{ steps.meta.outputs.labels }}
26 changes: 26 additions & 0 deletions .github/workflows/ci-properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"app_name": "slayer-indexer",
"aws_region": "us-east-2",
"k8s_cluster_name": "k8-mainnet",
"registry": "docker.io",
"image_name": "sovryn/slayer-indexer",
"prod_branch": "main",
"staging_branch": "staging",
"dev_branch": "develop",
"dockerfile_path": ".",
"APP_ENV_VARS": {
"APP_NAME": "slayer-indexer",
"NODE_ENV": "production",
"LOG_LEVEL": "debug",
"PORT": "3000",
"POSTGRES_PORT": "5432",
"TZ": "UTC"
},
"DEV_ENV_VARS": {
"FLAGS": "ui"
},
"STAGING_ENV_VARS": {
"FLAGS": "staging,ui"
},
"PROD_ENV_VARS": {}
}
84 changes: 84 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Run Tests

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [24.x]

services:
postgres:
image: postgres:13.18-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: secret
POSTGRES_DB: db
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U postgres -d db"
--health-interval=10s
--health-timeout=5s
--health-retries=5

redis:
image: redis:7.0.7-alpine
ports:
- 6379:6379
options: >-
--health-cmd="redis-cli ping"
--health-interval=10s
--health-timeout=5s
--health-retries=5

steps:
- uses: actions/checkout@v4

- name: PNPM cache
id: cache-pnpm
uses: actions/cache@v4
env:
cache-name: cache-pnpm
with:
path: |
node_modules
~/.pnpm
key: ${{ runner.os }}-test-${{ env.cache-name }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: NX cache
id: cache-nx
uses: actions/cache@v4
env:
cache-name: cache-nx
with:
path: |
.nx
key: ${{ runner.os }}-test-${{ env.cache-name }}-nx-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
run_install: false

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install Dependencies
if: steps.cache-pnpm.outputs.cache-hit != 'true'
run: pnpm install

- name: Run Tests
run: pnpm nx run-many -t test
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ vitest.config.*.timestamp*
dist/

test-output



.nx/cache
.nx/workspace-data
.cursor/rules/nx-rules.mdc
.github/instructions/nx.instructions.md
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Add files here to ignore them from prettier formatting
/dist
**/dist
/coverage
/.nx/cache
/.nx/workspace-data
/.nx/workspace-data

routeTree.gen.ts
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"recommendations": [
"ms-playwright.playwright",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker"
Expand Down
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug indexer with Nx",
"runtimeExecutable": "pnpm exec",
"runtimeArgs": ["nx", "serve", "indexer"],
"env": {
"NODE_OPTIONS": "--inspect=9229"
},
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": ["<node_internals>/**"],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/apps/indexer/dist/**/*.(m|c|)js",
"!**/node_modules/**"
]
}
]
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.sortImports": "explicit"
}
},
"cSpell.words": [
"sovryn"
]
}
23 changes: 23 additions & 0 deletions Dockerfile.indexer
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Build stage
FROM node:24.8.0-alpine

ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=3000

EXPOSE 3000

RUN corepack enable

WORKDIR /app

COPY package.json pnpm-lock.yaml pnpm-workspace.yaml nx.json tsconfig.json tsconfig.base.json ./
COPY apps/indexer ./apps/indexer
COPY packages ./packages
COPY tmp ./tmp

RUN pnpm install

RUN pnpm nx build indexer

CMD [ "node", "apps/indexer/dist/main.js" ]
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Sovryn Layer

Monorepo for Sovryn Layer frontend app and indexer.

## Development

Requirements:

- node@24.8
- pnpm@10
- docker compose (for indexer)

Project uses [nx](https://nx.dev/getting-started/intro) for workspace management.

### Starting project

#### Running entire stack

To run web-app and indexer:

1. `pnpm install` - install node modules
2. Adjust `.env.local` in `apps/web-app` (optional)
3. Adjust `.env` in `apps/indexer` (optional)
4. `pnpm docker:indexer` - spin off redis and postgresql for the indexer (optional)
5. `pnpm serve` - run both web-app and indexer in development mode

#### Frontend only

1. `pnpm install`
2. Adjust `.env.local` in `apps/web-app` for `VITE_API_BASE` to include deployed indexer url.
3. `pnpm serve:web` - runs web-app in development mode.

#### Indexer only

1. `pnpm install`
2. Adjust `.env` in `apps/indexer` (optional)
3. `pnpm docker:indexer` - spin off redis and postgresql for the indexer (optional)
4. `pnpm serve:indexer` - run indexer in development mode.

### Working with it

#### Adding and removing npm dependencies

To add new npm dependency to the app or package, use `--filter` flag when running `pnpm` to select to which project command should apply:

`pnpm add lodash --filter web-app` - installs lodash for web-app app.

`pnpm remove lodash --filter sdk` - removes lodash from sdk package.

`pnpm add typescript -w -D` - installs typescript to the workspace root as dev dependency.

#### Indexer

Indexer uses [drizzle-orm](https://orm.drizzle.team/docs/kit-overview) to work with migrations.
You may run drizzle commands on root folder of monorepo and it will be forwarded to indexer, ex: `pnpm drizzle-kit studio`

#### Packages

`packages` folder contains libraries that may be shared between projects. To create new packages, consult (nx documentation)[https://nx.dev/features/generate-code].
Once new package is generated, you may use that package in an app by adding it in the apps package.json file.
For example, if package generated is named as `@sovryn/my-pgk` and want to use it in the indexer, add `"@sovryn/my-pgk": "workspace:*"` to indexers package.json dependencies and run `pnpm install` on repositories root. Then `@sovryn/my-pgk` can be imported in the code normally.

`packages/slayer-shared` - MUST contain only code which can run in both browser and node environment and is dedicated for helper functions, interfaces and typings that should be shared between web-app and indexer.

`packages/sdk` - is just a placeholder right now. Likely to hold npm package with helpers to use sovryn layer for other projects in the future.
6 changes: 6 additions & 0 deletions apps/indexer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DATABASE_URL=postgres://postgres:secret@localhost:5432/db
REDIS_URL=redis://localhost:6379

# Comma-separated list of flags to enable specific features
# Available flags: ui, readonly, staging
# FLAGS=ui,readonly,staging
1 change: 1 addition & 0 deletions apps/indexer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
22 changes: 22 additions & 0 deletions apps/indexer/.spec.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"jsc": {
"target": "es2017",
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true
},
"keepClassNames": true,
"externalHelpers": true,
"loose": true
},
"module": {
"type": "es6"
},
"sourceMaps": true,
"exclude": []
}
Loading