From 004247b75b99f197619049fe1ae627fef8d024a5 Mon Sep 17 00:00:00 2001 From: gratestas Date: Sat, 18 Mar 2023 12:34:51 +0300 Subject: [PATCH 01/13] chore: add initial setup for containerized deployment --- docker-compose.yml | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..36dc869 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,48 @@ +version: "3" +services: + graph-node: + container_name: graph-node-container + image: graphprotocol/graph-node + ports: + - "8000:8000" + - "8001:8001" + - "8020:8020" + - "8030:8030" + - "8040:8040" + depends_on: + - ipfs + - postgres + extra_hosts: + - host.docker.internal:host-gateway + environment: + postgres_host: postgres + postgres_user: graph-node + postgres_pass: let-me-in + postgres_db: graph-node + ipfs: "ipfs:5001" + ethereum: "${ETHEREUM_NODE_PROVIDER}" + GRAPH_LOG: info + ipfs: + container_name: ipfs-container + image: ipfs/go-ipfs:v0.10.0 + ports: + - "5001:5001" + volumes: + - ./data/ipfs:/data/ipfs + postgres: + container_name: postgres-container + image: postgres + ports: + - "5432:5432" + command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"] + environment: + POSTGRES_USER: graph-node + POSTGRES_PASSWORD: let-me-in + POSTGRES_DB: graph-node + # FIXME: remove this env. var. which we shouldn't need. Introduced by + # , maybe as a + # workaround for https://github.com/docker/for-mac/issues/6270? + PGDATA: "/var/lib/postgresql/data" + POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C" + volumes: + - ./data/postgres:/var/lib/postgresql/data From 16418ad981d95f68dca4365824a7c988dcee1ee4 Mon Sep 17 00:00:00 2001 From: gratestas Date: Sat, 18 Mar 2023 12:35:59 +0300 Subject: [PATCH 02/13] chore: ignore generated data of graph node --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 7ae6e10..2b2f53d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,10 @@ node_modules/ + +# artifacts build/ generated/ + +# graph node +data/ + .idea/ \ No newline at end of file From 657063704741262c1c8ac6d47689f9d82c4ccfeb Mon Sep 17 00:00:00 2001 From: gratestas Date: Sat, 18 Mar 2023 20:08:09 +0300 Subject: [PATCH 03/13] feat: add workflow to deploy subgraph locally for each PR --- .github/workflows/deploy-staging.yml | 57 ++++++++++++++++++++++++++++ package.json | 8 ++-- 2 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/deploy-staging.yml diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 0000000..d194474 --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,57 @@ +name: Deploy Subgraph - Local + +on: + pull_request: + branches: + - master + +jobs: + deploy-staging: + runs-on: ubuntu-latest + environment: staging + env: + SUBGRAPH_NAME: thetruthpost-${{ github.event.pull_request.number }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: 16 + + - name: Install dependencies + run: yarn install + + - name: Build subgraph + run: | + export NETWORK_NAME=goerli + yarn codegen + yarn build + + - name: Create and start Docker containers + run: | + export ETHEREUM_NODE_PROVIDER=${{ secrets.ETHEREUM_NODE_PROVIDER }} + docker-compose up -d + + - name: Wait for containers to start + run: | + while [[ "$(docker-compose ps -q | xargs docker inspect --format '{{.State.Status}}')" != "running" ]]; do sleep 2; done + + - name: Create and deploy a local Subgraph + run: yarn create-local $SUBGRAPH_NAME + + - name: Deploy a local Subgraph + run: yarn deploy-local $SUBGRAPH_NAME --version-label 0.0.1 + + - name: Post subgraph URL to pull request + uses: peter-evans/create-or-update-comment@v2 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + A new subgraph deployment has been created for this pull request. + You can access it at: https://localhost:8000/subgraphs/name/$SUBGRAPH_NAME/graphql + + - name: Stop Docker containers + if: github.event.pull_request.merged == true || github.event.pull_request.closed == true + run: docker-compose down diff --git a/package.json b/package.json index 9644d78..f2dd6d4 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,11 @@ "license": "UNLICENSED", "scripts": { "codegen": "graph codegen", - "build": "graph build", + "build": "graph build --network $NETWORK_NAME", "deploy": "graph deploy --product hosted-service proveuswrong/thetruthpost", - "create-local": "graph create --node http://localhost:8020/ prove-me-wrong", - "remove-local": "graph remove --node http://localhost:8020/ prove-me-wrong", - "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 prove-me-wrong" + "create-local": "graph create --node http://localhost:8020/ $SUBGRAPH_NAME", + "remove-local": "graph remove --node http://localhost:8020/ $SUBGRAPH_NAME", + "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 $SUBGRAPH_NAME" }, "dependencies": { "@graphprotocol/graph-cli": "^0.38.0", From 233b9dc88b13766b9d5a2f93a7250559c438e901 Mon Sep 17 00:00:00 2001 From: gratestas Date: Sat, 18 Mar 2023 20:13:08 +0300 Subject: [PATCH 04/13] chore: add networks config file --- networks.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 networks.json diff --git a/networks.json b/networks.json new file mode 100644 index 0000000..da38677 --- /dev/null +++ b/networks.json @@ -0,0 +1,8 @@ +{ + "goerli": { + "ProveMeWrong": { + "address": "0x0136ed2132Ec1e99046889058F67c9C2fd5FD578", + "startBlock": 6790826 + } + } +} From 63faacd417ff797230b8e64ed1032ee45483b77e Mon Sep 17 00:00:00 2001 From: gratestas Date: Sat, 18 Mar 2023 20:30:50 +0300 Subject: [PATCH 05/13] fix: temp disable containers' status check --- .github/workflows/deploy-staging.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index d194474..8ce6640 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -35,9 +35,9 @@ jobs: docker-compose up -d - name: Wait for containers to start - run: | - while [[ "$(docker-compose ps -q | xargs docker inspect --format '{{.State.Status}}')" != "running" ]]; do sleep 2; done - + run: sleep 10 + # run: | + # while [[ "$(docker-compose ps -q | xargs docker inspect --format '{{.State.Status}}')" != "running" ]]; do sleep 2; done - name: Create and deploy a local Subgraph run: yarn create-local $SUBGRAPH_NAME From b3eac6338b6b09be60221800b2d4f6fa47bbe15b Mon Sep 17 00:00:00 2001 From: gratestas Date: Sat, 18 Mar 2023 20:38:06 +0300 Subject: [PATCH 06/13] fix: remove incorrectly passed argument --- .github/workflows/deploy-staging.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 8ce6640..3f66cab 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -39,10 +39,10 @@ jobs: # run: | # while [[ "$(docker-compose ps -q | xargs docker inspect --format '{{.State.Status}}')" != "running" ]]; do sleep 2; done - name: Create and deploy a local Subgraph - run: yarn create-local $SUBGRAPH_NAME + run: yarn create-local - name: Deploy a local Subgraph - run: yarn deploy-local $SUBGRAPH_NAME --version-label 0.0.1 + run: yarn deploy-local --version-label 0.0.1 - name: Post subgraph URL to pull request uses: peter-evans/create-or-update-comment@v2 From bf8f116e59435dc7b90adfebbc0c5f9ffd56d2f5 Mon Sep 17 00:00:00 2001 From: gratestas Date: Sun, 19 Mar 2023 15:56:55 +0300 Subject: [PATCH 07/13] feat: use ngrok for port tunneling --- .github/workflows/deploy-staging.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 3f66cab..d049bc8 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -38,6 +38,27 @@ jobs: run: sleep 10 # run: | # while [[ "$(docker-compose ps -q | xargs docker inspect --format '{{.State.Status}}')" != "running" ]]; do sleep 2; done + + - name: Download and install ngrok + run: | + curl -s https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok.zip + unzip ngrok.zip + sudo mv ngrok /usr/local/bin + + - name: Start ngrok tunnel for Graph Node + run: | + ngrok authtoken ${{ secrets.NGROK_AUTH_TOKEN }} + ngrok http 8020 > /dev/null & + + - name: Install jq + run: sudo apt-get install -y jq + + - name: Get ngrok public URL + run: | + sleep 10 + export NGROK_URL=$(curl -s http://localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url') + echo "NGROK_URL=$NGROK_URL" >> $GITHUB_ENV + - name: Create and deploy a local Subgraph run: yarn create-local @@ -50,7 +71,7 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body: | A new subgraph deployment has been created for this pull request. - You can access it at: https://localhost:8000/subgraphs/name/$SUBGRAPH_NAME/graphql + You can access it at: https://${{env.NGROK_URL}}/subgraphs/name/${{SUBGRAPH_NAME}}/graphql - name: Stop Docker containers if: github.event.pull_request.merged == true || github.event.pull_request.closed == true From 08af19494f9ca5c8372bfd8e061cc92dd102144f Mon Sep 17 00:00:00 2001 From: gratestas Date: Sun, 19 Mar 2023 16:12:24 +0300 Subject: [PATCH 08/13] fix: line identation --- .github/workflows/deploy-staging.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index d049bc8..342c883 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -40,24 +40,24 @@ jobs: # while [[ "$(docker-compose ps -q | xargs docker inspect --format '{{.State.Status}}')" != "running" ]]; do sleep 2; done - name: Download and install ngrok - run: | + run: | curl -s https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok.zip unzip ngrok.zip sudo mv ngrok /usr/local/bin - - name: Start ngrok tunnel for Graph Node - run: | - ngrok authtoken ${{ secrets.NGROK_AUTH_TOKEN }} - ngrok http 8020 > /dev/null & + - name: Start ngrok tunnel for Graph Node + run: | + ngrok authtoken ${{ secrets.NGROK_AUTH_TOKEN }} + ngrok http 8020 > /dev/null & - - name: Install jq - run: sudo apt-get install -y jq + - name: Install jq + run: sudo apt-get install -y jq - - name: Get ngrok public URL - run: | - sleep 10 - export NGROK_URL=$(curl -s http://localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url') - echo "NGROK_URL=$NGROK_URL" >> $GITHUB_ENV + - name: Get ngrok public URL + run: | + sleep 10 + export NGROK_URL=$(curl -s http://localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url') + echo "NGROK_URL=$NGROK_URL" >> $GITHUB_ENV - name: Create and deploy a local Subgraph run: yarn create-local From 9c7d536080b0ad6c33bfbc189036f3bfe710690a Mon Sep 17 00:00:00 2001 From: gratestas Date: Sun, 19 Mar 2023 16:16:24 +0300 Subject: [PATCH 09/13] fix: line identation --- .github/workflows/deploy-staging.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 342c883..d37b43e 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -36,14 +36,14 @@ jobs: - name: Wait for containers to start run: sleep 10 + # run: | # while [[ "$(docker-compose ps -q | xargs docker inspect --format '{{.State.Status}}')" != "running" ]]; do sleep 2; done - - name: Download and install ngrok run: | - curl -s https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok.zip - unzip ngrok.zip - sudo mv ngrok /usr/local/bin + curl -s https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok.zip + unzip ngrok.zip + sudo mv ngrok /usr/local/bin - name: Start ngrok tunnel for Graph Node run: | @@ -52,7 +52,7 @@ jobs: - name: Install jq run: sudo apt-get install -y jq - + - name: Get ngrok public URL run: | sleep 10 From 598ec3815a8e306874e65ef387845020905aa5c7 Mon Sep 17 00:00:00 2001 From: gratestas Date: Sun, 19 Mar 2023 16:21:08 +0300 Subject: [PATCH 10/13] fix: incorrect call of env variable --- .github/workflows/deploy-staging.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index d37b43e..437ef03 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -71,7 +71,7 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body: | A new subgraph deployment has been created for this pull request. - You can access it at: https://${{env.NGROK_URL}}/subgraphs/name/${{SUBGRAPH_NAME}}/graphql + You can access it at: https://${{env.NGROK_URL}}/subgraphs/name/${{env.SUBGRAPH_NAME}}/graphql - name: Stop Docker containers if: github.event.pull_request.merged == true || github.event.pull_request.closed == true From fc4c1ff9681b217eb26801d718f6d66af4abc529 Mon Sep 17 00:00:00 2001 From: gratestas Date: Sun, 19 Mar 2023 16:33:37 +0300 Subject: [PATCH 11/13] feat: add temp sleep timeout-10 min --- .github/workflows/deploy-staging.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 437ef03..50036c4 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -73,6 +73,9 @@ jobs: A new subgraph deployment has been created for this pull request. You can access it at: https://${{env.NGROK_URL}}/subgraphs/name/${{env.SUBGRAPH_NAME}}/graphql + - name: Wait for 10 mins before completing the workflow + run: sleep 600 + - name: Stop Docker containers if: github.event.pull_request.merged == true || github.event.pull_request.closed == true run: docker-compose down From 16eda19adb817f89d655f73e6fa0ba1d49d2b5a3 Mon Sep 17 00:00:00 2001 From: gratestas Date: Sun, 19 Mar 2023 17:31:52 +0300 Subject: [PATCH 12/13] fix: incorrect port tunnelled for HTTP requests --- .github/workflows/deploy-staging.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 50036c4..63a46ef 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -48,7 +48,7 @@ jobs: - name: Start ngrok tunnel for Graph Node run: | ngrok authtoken ${{ secrets.NGROK_AUTH_TOKEN }} - ngrok http 8020 > /dev/null & + ngrok http 8000 > /dev/null & - name: Install jq run: sudo apt-get install -y jq From 3f73e42e43ce973c989db8c131be9b14b6b84e63 Mon Sep 17 00:00:00 2001 From: gratestas Date: Sun, 19 Mar 2023 18:57:18 +0300 Subject: [PATCH 13/13] refactor: change trigger event to --- .github/workflows/deploy-production.yml | 41 +++++++++++++++++++++++++ .github/workflows/deploy.yml | 34 -------------------- 2 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/deploy-production.yml delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml new file mode 100644 index 0000000..2a132f2 --- /dev/null +++ b/.github/workflows/deploy-production.yml @@ -0,0 +1,41 @@ +name: Deploy Subgraph - Live + +on: + workflow_dispatch: + inputs: + network: + description: The network to deploy the subgraph to + required: true + default: "goerli" + type: choice + options: + - mainnet + - goerli + +jobs: + deploy-production: + runs-on: ubuntu-latest + environment: production + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: 16 + + - name: Install dependencies + run: yarn install + + - name: Build subgraph + run: | + export NETWORK_NAME=${{ inputs.network }} + yarn codegen + yarn build + + - name: Authenticate with TheGraph + run: yarn graph auth https://api.thegraph.com/deploy/ ${{ secrets.SUBGRAPH_AUTH_TOKEN }} + + - name: Deploy subgraph + run: yarn deploy diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 6d466ab..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Deploy Subgraph - -on: - push: - branch: - - master - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: 16 - - - name: Install dependencies - run: yarn install - - - name: subgraph codegen - run: yarn codegen - - - name: build subgprah - run: yarn build - - - name: authenticate subgraph - run: yarn graph auth https://api.thegraph.com/deploy/ ${{secrets.SUBGRAPH_AUTH_TOKEN}} - - - name: deploy subgraph - run: yarn deploy