Skip to content

Commit 20c42e2

Browse files
authored
Merge pull request #2 from DistributedCollective/develop
SOV-5164
1 parent d24b897 commit 20c42e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+5940
-974
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Build Indexer
2+
3+
on:
4+
push:
5+
branches: [develop, staging, main]
6+
paths:
7+
- 'apps/indexer/*'
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
call-workflow-init:
16+
uses: DistributedCollective/.github/.github/workflows/init.yml@v3_staging
17+
with:
18+
ref: ${{ github.ref }}
19+
base_ref: ${{ github.base_ref }}
20+
21+
build:
22+
needs: call-workflow-init
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
strategy:
28+
matrix:
29+
node-version: [24.x]
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Install pnpm
35+
uses: pnpm/action-setup@v4
36+
with:
37+
version: 10
38+
run_install: false
39+
40+
- name: Use Node.js ${{ matrix.node-version }}
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: ${{ matrix.node-version }}
44+
cache: 'pnpm'
45+
46+
- name: Install Dependencies
47+
run: pnpm install
48+
49+
# Login against a Docker registry except on PR
50+
# https://github.com/docker/login-action
51+
- name: Login to registry ${{ needs.call-workflow-init.outputs.registry }}
52+
if: github.event_name != 'pull_request'
53+
uses: docker/login-action@v3.0.0
54+
with:
55+
registry: ${{ needs.call-workflow-init.outputs.registry }}
56+
username: ${{ secrets.DOCKER_USERNAME }}
57+
password: ${{ secrets.DOCKER_PASSWORD }}
58+
59+
# Extract metadata (tags, labels) for Docker
60+
# https://github.com/docker/metadata-action
61+
- name: Extract Docker metadata
62+
id: meta
63+
uses: docker/metadata-action@v5.0.0
64+
with:
65+
images: ${{ needs.call-workflow-init.outputs.registry }}/${{ needs.call-workflow-init.outputs.image_name }}
66+
67+
- name: Build indexer
68+
run: pnpm nx build indexer
69+
70+
# Build and push Docker image with Buildx (don't push on PR)
71+
# https://github.com/docker/build-push-action
72+
- name: Build and push Docker image
73+
uses: docker/build-push-action@v5.0.0
74+
with:
75+
context: .
76+
file: ${{ needs.call-workflow-init.outputs.dockerfile_path }}/Dockerfile.indexer
77+
push: ${{ github.event_name != 'pull_request' }}
78+
tags: ${{ needs.call-workflow-init.outputs.registry }}/${{ needs.call-workflow-init.outputs.image_name }}:${{ needs.call-workflow-init.outputs.KUBE_NAMESPACE }}
79+
labels: ${{ steps.meta.outputs.labels }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"app_name": "slayer-indexer",
3+
"aws_region": "us-east-2",
4+
"k8s_cluster_name": "k8-mainnet",
5+
"registry": "docker.io",
6+
"image_name": "sovryn/slayer-indexer",
7+
"prod_branch": "main",
8+
"staging_branch": "staging",
9+
"dev_branch": "develop",
10+
"dockerfile_path": ".",
11+
"APP_ENV_VARS": {
12+
"APP_NAME": "slayer-indexer",
13+
"NODE_ENV": "production",
14+
"LOG_LEVEL": "debug",
15+
"PORT": "3000",
16+
"POSTGRES_PORT": "5432",
17+
"TZ": "UTC"
18+
},
19+
"DEV_ENV_VARS": {
20+
"FLAGS": "ui"
21+
},
22+
"STAGING_ENV_VARS": {
23+
"FLAGS": "staging,ui"
24+
},
25+
"PROD_ENV_VARS": {}
26+
}

