Skip to content

Commit 6ce9a92

Browse files
authored
refactor(network-subgraphs): Simplify subgraph yaml management (#1008)
Removed `subgraph.yaml` templating functionality. It was a draft implementation and was not in use. Moved build functionality from the npm script to a separate `build.sh` file. The file requires one parameter which defined the target environment (e.g. `dev2`). Renamed `subgraph.yml` to `subgraph_dev2.yml` to highlight that this file is for `streamr-docker-dev`. Moved `streamr-docker-dev` scripts to the `start.sh` (which is run when `deploy-network-subgraphs-fastchain` docker image starts). Removed some obsolete scripts from package.json (`create-local`, `deploy-local`, `redeploy-local`) ## Next steps In a follow-up PRs we'll improve this by: - modifying `build.sh` so that it build all the output to a `dist` directory - reducing copy-paste of between `subgraph.yaml` files by implementing a better templating functionality ## Future improvements - Could rename `subgraph_matic.yaml` to `subgraph_polygon.yaml` so that it communicates the environment clearly. - The `test` and `coverage` scripts in package.json access some files from the root level. Could move that functionality to this subpackage.
1 parent 18b6350 commit 6ce9a92

13 files changed

+20
-129
lines changed

matchstick.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
testsFolder: ./packages/network-subgraphs/tests
2-
manifestPath: ./packages/network-subgraphs/subgraph.yaml
2+
manifestPath: ./packages/network-subgraphs/subgraph_dev2.yaml

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
"test": "npm run test --workspaces --if-present",
2222
"integration-test": "npm run integration-test --workspaces --if-present",
2323
"test:subgraph": "graph test -d",
24-
"graph1_build": "npm run deployLocalWithExport -w=network-contracts",
25-
"graph2_copyInfo": "./scripts/copyAbis.sh && ./scripts/generateYaml.sh",
26-
"graph3_build": "npm run doAll --workspace=network-subgraphs",
27-
"graph": "npm run graph1_build && npm run graph2_copyInfo && npm run graph3_build",
2824
"e2etest": "npm run e2etest --workspace=network-contracts"
2925
},
3026
"devDependencies": {

packages/network-subgraphs/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/generated/
66
/abis/
77
/tests/.docker/
8-
/tests/.latest.json
8+
/tests/.latest.json
9+
subgraph.yaml
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
if [ "$#" -ne 1 ]; then
4+
echo "Usage: $0 <environment-id>"
5+
exit 1
6+
fi
7+
8+
# TODO could build these to "dist" directory so that we don't need to clean up the subgraph.yaml in package.json (the "rm subgraph.yaml" command)
9+
# - then we can also remove subgraph.yaml from .gitignore
10+
cp subgraph_$1.yaml subgraph.yaml
11+
./scripts/copyAbisFromContractsPackage.sh
12+
npx graph codegen
13+
npx graph build

packages/network-subgraphs/package.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@
55
"private": true,
66
"scripts": {
77
"clean": "rm -rf build generated abis",
8-
"codegen": "graph codegen",
9-
"graphbuild": "graph build",
10-
"build": "./scripts/copyAbisFromContractsPackage.sh && npm run codegen && npm run graphbuild",
11-
"docker:buildLocalArch": "npm run build && docker build . -t streamr/deploy-network-subgraphs:dev-fastchain",
12-
"docker:buildMultiArchAndPush": "npm run build && docker buildx build --platform linux/amd64,linux/arm64 . -t streamr/deploy-network-subgraphs:dev-fastchain --push",
13-
"create-docker-dev": "graph create streamr-dev/network-subgraphs --node http://streamr-dev-thegraph-node-fastchain:8020",
14-
"deploy-docker-dev": "graph deploy streamr-dev/network-subgraphs --version-label v0.0.1 --ipfs http://streamr-dev-ipfs:5001 --node http://streamr-dev-thegraph-node-fastchain:8020",
15-
"create-local": "graph create streamr-dev/network-subgraphs --node http://localhost:8820",
16-
"deploy-local": "graph deploy streamr-dev/network-subgraphs --version-label v0.0.1 --ipfs http://localhost:5001 --node http://localhost:8820",
17-
"redeploy-local": "npm run clean && npm run build && npm run create-local && npm run deploy-local",
8+
"docker:buildLocalArch": "./build.sh dev2 && docker build . -t streamr/deploy-network-subgraphs:dev-fastchain && rm subgraph.yaml",
9+
"docker:buildMultiArchAndPush": "./build.sh dev2 && docker buildx build --platform linux/amd64,linux/arm64 . -t streamr/deploy-network-subgraphs:dev-fastchain --push && rm subgraph.yaml",
1810
"test": "cd ../../ && graph test -d --version 0.5.4",
1911
"coverage": "cd ../../ && graph test -d -- -c"
2012
},

packages/network-subgraphs/start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ if [ ! -e $CONTAINER_ALREADY_STARTED ]; then
1919
# TODO we could also wait for dev-chain-fast and postgres start, but in practice these are started almost immediately
2020
# and therefore it makes sense to wait only for the Graph Node
2121
wait_for_graph_node_start
22-
npm run create-docker-dev
23-
npm run deploy-docker-dev
22+
npx graph create streamr-dev/network-subgraphs --node http://streamr-dev-thegraph-node-fastchain:8020
23+
npx graph deploy streamr-dev/network-subgraphs --version-label v0.0.1 --ipfs http://streamr-dev-ipfs:5001 --node http://streamr-dev-thegraph-node-fastchain:8020
2424
else
2525
echo "-- Not first container startup, doing nothing.--"
2626
fi

packages/network-subgraphs/subgraph.template.yaml

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

packages/network-subgraphs/subgraph_amoy.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# if you recreate the docker image to autodeploy in the dev env this file is used directly
2-
# if you deploy locally use the npm task or scripts/generateYaml.sh to re-generate/update this file
3-
41
specVersion: 0.0.4
52
description: Subgraph definitions for the stream permission registry
63
repository:

packages/network-subgraphs/subgraph.yaml renamed to packages/network-subgraphs/subgraph_dev2.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# if you recreate the docker image to autodeploy in the dev env this file is used directly
2-
# if you deploy locally use the npm task or scripts/generateYaml.sh to re-generate/update this file
3-
41
specVersion: 0.0.4
52
description: Subgraph definitions for the stream permission registry
63
repository:

packages/network-subgraphs/subgraph_iotex.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# if you recreate the docker image to autodeploy in the dev env this file is used directly
2-
# if you deploy locally use the npm task or scripts/generateYaml.sh to re-generate/update this file
3-
41
specVersion: 0.0.4
52
description: Subgraph definitions for the Streamr contracts
63
repository:

0 commit comments

Comments
 (0)