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-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 0000000..63a46ef --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -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 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 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 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 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 + } + } +} 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",