Skip to content

Commit d422d2d

Browse files
committed
Add Docker support and environment setup for poco-subgraph
- Introduced .dockerignore and Dockerfile for containerization. - Updated networks.json with new addresses and start blocks. - Enhanced package.json with new scripts for cleaning and managing the build process. - Created .gitignore for test-stack to exclude .env files. - Added docker-compose.yml to define services for the test environment. - Implemented prepare-test-env.js for dynamic environment variable generation. - Removed tsconfig.json as it is no longer needed.
1 parent 721f751 commit d422d2d

File tree

8 files changed

+179
-24
lines changed

8 files changed

+179
-24
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
3+
# generated files
4+
build
5+
generated
6+
7+
# test files
8+
test-stack

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# iexec-poco-subgraph deployer
2+
3+
FROM node:20
4+
5+
WORKDIR /iexec-poco-subgraph
6+
7+
COPY package*.json .
8+
COPY schema.graphql .
9+
COPY subgraph.yaml .
10+
COPY networks.json .
11+
COPY src ./src
12+
13+
RUN npm ci
14+
15+
ENTRYPOINT [ "npm", "run", "all" ]

networks.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
"test": {
2+
"fork-test": {
33
"ERC1538": {
4-
"address": "0xc4b11f41746D3Ad8504da5B383E1aB9aa969AbC7",
5-
"startBlock": 0
4+
"address": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
5+
"startBlock": 4543300
66
},
77
"Core": {
8-
"address": "0xc4b11f41746D3Ad8504da5B383E1aB9aa969AbC7",
9-
"startBlock": 0
8+
"address": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
9+
"startBlock": 4543300
1010
},
1111
"AppRegistry": {
12-
"address": "0xd5Fe43e3cDD29812949dc9b368345537D7B73001",
13-
"startBlock": 0
12+
"address": "0xB1C52075b276f87b1834919167312221d50c9D16",
13+
"startBlock": 4543300
1414
},
1515
"DatasetRegistry": {
16-
"address": "0xf3bd0602fA481230271c5396f146e5695D3750A6",
17-
"startBlock": 0
16+
"address": "0x799DAa22654128d0C64d5b79eac9283008158730",
17+
"startBlock": 4543300
1818
},
1919
"WorkerpoolRegistry": {
20-
"address": "0x6Cb57fA761812c34645C945cA89AAe3602D42eD3",
21-
"startBlock": 0
20+
"address": "0xC76A18c78B7e530A165c5683CB1aB134E21938B4",
21+
"startBlock": 4543300
2222
}
2323
},
2424
"bellecour": {

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
"name": "@iexec/subgraph",
33
"version": "1.1.0",
44
"author": "iExec",
5+
"type": "module",
56
"license": "Apache-2.0",
67
"scripts": {
78
"prepare": "husky",
9+
"clean": "rm -rf generated && rm -rf build",
810
"codegen": "graph codegen ",
911
"test": "npm run codegen && graph test",
1012
"coverage": "npm run codegen && graph test -- -c",
11-
"test-docker": "npm run codegen && docker run -it --rm -v $(pwd):/matchstick/subgraph rainprotocol/matchstick:main",
12-
"build": "npm run codegen && graph build --network ${NETWORK_NAME:-bellecour}",
13+
"build": "graph build --network ${NETWORK_NAME:-bellecour}",
1314
"create": "graph create ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020}",
1415
"deploy": "graph deploy ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020} --ipfs ${IPFS_URL:-http://localhost:5001} --version-label ${VERSION_LABEL:-bellecour/poco-v5}",
15-
"deploy:all": "npm run build && npm run create && npm run deploy",
16+
"all": "npm run clean && npm run codegen && npm run build && npm run create && npm run deploy",
17+
"stop-test-stack": "cd test-stack && docker compose down --remove-orphans --volumes",
18+
"start-test-stack": "npm run stop-test-stack && cd test-stack && docker compose build && node prepare-test-env.js && docker compose up -d",
1619
"itest": "DEBUG=testcontainers:* mocha"
1720
},
1821
"lint-staged": {

test-stack/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

test-stack/docker-compose.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
services:
2+
blockchain-fork:
3+
restart: "no"
4+
image: ghcr.io/foundry-rs/foundry:v1.0.0
5+
entrypoint: anvil
6+
command: "--host 0.0.0.0 --port 8545 --hardfork berlin --fork-url $FORK_URL --fork-block-number $FORK_BLOCK --chain-id 134 --gas-limit 6700000 --gas-price 0"
7+
expose:
8+
- 8545
9+
ports:
10+
- 8545:8545
11+
healthcheck:
12+
test: (echo >/dev/tcp/$(hostname)/8545) &>/dev/null
13+
interval: 10s
14+
timeout: 5s
15+
retries: 3
16+
start_period: 30s
17+
18+
graphnode-postgres:
19+
image: postgres:16.8
20+
restart: unless-stopped
21+
command:
22+
- "postgres"
23+
- "-cshared_preload_libraries=pg_stat_statements"
24+
expose:
25+
- 5432
26+
environment:
27+
POSTGRES_USER: graphnode
28+
POSTGRES_PASSWORD: password
29+
POSTGRES_DB: graphnode-db
30+
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
31+
healthcheck:
32+
test: pg_isready -U graphnode -d graphnode-db
33+
interval: 10s
34+
timeout: 5s
35+
retries: 3
36+
start_period: 30s
37+
38+
ipfs:
39+
restart: unless-stopped
40+
image: ipfs/go-ipfs:v0.34.1
41+
expose:
42+
- 8080
43+
- 5001
44+
ports:
45+
- 8080:8080
46+
- 5001:5001
47+
48+
graphnode:
49+
image: graphprotocol/graph-node:v0.37.0
50+
restart: unless-stopped
51+
expose:
52+
- 8000
53+
- 8020
54+
ports:
55+
# GraphQL HTTP
56+
- 8000:8000
57+
# GraphQL WS
58+
# - 8001:8001
59+
# admin RPC
60+
- 8020:8020
61+
# metrics
62+
# - 8040:8040
63+
environment:
64+
postgres_host: graphnode-postgres
65+
postgres_port: 5432
66+
postgres_user: graphnode
67+
postgres_pass: password
68+
postgres_db: graphnode-db
69+
ipfs: ipfs:5001
70+
ethereum: blockchain:http://blockchain-fork:8545
71+
GRAPH_ETHEREUM_GENESIS_BLOCK_NUMBER: $FORK_BLOCK
72+
depends_on:
73+
blockchain-fork:
74+
condition: service_healthy
75+
graphnode-postgres:
76+
condition: service_healthy
77+
ipfs:
78+
condition: service_started
79+
healthcheck:
80+
test: netcat -w 1 0.0.0.0 8020
81+
interval: 10s
82+
timeout: 5s
83+
retries: 5
84+
start_period: 30s
85+
86+
poco-subgraph-deployer:
87+
build:
88+
context: ..
89+
dockerfile: ./Dockerfile
90+
environment:
91+
GRAPHNODE_URL: http://graphnode:8020
92+
IPFS_URL: http://ipfs:5001
93+
depends_on:
94+
blockchain-fork:
95+
condition: service_healthy
96+
graphnode:
97+
condition: service_healthy

test-stack/prepare-test-env.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { mkdirSync, writeFileSync } from 'fs';
2+
import { join } from 'path';
3+
4+
const forkUrl = process.env.FORK_URL || 'https://bellecour.iex.ec';
5+
6+
fetch(forkUrl, {
7+
method: 'POST',
8+
body: JSON.stringify({
9+
jsonrpc: 2.0,
10+
method: 'eth_blockNumber',
11+
params: [],
12+
id: 1,
13+
}),
14+
})
15+
.then((res) => res.json())
16+
.then((jsonRes) => {
17+
const forkBlockNumber = parseInt(jsonRes.result.substring(2), 16);
18+
if (process.env.DRONE) {
19+
const LOCAL_STACK_ENV_DIR = 'local-stack-env';
20+
console.log(`Creating ${LOCAL_STACK_ENV_DIR} directory for drone test-stack`);
21+
mkdirSync(LOCAL_STACK_ENV_DIR, { recursive: true });
22+
writeFileSync(join(LOCAL_STACK_ENV_DIR, 'FORK_URL'), forkUrl);
23+
writeFileSync(join(LOCAL_STACK_ENV_DIR, 'FORK_BLOCK'), `${forkBlockNumber}`);
24+
} else {
25+
console.log('Creating .env file for docker-compose test-stack');
26+
writeFileSync(
27+
'.env',
28+
`############ THIS FILE IS GENERATED ############
29+
# run "node prepare-test-env.js" to regenerate #
30+
################################################
31+
32+
# blockchain node to use as the reference for the local fork
33+
FORK_URL=${forkUrl}
34+
# block number to fork from
35+
FORK_BLOCK=${forkBlockNumber}`,
36+
);
37+
}
38+
})
39+
.catch((e) => {
40+
throw Error(`Failed to get current block number from ${forkUrl}: ${e}`);
41+
});

tsconfig.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)