Skip to content

Commit

Permalink
Subgraph: update scripts
Browse files Browse the repository at this point in the history
- Add ./start-graph
- Remove ./docker-cleanup.sh (replaced by ./start-graph --reset)
- Rename ./deploy to ./deploy-subgraph for clarity
- Update README with new instructions
  • Loading branch information
bpierre committed Sep 10, 2024
1 parent 35c5b06 commit 4352c72
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 46 deletions.
27 changes: 6 additions & 21 deletions subgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ anvil --host 0.0.0.0 --gas-limit 100000000000 --base-fee 1

# 2. Deploy the contracts
cd contracts
./deploy-subgraph local
# or with demo troves:
# ./deploy-subgraph local --open-demo-troves
./deploy local
# use --open-demo-troves to start with some demo data:
# ./deploy local --open-demo-troves

# 3. Run the graph node
cd subgraph
docker-compose up
./start-graph
# use --reset to clear the state:
# ./start-graph --reset

# 4. Deploy the subgraph
cd subgraph
Expand All @@ -23,20 +25,3 @@ cd subgraph
# subgraph.yaml file (after confirmation).
./deploy-subgraph local --version v1 --create
```

### Reset the subgraph state

```sh
# 1. Stop docker-compose (Ctrl+C)

# 2. Delete the docker volumes
./docker-cleanup.sh

# 3. Start docker-compose again
cd subgraph
docker-compose up

# 4. Redeploy the subgraph
cd subgraph
./deploy-subgraph local --version v1 --create
```
6 changes: 3 additions & 3 deletions subgraph/cli/deploy.ts → subgraph/cli/deploy-subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const SUBGRAPH_PATH = path.join(__dirname, "../subgraph.yaml");
const LATEST_DEPLOYMENT_CONTEXT_PATH = path.join(__dirname, "../../contracts/deployment-context-latest.json");

const HELP = `
deploy - deploy the Liquity v2 subgraph
deploy-subgraph - deploy the Liquity v2 subgraph
Usage:
./deploy [NETWORK_PRESET] [OPTIONS]
./deploy-subgraph [NETWORK_PRESET] [OPTIONS]
Arguments:
NETWORK_PRESET A network preset, which is a shorthand for setting certain options.
Expand Down Expand Up @@ -150,7 +150,7 @@ async function updateDeclarationWithLatestBoldToken() {
const declaration = subgraphDeclaration();
const latestDeploymentContext = getLatestDeploymentContext();

const deployedAddress = latestDeploymentContext?.deployedContracts.BoldToken;
const deployedAddress = latestDeploymentContext?.protocolContracts.BoldToken;
if (!deployedAddress || (declaration.boldTokenAddress === deployedAddress)) {
return;
}
Expand Down
66 changes: 66 additions & 0 deletions subgraph/cli/start-graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { $, echo, minimist, question } from "zx";

const HELP = `
start-graph - start a Graph Node
Usage:
./start-graph [OPTIONS]
Options:
--reset Remove all containers and volumes.
--help, -h Show this help message.
`;

const argv = minimist(process.argv.slice(2), {
alias: {
h: "help",
},
boolean: [
"reset",
"help",
],
});

async function resetCheck() {
if (argv.reset) {
return true;
}
const response = (
await question("Do you want to remove all containers and volumes? [y/N] ")
).toLowerCase();
return response === "y" || response === "yes";
}

export async function main() {
if (argv.help) {
echo`${HELP}`;
process.exit(0);
}

$.verbose = true;

if (await resetCheck()) {
echo``;
echo`Stopping and removing containers…`;
echo``;
await $`docker compose rm -fsv`;

echo``;
echo`Removing volumes…`;
echo``;
await $`docker volume rm subgraph_ipfs`;
await $`docker volume rm subgraph_postgres`;
}

echo``;
echo`Starting Graph Node…`;

// TODO: handle SIGINT
// process.on("SIGINT", async () => {
// echo`Caught interrupt signal. Shutting down containers…`;
// await $`docker compose down`;
// process.exit();
// });

await $`docker compose up`;
}
2 changes: 1 addition & 1 deletion subgraph/deploy-subgraph
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env -S pnpm exec tsx

require("./cli/deploy").main().catch(({ message }) => {
require("./cli/deploy-subgraph").main().catch(({ message }) => {
console.error("");
console.error(` Error: ${message}`);
console.error("");
Expand Down
21 changes: 0 additions & 21 deletions subgraph/docker-cleanup.sh

This file was deleted.

8 changes: 8 additions & 0 deletions subgraph/start-graph
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env -S pnpm exec tsx

require("./cli/start-graph").main().catch(({ message }) => {
console.error("");
console.error(` Error: ${message}`);
console.error("");
process.exit(1);
});

0 comments on commit 4352c72

Please sign in to comment.