Skip to content

Commit 4fd6a87

Browse files
committed
feat: add web3 docker setup
1 parent 5559145 commit 4fd6a87

File tree

5 files changed

+173
-61
lines changed

5 files changed

+173
-61
lines changed

docker-setup/Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.PHONY: check-env-file \
22
infra-up infra-stop \
3-
build-services services-up services-stop
3+
build-services services-up services-stop \
4+
web3-start web3-stop
45

56
DOCKER_PARALLEL ?= 4
67

@@ -26,6 +27,18 @@ services-stop:
2627
@service_names="$(wordlist 2, $(words $(MAKECMDGOALS)), $(MAKECMDGOALS))"; \
2728
docker-compose --env-file .env.compose.local stop $$service_names
2829

30+
web3-up:
31+
@service_names="$(wordlist 2, $(words $(MAKECMDGOALS)), $(MAKECMDGOALS))"; \
32+
docker-compose -f docker-compose.web3.yml --parallel $(DOCKER_PARALLEL) up -d $$service_names
33+
34+
web3-stop:
35+
@service_names="$(wordlist 2, $(words $(MAKECMDGOALS)), $(MAKECMDGOALS))"; \
36+
docker-compose -f docker-compose.web3.yml stop $$service_names
37+
38+
# also remove volumes to get the clean start after
39+
web3-down:
40+
docker-compose -f docker-compose.web3.yml down -v
41+
2942
# catch-all and noop; to avoid warnings when using MAKECMDGOALS
3043
%:
3144
@:
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: human-protocol-local-web3
2+
3+
x-service-default-config:
4+
restart: &default-restart unless-stopped
5+
logging: &default-logging
6+
options:
7+
max-size: 10m
8+
max-file: 3
9+
10+
x-hardcoded-vars:
11+
graph_db_user: &graph_db_user graph-node
12+
graph_db_passwrod: &graph_db_passwrod let-me-in
13+
graph_db_name: &graph_db_name graph-node
14+
15+
services:
16+
blockchain-node:
17+
container_name: blockchain-node
18+
image: human-protocol/hardhat-blockchain-node
19+
pull_policy: build
20+
restart: *default-restart
21+
logging:
22+
<<: *default-logging
23+
build:
24+
context: ../
25+
dockerfile: packages/core/Dockerfile.local
26+
healthcheck:
27+
test: yarn local:readiness
28+
interval: 15s
29+
timeout: 30s
30+
retries: 0
31+
networks:
32+
- human_protocol_web3
33+
ports:
34+
- name: node-port
35+
target: 8545
36+
published: ${BLOCKCHAIN_NODE_PORT:-8545}
37+
38+
ipfs:
39+
container_name: ipfs
40+
image: ipfs/kubo:v0.14.0
41+
restart: *default-restart
42+
logging:
43+
<<: *default-logging
44+
healthcheck:
45+
test: ["CMD-SHELL", "ipfs id > /dev/null"]
46+
interval: 10s
47+
timeout: 5s
48+
retries: 3
49+
networks:
50+
- human_protocol_web3
51+
ports:
52+
- name: ipfs-port
53+
target: 5001
54+
published: ${IPFS_PORT:-5010}
55+
volumes:
56+
- ipfs-data:/data/ipfs:Z
57+
58+
graph-node-db:
59+
container_name: graph-node-db
60+
image: postgres:latest
61+
restart: *default-restart
62+
logging:
63+
<<: *default-logging
64+
networks:
65+
- human_protocol_web3
66+
ports:
67+
- name: instance_port
68+
target: 5432
69+
published: ${GRAPH_NODE_DB_PORT:-5434}
70+
command:
71+
[
72+
"postgres",
73+
"-cshared_preload_libraries=pg_stat_statements",
74+
"-cmax_connections=200"
75+
]
76+
healthcheck:
77+
test: ["CMD", "pg_isready"]
78+
interval: 10s
79+
timeout: 5s
80+
retries: 5
81+
volumes:
82+
- graph-node-db-data:/var/lib/postgresql/data:Z
83+
environment:
84+
POSTGRES_USER: *graph_db_user
85+
POSTGRES_PASSWORD: *graph_db_passwrod
86+
POSTGRES_DB: *graph_db_name
87+
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
88+
89+
graph-node:
90+
container_name: graph-node
91+
# In case of issues on Mac M1 rebuild the image for it locally
92+
# https://github.com/graphprotocol/graph-node/blob/master/docker/README.md#running-graph-node-on-an-macbook-m1
93+
image: graphprotocol/graph-node
94+
restart: *default-restart
95+
logging:
96+
<<: *default-logging
97+
networks:
98+
- human_protocol_web3
99+
ports:
100+
- '8000:8000'
101+
- '8001:8001'
102+
- '8020:8020'
103+
- '8030:8030'
104+
- '8040:8040'
105+
depends_on:
106+
- blockchain-node
107+
- ipfs
108+
- graph-node-db
109+
environment:
110+
postgres_host: graph-node-db
111+
postgres_user: *graph_db_user
112+
postgres_pass: *graph_db_passwrod
113+
postgres_db: *graph_db_name
114+
ipfs: ipfs:5001
115+
ethereum: localhost:http://blockchain-node:8545
116+
GRAPH_LOG: info
117+
118+
volumes:
119+
ipfs-data:
120+
graph-node-db-data:
121+
122+
networks:
123+
human_protocol_web3:
124+
name: human-protocol-web3

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"build:sdk": "yarn workspace @human-protocol/sdk build",
1313
"build:libs": "yarn build:core && yarn build:sdk",
1414
"docker:infra-up": "make -C ./docker-setup check-env-file infra-up",
15+
"docker:web3-up": "make -C ./docker-setup web3-up",
16+
"docker:web3-down": "make -C ./docker-setup web3-down",
1517
"docker:stop": "make -C ./docker-setup services-stop"
1618
},
1719
"workspaces": [

packages/sdk/typescript/subgraph/README.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@ Package installation
2929
yarn install
3030
```
3131

32+
## Development
33+
### Tests
34+
35+
To run tests next commands should be executed:
36+
37+
```bash
38+
NETWORK=polygon yarn generate
39+
40+
yarn codegen
41+
42+
yarn build
43+
44+
yarn test
45+
```
46+
47+
### e2e test using local node
48+
You can e2e test subgraph changes by running blockchain and graph node locally. To do so, first you will need to run necessary infra in Docker:
49+
```bash
50+
yarn workspace human-protocol docker:web3-up
51+
```
52+
> In case you already have such infra running and want a clean start w/o previous data - run `yarn workspace human-protocol docker:web3-down` first
53+
54+
After you have the infra running:
55+
```bash
56+
# Generate artifacts for running subgraph on localhost
57+
NETWORK=localhost yarn generate
58+
# Create graph for localhost
59+
yarn create-local
60+
# Deploy the graph
61+
yarn deploy-local
62+
```
63+
After that subgraph should be available on `http://0.0.0.0:8000/subgraphs/name/humanprotocol/localhost`
64+
3265
## 🏊 Deploying graphs for live networks
3366

3467
1. Generate & deploy on matic
@@ -49,20 +82,6 @@ You can access it on `http://localhost:8020/`
4982

5083
The deployment of the graph on each network is automatically triggered by the github CI when mofications are made on the subgraph.
5184

52-
### Tests
53-
54-
To run tests next commands should be executed:
55-
56-
```bash
57-
NETWORK=polygon yarn generate
58-
59-
yarn codegen
60-
61-
yarn build
62-
63-
yarn test
64-
```
65-
6685
### Supported networks
6786

6887
Following networks are supported :

packages/sdk/typescript/subgraph/docker-compose.yml

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

0 commit comments

Comments
 (0)