Skip to content

Commit 25b2a22

Browse files
authored
Merge pull request #12 from initia-labs/feat/docker-compose
Feat/docker compose
2 parents 558c132 + ba631bd commit 25b2a22

File tree

12 files changed

+457
-93
lines changed

12 files changed

+457
-93
lines changed

dockerfiles/.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
POSTGRES_USER="postgres"
2+
POSTGRES_PASSWORD="postgres"
3+
POSTGRES_DB="core_indexer"
4+
CHAIN="initiation-2"
5+
ENVIRONMENT="local"

dockerfiles/Dockerfile.informative

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
FROM golang:1.22
2-
3-
WORKDIR /
4-
COPY informative-indexer /informative-indexer
1+
FROM golang:1.23 AS builder
52

63
WORKDIR /informative-indexer
4+
COPY ../informative-indexer /informative-indexer
5+
76
RUN go build -o /informative-indexer.bin .
87

8+
FROM ubuntu:latest
9+
10+
RUN apt-get update && apt-get install -y ca-certificates
11+
12+
WORKDIR /informative-indexer
13+
COPY --from=builder /informative-indexer.bin /informative-indexer.bin
14+
915
CMD ["/informative-indexer.bin"]

dockerfiles/README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
## Docker compose for informative indexer
2+
3+
### Prerequisite
4+
1. Create a .env file.
5+
- Add the following content to your `.env` file.
6+
```env
7+
POSTGRES_USER="postgres"
8+
POSTGRES_PASSWORD="postgres"
9+
POSTGRES_DB="core_indexer"
10+
CHAIN="initiation-2"
11+
ENVIRONMENT="local"
12+
```
13+
2. Update the `block_height` value
14+
- Modify the `block_height` value in `init/init.sql` if you want to change the starting block height.
15+
- Default: 2797040
16+
17+
### Run
18+
Run the following command to start the service:
19+
```shell
20+
docker compose -f dockerfiles/docker-compose-informative.yml up --build
21+
```
22+
23+
### Fake-GCS
24+
We are using [fake-gcs-server](https://github.com/fsouza/fake-gcs-server) to enable the storage feature.
25+
You can view your fake GCS information at: `http://localhost:9184/storage/v1/b/{bucket_name}`
26+
```json
27+
{
28+
"kind": "storage#bucket",
29+
"id": "initiation-2-local-informative-indexer-large-block-results",
30+
"defaultEventBasedHold": false,
31+
"name": "initiation-2-local-informative-indexer-large-block-results",
32+
"versioning": {
33+
"enabled": false
34+
},
35+
"timeCreated": "2025-01-23T06:11:01.205566Z",
36+
"updated": "2025-01-23T06:11:01.205566Z",
37+
"location": "US-CENTRAL1",
38+
"storageClass": "STANDARD",
39+
"projectNumber": "0",
40+
"metageneration": "1",
41+
"etag": "RVRhZw==",
42+
"locationType": "region"
43+
}
44+
```
45+
46+
### Hasura for GraphQL
47+
We use Hasura for GraphQL. Run the following to update the metadata.
48+
```shell
49+
curl -X POST -H 'Content-Type: application/json' \
50+
--data '{
51+
"type": "bulk",
52+
"source": "default",
53+
"resource_version": 1,
54+
"args": [
55+
{
56+
"type": "postgres_track_tables",
57+
"args": {
58+
"allow_warnings": true,
59+
"tables": [
60+
{"table": {"name": "finalize_block_events", "schema": "public"}, "source": "default"},
61+
{"table": {"name": "move_events", "schema": "public"}, "source": "default"},
62+
{"table": {"name": "transaction_events", "schema": "public"}, "source": "default"}
63+
]
64+
}
65+
}
66+
]
67+
}' \
68+
http://localhost:8080/v1/metadata
69+
```
+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
services:
2+
postgres:
3+
image: postgres:15
4+
container_name: postgres
5+
environment:
6+
POSTGRES_USER: ${POSTGRES_USER}
7+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
8+
POSTGRES_DB: ${POSTGRES_DB}
9+
restart: always
10+
ports:
11+
- "5432:5432"
12+
volumes:
13+
- pg_data:/var/lib/postgresql/data
14+
- ./init/:/docker-entrypoint-initdb.d/
15+
healthcheck:
16+
test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER}" ]
17+
interval: 10s
18+
timeout: 5s
19+
retries: 5
20+
21+
graphql-engine:
22+
image: hasura/graphql-engine:v2.43.0
23+
ports:
24+
- "8080:8080"
25+
restart: always
26+
environment:
27+
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/hasura_metadata
28+
HASURA_GRAPHQL_DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
29+
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
30+
HASURA_GRAPHQL_DEV_MODE: "true"
31+
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
32+
depends_on:
33+
postgres:
34+
condition: service_healthy
35+
36+
storage:
37+
container_name: gcs
38+
image: fsouza/fake-gcs-server
39+
restart: always
40+
ports:
41+
- "9184:9184"
42+
volumes:
43+
- storage:/storage/${CHAIN}-local-informative-indexer-large-block-results
44+
# - storage:/storage/${CHAIN}-local-core-informative-data-backup
45+
command: -scheme http -port 9184
46+
47+
zookeeper:
48+
image: confluentinc/cp-zookeeper
49+
hostname: zookeeper
50+
container_name: zookeeper
51+
healthcheck:
52+
test: nc -z localhost 2181 || exit -1
53+
interval: 10s
54+
timeout: 5s
55+
retries: 3
56+
ports:
57+
- "2181:2181"
58+
environment:
59+
ZOOKEEPER_CLIENT_PORT: 2181
60+
ZOOKEEPER_TICK_TIME: 2000
61+
62+
broker:
63+
image: confluentinc/cp-kafka
64+
hostname: broker
65+
container_name: broker
66+
depends_on:
67+
- zookeeper
68+
healthcheck:
69+
test: kafka-topics --bootstrap-server broker:29092 --list
70+
interval: 30s
71+
timeout: 10s
72+
retries: 3
73+
ports:
74+
- "29092:29092"
75+
- "9092:9092"
76+
environment:
77+
KAFKA_BROKER_ID: 1
78+
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
79+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
80+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
81+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
82+
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
83+
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
84+
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
85+
KAFKA_SOCKET_REQUEST_MAX_BYTES: 500000000
86+
KAFKA_MESSAGE_MAX_BYTES: 500000000
87+
KAFKA_REPLICA_FETCH_MAX_BYTES: 500000000
88+
89+
sweeper:
90+
build:
91+
context: ../
92+
dockerfile: dockerfiles/Dockerfile.informative
93+
container_name: sweeper
94+
environment:
95+
RPC_ENDPOINTS: '{"rpcs":[{"url": "https://rpc.testnet.initia.xyz"}]}'
96+
BOOTSTRAP_SERVER: broker:29092
97+
DB_CONNECTION_STRING: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
98+
BLOCK_RESULTS_TOPIC: ${CHAIN}-local-informative-indexer-block-results-messages
99+
CHAIN: ${CHAIN}
100+
ENVIRONMENT: ${ENVIRONMENT}
101+
CLAIM_CHECK_BUCKET: ${CHAIN}-local-informative-indexer-large-block-results
102+
depends_on:
103+
postgres:
104+
condition: service_healthy
105+
broker:
106+
condition: service_healthy
107+
command: [ "/informative-indexer.bin", "sweep" ]
108+
109+
flusher:
110+
build:
111+
context: ../
112+
dockerfile: dockerfiles/Dockerfile.informative
113+
container_name: flusher
114+
environment:
115+
BOOTSTRAP_SERVER: broker:29092
116+
BLOCK_RESULTS_TOPIC: ${CHAIN}-local-informative-indexer-block-results-messages
117+
BLOCK_RESULTS_CONSUMER_GROUP: ${CHAIN}-local-informative-indexer-flusher
118+
BLOCK_RESULTS_CLAIM_CHECK_BUCKET: ${CHAIN}-local-informative-indexer-large-block-results
119+
CLAIM_CHECK_THRESHOLD_IN_MB: 1
120+
DB_CONNECTION_STRING: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
121+
CHAIN: ${CHAIN}
122+
ENVIRONMENT: ${ENVIRONMENT}
123+
ID: 1
124+
depends_on:
125+
postgres:
126+
condition: service_healthy
127+
broker:
128+
condition: service_healthy
129+
command: [ "/informative-indexer.bin", "flush" ]
130+
131+
# prunner:
132+
# build:
133+
# context: ../
134+
# dockerfile: dockerfiles/Dockerfile.informative
135+
# container_name: prunner
136+
# environment:
137+
# DB_CONNECTION_STRING: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
138+
# BACKUP_BUCKET_NAME: ${CHAIN}-local-core-informative-data-backup
139+
# BACKUP_FILE_PREFIX: events
140+
# PRUNING_KEEP_BLOCK: 10
141+
# PRUNING_INTERVAL: 1
142+
# CHAIN: ${CHAIN}
143+
# ENVIRONMENT: ${ENVIRONMENT}
144+
# depends_on:
145+
# - sweeper
146+
# - flusher
147+
# command: [ "/informative-indexer.bin", "prune" ]
148+
149+
volumes:
150+
pg_data:
151+
storage:

dockerfiles/init/init.sql

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CREATE DATABASE hasura_metadata;
2+
3+
CREATE TABLE IF NOT EXISTS transaction_events(
4+
transaction_hash varchar,
5+
block_height bigint,
6+
event_key varchar,
7+
event_value varchar,
8+
event_index integer
9+
);
10+
11+
CREATE TABLE IF NOT EXISTS finalize_block_events(
12+
block_height bigint,
13+
event_key varchar,
14+
event_value varchar,
15+
event_index integer,
16+
mode varchar
17+
);
18+
19+
CREATE TABLE IF NOT EXISTS move_events(
20+
type_tag varchar,
21+
data jsonb,
22+
block_height bigint,
23+
transaction_hash varchar,
24+
event_index integer
25+
);
26+
27+
INSERT INTO transaction_events(transaction_hash, block_height, event_key, event_value, event_index) VALUES ('7cbd3c3abc1790b92a8ddcfcb666d31891a09b7bea2861d92d444ca07a8859b7', 2797040, 'execute.sender', '0x1,0x50fbce14436f1bfa9b30576dbb8a5a0c1e249dd3', 0);

0 commit comments

Comments
 (0)