.github/workflows/test.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Run Tests
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.ref }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [24.x]
17+
18+
services:
19+
postgres:
20+
image: postgres:13.18-alpine
21+
env:
22+
POSTGRES_USER: postgres
23+
POSTGRES_PASSWORD: secret
24+
POSTGRES_DB: db
25+
ports:
26+
- 5432:5432
27+
options: >-
28+
--health-cmd="pg_isready -U postgres -d db"
29+
--health-interval=10s
30+
--health-timeout=5s
31+
--health-retries=5
32+
33+
redis:
34+
image: redis:7.0.7-alpine
35+
ports:
36+
- 6379:6379
37+
options: >-
38+
--health-cmd="redis-cli ping"
39+
--health-interval=10s
40+
--health-timeout=5s
41+
--health-retries=5
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: PNPM cache
47+
id: cache-pnpm
48+
uses: actions/cache@v4
49+
env:
50+
cache-name: cache-pnpm
51+
with:
52+
path: |
53+
node_modules
54+
~/.pnpm
55+
key: ${{ runner.os }}-test-${{ env.cache-name }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
56+
57+
- name: NX cache
58+
id: cache-nx
59+
uses: actions/cache@v4
60+
env:
61+
cache-name: cache-nx
62+
with:
63+
path: |
64+
.nx
65+
key: ${{ runner.os }}-test-${{ env.cache-name }}-nx-${{ hashFiles('**/pnpm-lock.yaml') }}
66+
67+
- name: Install pnpm
68+
uses: pnpm/action-setup@v4
69+
with:
70+
version: 10
71+
run_install: false
72+
73+
- name: Use Node.js ${{ matrix.node-version }}
74+
uses: actions/setup-node@v4
75+
with:
76+
node-version: ${{ matrix.node-version }}
77+
cache: 'pnpm'
78+
79+
- name: Install Dependencies
80+
if: steps.cache-pnpm.outputs.cache-hit != 'true'
81+
run: pnpm install
82+
83+
- name: Run Tests
84+
run: pnpm nx run-many -t test

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ vitest.config.*.timestamp*
55
dist/
66

77
test-output
8+
9+
10+
11+
.nx/cache
12+
.nx/workspace-data
13+
.cursor/rules/nx-rules.mdc
14+
.github/instructions/nx.instructions.md

.prettierignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Add files here to ignore them from prettier formatting
22
/dist
3+
**/dist
34
/coverage
45
/.nx/cache
5-
/.nx/workspace-data
6+
/.nx/workspace-data
7+
8+
routeTree.gen.ts

.vscode/extensions.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"recommendations": [
3-
"ms-playwright.playwright",
43
"dbaeumer.vscode-eslint",
54
"esbenp.prettier-vscode",
65
"streetsidesoftware.code-spell-checker"

.vscode/launch.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Debug indexer with Nx",
8+
"runtimeExecutable": "pnpm exec",
9+
"runtimeArgs": ["nx", "serve", "indexer"],
10+
"env": {
11+
"NODE_OPTIONS": "--inspect=9229"
12+
},
13+
"console": "integratedTerminal",
14+
"internalConsoleOptions": "neverOpen",
15+
"skipFiles": ["<node_internals>/**"],
16+
"sourceMaps": true,
17+
"outFiles": [
18+
"${workspaceFolder}/apps/indexer/dist/**/*.(m|c|)js",
19+
"!**/node_modules/**"
20+
]
21+
}
22+
]
23+
}

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
"editor.codeActionsOnSave": {
55
"source.organizeImports": "explicit",
66
"source.sortImports": "explicit"
7-
}
7+
},
8+
"cSpell.words": [
9+
"sovryn"
10+
]
811
}

Dockerfile.indexer

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Build stage
2+
FROM node:24.8.0-alpine
3+
4+
ENV NODE_ENV=production
5+
ENV HOST=0.0.0.0
6+
ENV PORT=3000
7+
8+
EXPOSE 3000
9+
10+
RUN corepack enable
11+
12+
WORKDIR /app
13+
14+
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml nx.json tsconfig.json tsconfig.base.json ./
15+
COPY apps/indexer ./apps/indexer
16+
COPY packages ./packages
17+
COPY tmp ./tmp
18+
19+
RUN pnpm install
20+
21+
RUN pnpm nx build indexer
22+
23+
CMD [ "node", "apps/indexer/dist/main.js" ]

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Sovryn Layer
2+
3+
Monorepo for Sovryn Layer frontend app and indexer.
4+
5+
## Development
6+
7+
Requirements:
8+
9+
- node@24.8
10+
- pnpm@10
11+
- docker compose (for indexer)
12+
13+
Project uses [nx](https://nx.dev/getting-started/intro) for workspace management.
14+
15+
### Starting project
16+
17+
#### Running entire stack
18+
19+
To run web-app and indexer:
20+
21+
1. `pnpm install` - install node modules
22+
2. Adjust `.env.local` in `apps/web-app` (optional)
23+
3. Adjust `.env` in `apps/indexer` (optional)
24+
4. `pnpm docker:indexer` - spin off redis and postgresql for the indexer (optional)
25+
5. `pnpm serve` - run both web-app and indexer in development mode
26+
27+
#### Frontend only
28+
29+
1. `pnpm install`
30+
2. Adjust `.env.local` in `apps/web-app` for `VITE_API_BASE` to include deployed indexer url.
31+
3. `pnpm serve:web` - runs web-app in development mode.
32+
33+
#### Indexer only
34+
35+
1. `pnpm install`
36+
2. Adjust `.env` in `apps/indexer` (optional)
37+
3. `pnpm docker:indexer` - spin off redis and postgresql for the indexer (optional)
38+
4. `pnpm serve:indexer` - run indexer in development mode.
39+
40+
### Working with it
41+
42+
#### Adding and removing npm dependencies
43+
44+
To add new npm dependency to the app or package, use `--filter` flag when running `pnpm` to select to which project command should apply:
45+
46+
`pnpm add lodash --filter web-app` - installs lodash for web-app app.
47+
48+
`pnpm remove lodash --filter sdk` - removes lodash from sdk package.
49+
50+
`pnpm add typescript -w -D` - installs typescript to the workspace root as dev dependency.
51+
52+
#### Indexer
53+
54+
Indexer uses [drizzle-orm](https://orm.drizzle.team/docs/kit-overview) to work with migrations.
55+
You may run drizzle commands on root folder of monorepo and it will be forwarded to indexer, ex: `pnpm drizzle-kit studio`
56+
57+
#### Packages
58+
59+
`packages` folder contains libraries that may be shared between projects. To create new packages, consult (nx documentation)[https://nx.dev/features/generate-code].
60+
Once new package is generated, you may use that package in an app by adding it in the apps package.json file.
61+
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.
62+
63+
`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.
64+
65+
`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.

0 commit comments

Comments
 (0)