Skip to content

Commit fc03add

Browse files
yehia67saihaj
andauthored
scaffold: generate docker-compose.yml when calling graph init (#1610)
* scaffold: generate docker-compose.yml when calling graph init * feat: include the pre-release files * Apply suggestions from code review --------- Co-authored-by: Saihajpreet Singh <[email protected]>
1 parent 9f522aa commit fc03add

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

.changeset/young-rockets-develop.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': minor
3+
---
4+
5+
Generate `docker-compose.yml` with `graph init` command
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
export const getDockerFile = () => {
2+
return `version: '3'
3+
services:
4+
graph-node:
5+
image: graphprotocol/graph-node
6+
ports:
7+
- '8000:8000'
8+
- '8001:8001'
9+
- '8020:8020'
10+
- '8030:8030'
11+
- '8040:8040'
12+
depends_on:
13+
- ipfs
14+
- postgres
15+
extra_hosts:
16+
- host.docker.internal:host-gateway
17+
environment:
18+
postgres_host: postgres
19+
postgres_user: graph-node
20+
postgres_pass: let-me-in
21+
postgres_db: graph-node
22+
ipfs: 'ipfs:5001'
23+
ethereum: 'mainnet:http://host.docker.internal:8545'
24+
GRAPH_LOG: info
25+
ipfs:
26+
image: ipfs/kubo:v0.17.0
27+
ports:
28+
- '5001:5001'
29+
volumes:
30+
- ./data/ipfs:/data/ipfs
31+
postgres:
32+
image: postgres:14
33+
ports:
34+
- '5432:5432'
35+
command:
36+
[
37+
"postgres",
38+
"-cshared_preload_libraries=pg_stat_statements",
39+
"-cmax_connections=200"
40+
]
41+
environment:
42+
POSTGRES_USER: graph-node
43+
POSTGRES_PASSWORD: let-me-in
44+
POSTGRES_DB: graph-node
45+
# FIXME: remove this env. var. which we shouldn't need. Introduced by
46+
# <https://github.com/graphprotocol/graph-node/pull/3511>, maybe as a
47+
# workaround for https://github.com/docker/for-mac/issues/6270?
48+
PGDATA: "/var/lib/postgresql/data"
49+
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
50+
volumes:
51+
- ./data/postgres:/var/lib/postgresql/data`;
52+
};

packages/cli/src/scaffold/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getSubgraphBasename } from '../command-helpers/subgraph';
44
import Protocol from '../protocols';
55
import ABI from '../protocols/ethereum/abi';
66
import { version } from '../version';
7+
import { getDockerFile } from './get-docker-file';
78
import { generateEventIndexingHandlers } from './mapping';
89
import { abiEvents, generateEventType, generateExampleEntityType } from './schema';
910
import { generateTestsFiles } from './tests';
@@ -154,6 +155,10 @@ dataSources:
154155
);
155156
}
156157

158+
async generateDockerFileConfig() {
159+
return await prettier.format(getDockerFile(), { parser: 'yaml' });
160+
}
161+
157162
async generateMappings() {
158163
return this.protocol.getMappingScaffold()
159164
? { [`${strings.kebabCase(this.contractName)}.ts`]: await this.generateMapping() }
@@ -208,6 +213,7 @@ dataSources:
208213
'subgraph.yaml': await this.generateManifest(),
209214
'schema.graphql': await this.generateSchema(),
210215
'tsconfig.json': await this.generateTsConfig(),
216+
'docker-compose.yml': await this.generateDockerFileConfig(),
211217
src: await this.generateMappings(),
212218
abis: await this.generateABIs(),
213219
tests: await this.generateTests(),

0 commit comments

Comments
 (0)