Skip to content

Commit 59c81ab

Browse files
committed
feat: local deployment
1 parent e830411 commit 59c81ab

File tree

12 files changed

+146
-70
lines changed

12 files changed

+146
-70
lines changed

.dockerignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Ignore all .env files in any directory or subdirectory
2+
**/.env
3+
4+
# Ignore node_modules and dist directories in any directory or subdirectory
5+
**/node_modules
6+
**/dist
7+
8+
**/.git
9+
**/.turbo
10+
**/*.md

Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Based on example:
2+
FROM node:20-slim AS base
3+
ENV PNPM_HOME="/pnpm"
4+
ENV PATH="$PNPM_HOME:$PATH"
5+
RUN corepack enable
6+
7+
FROM base AS build
8+
COPY . /usr/src/app
9+
WORKDIR /usr/src/app
10+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
11+
RUN pnpm run -r build
12+
RUN pnpm deploy --filter=./apps/processing --prod /prod/processing
13+
14+
FROM base AS processing
15+
COPY --from=build /prod/processing /prod/processing
16+
WORKDIR /prod/processing
17+
CMD [ "pnpm", "start" ]

README.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This repository is a monorepo that contains 1 package and 2 applications:
1010
- @ts-turborepo-boilerplate/sample-app: A demo application demonstrating the use of sample-lib.
1111
- @grants-stack-indexer/indexer: An [`envio`](https://docs.envio.dev/) indexer, that collects all the relevant events from Allo contracts.
1212

13-
## 🚀 Local Deployment (Dockerized)
13+
## 🚀 Local Deployment (Development)
1414

1515
### Prerequisites
1616

@@ -19,15 +19,27 @@ Ensure you have the following installed on your machine:
1919
- [Docker](https://www.docker.com/get-started)
2020
- [Docker Compose](https://docs.docker.com/compose/install/)
2121

22-
### Run
22+
### Setup
2323

24-
To deploy locally with Docker, run the following command:
24+
1. Build and start the services in detached mode:
2525

2626
```
2727
docker-compose up -d --build
2828
```
2929

30-
Once the deployment is complete, you can access Hasura by navigating to:
30+
2. After starting Docker Compose, run the following command to apply the database migrations:
31+
32+
```
33+
pnpm script:db:migrate
34+
```
35+
36+
3. Navigate to the processing service directory and start it with:
37+
38+
```
39+
cd apps/processing && pnpm dev
40+
```
41+
42+
Once the setup is completed you can access Hasura by navigating to:
3143

3244
```
3345
http://localhost:8080/

apps/indexer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"chai": "4.3.10",
16-
"envio": "2.7.2",
16+
"envio": "2.7.3",
1717
"ethers": "6.8.0",
1818
"yaml": "2.5.1"
1919
},

apps/indexer/pnpm-lock.yaml

+26-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/processing/.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.git
3+
.gitignore
4+
*.md
5+
generated

apps/processing/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:20-slim AS base
2+
ENV PNPM_HOME="/pnpm"
3+
ENV PATH="$PNPM_HOME:$PATH"
4+
RUN corepack enable
5+
COPY . /app
6+
WORKDIR /app
7+
8+
RUN --mount=type=cache,id=pnpm,target=$PNPM_HOME/store pnpm install --frozen-lockfile
9+
RUN pnpm dlx envio codegen
10+
11+
CMD pnpm dlx envio local db-migrate up && pnpm dlx envio start

docker-compose.yaml

+22-16
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ services:
44
restart: always
55
ports:
66
- "${DATALAYER_POSTGRES_EXPOSED_PORT:-5432}:5432"
7-
volumes:
8-
- db_data:/var/lib/datalayer-postgresql/data
7+
# TODO: remove the comment when processing service persists latest event processed
8+
# volumes:
9+
# - db_data:/var/lib/datalayer-postgres/data
910
env_file:
1011
- .env
1112
environment:
@@ -19,8 +20,7 @@ services:
1920
interval: 5s
2021
timeout: 5s
2122
retries: 5
22-
23-
api-hasura:
23+
datalayer-graphql:
2424
image: hasura/graphql-engine:v2.44.0
2525
ports:
2626
- "${DATALAYER_HASURA_EXPOSED_PORT:-8082}:8080"
@@ -56,29 +56,33 @@ services:
5656
start_period: 5s
5757
networks:
5858
- datalayer
59-
60-
envio-postgres:
59+
indexer-postgres:
6160
image: postgres:16
6261
restart: always
6362
ports:
6463
- "${ENVIO_POSTGRES_EXPOSED_PORT:-5433}:5432"
6564
volumes:
66-
- db_data:/var/lib/envio-postgresql/data
65+
- db_data:/var/lib/indexer-postgres/data
6766
env_file:
6867
- .env
6968
environment:
7069
POSTGRES_DB: ${ENVIO_PG_DATABASE}
7170
POSTGRES_USER: ${ENVIO_PG_USER}
7271
POSTGRES_PASSWORD: ${ENVIO_POSTGRES_PASSWORD}
72+
healthcheck:
73+
test: ["CMD-SHELL", "pg_isready -U ${DATALAYER_PG_USER}"]
74+
interval: 5s
75+
timeout: 5s
76+
retries: 5
7377
networks:
74-
- indexer-service
75-
graphql-engine:
78+
- indexer
79+
indexer-graphql:
7680
image: hasura/graphql-engine:v2.23.0
7781
ports:
7882
- "${HASURA_EXPOSED_PORT:-8080}:${PORT:-8080}"
7983
user: 1001:1001
8084
depends_on:
81-
- "envio-postgres"
85+
- "indexer-postgres"
8286
restart: always
8387
env_file:
8488
- .env
@@ -89,24 +93,26 @@ services:
8993
retries: 50
9094
start_period: 5s
9195
networks:
92-
- indexer-service
96+
- indexer
9397
indexer-service:
9498
build:
9599
context: ./apps/indexer
96100
dockerfile: Dockerfile
97-
depends_on:
98-
- "envio-postgres"
99-
- "graphql-engine"
100101
restart: always
102+
depends_on:
103+
indexer-postgres:
104+
condition: service_healthy
105+
indexer-graphql:
106+
condition: service_healthy
101107
env_file:
102108
- .env
103109
networks:
104-
- indexer-service
110+
- indexer
105111
volumes:
106112
db_data:
107113
ganache-data:
108114
networks:
109-
indexer-service:
115+
indexer:
110116
name: indexer_test_network
111117
datalayer:
112118
name: datalayer_test_network

packages/data-flow/src/orchestrator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export class Orchestrator {
100100
await delay(this.fetchDelayInMs);
101101
continue;
102102
}
103+
await this.eventsRegistry.saveLastProcessedEvent(event);
103104

104105
event = await this.enhanceStrategyId(event);
105106
if (event.contractName === "Strategy" && "strategyId" in event) {
@@ -126,7 +127,6 @@ export class Orchestrator {
126127
)}`,
127128
);
128129
}
129-
await this.eventsRegistry.saveLastProcessedEvent(event);
130130
} catch (error: unknown) {
131131
// TODO: improve error handling, retries and notify
132132
if (

packages/data-flow/test/unit/orchestrator.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ describe("Orchestrator", { sequential: true }, () => {
502502

503503
expect(eventsProcessorSpy).toHaveBeenCalledTimes(2);
504504
expect(orchestrator["dataLoader"].applyChanges).toHaveBeenCalledTimes(1);
505-
expect(mockEventsRegistry.saveLastProcessedEvent).toHaveBeenCalledTimes(1);
505+
expect(mockEventsRegistry.saveLastProcessedEvent).toHaveBeenCalledTimes(2);
506506
expect(consoleSpy).toHaveBeenCalledTimes(1);
507507
expect(consoleSpy).toHaveBeenCalledWith(
508508
expect.stringContaining(`Error processing event: ${stringify(errorEvent)}`),

packages/indexer-client/src/providers/envioIndexerClient.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class EnvioIndexerClient implements IIndexerClient {
3232
$limit: Int!
3333
) {
3434
raw_events(
35+
order_by: [{ block_number: asc }, { log_index: asc }]
3536
where: {
3637
chain_id: { _eq: $chainId }
3738
_or: [
@@ -69,7 +70,7 @@ export class EnvioIndexerClient implements IIndexerClient {
6970
if (error instanceof InvalidIndexerResponse) {
7071
throw error;
7172
}
72-
throw new IndexerClientError(JSON.stringify(error));
73+
throw new IndexerClientError(JSON.stringify(error, Object.getOwnPropertyNames(error)));
7374
}
7475
}
7576
}

0 commit comments

Comments
 (0)