Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: staging deployment #6

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
41 changes: 41 additions & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
@@ -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
81 changes: 81 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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: 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 8000 > /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

- name: Deploy a local Subgraph
run: yarn deploy-local --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://${{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
34 changes: 0 additions & 34 deletions .github/workflows/deploy.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
node_modules/

# artifacts
build/
generated/

# graph node
data/

.idea/
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
# <https://github.com/graphprotocol/graph-node/pull/3511>, 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
8 changes: 8 additions & 0 deletions networks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"goerli": {
"ProveMeWrong": {
"address": "0x0136ed2132Ec1e99046889058F67c9C2fd5FD578",
"startBlock": 6790826
}
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down