Skip to content

Commit e2a9688

Browse files
Merge branch 'develop' into feature/detect-user-chain
2 parents 28a1cc9 + 5ab3947 commit e2a9688

File tree

11 files changed

+2870
-3255
lines changed

11 files changed

+2870
-3255
lines changed

.drone.yml

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -531,105 +531,6 @@ steps:
531531
password:
532532
from_secret: dockerhub-password
533533

534-
---
535-
kind: pipeline
536-
type: docker
537-
name: subgraph deploy
538-
539-
trigger:
540-
event:
541-
- promote
542-
target:
543-
# deploy the dataprotector subgraph for the staging environment
544-
- subgraph-deploy-staging
545-
# deploy the dataprotector subgraph
546-
- subgraph-deploy-tmp
547-
# deploy the dataprotector subgraph for the prod environment
548-
- subgraph-deploy-prod
549-
branch:
550-
- develop
551-
- main
552-
553-
steps:
554-
- name: install deps
555-
image: node:18.19
556-
pull: always
557-
commands:
558-
- cd packages/subgraph
559-
- npm ci
560-
561-
- name: deploy-v2-staging
562-
image: node:18.19
563-
params:
564-
- START_BLOCK
565-
environment:
566-
GRAPHNODE_URL:
567-
from_secret: graphnode-url-staging
568-
IPFS_URL:
569-
from_secret: ipfs-url-staging
570-
ENV: staging
571-
commands:
572-
- cd packages/subgraph
573-
- export SUBGRAPH_NAME=bellecour/staging-dataprotector-v2
574-
- echo "deploying commit $DRONE_COMMIT on subgraph $SUBGRAPH_NAME"
575-
- npm run codegen
576-
- npm run build
577-
- npx graph create --node $GRAPHNODE_URL $SUBGRAPH_NAME
578-
- npx graph deploy --node $GRAPHNODE_URL $SUBGRAPH_NAME --ipfs $IPFS_URL --version-label $(npm pkg get version)
579-
when:
580-
target:
581-
- subgraph-deploy-staging
582-
branch:
583-
- develop
584-
585-
- name: deploy-v2-tmp
586-
image: node:18.19
587-
params:
588-
- START_BLOCK
589-
environment:
590-
GRAPHNODE_URL:
591-
from_secret: graphnode-url
592-
IPFS_URL:
593-
from_secret: ipfs-url
594-
ENV: prod
595-
commands:
596-
- cd packages/subgraph
597-
- export SUBGRAPH_NAME=bellecour/tmp-dataprotector-v2
598-
- echo "deploying commit $DRONE_COMMIT on subgraph $SUBGRAPH_NAME"
599-
- npm run codegen
600-
- npm run build
601-
- npx graph create --node $GRAPHNODE_URL $SUBGRAPH_NAME
602-
- npx graph deploy --node $GRAPHNODE_URL $SUBGRAPH_NAME --ipfs $IPFS_URL --version-label $DRONE_COMMIT
603-
when:
604-
target:
605-
- subgraph-deploy-tmp
606-
branch:
607-
- main
608-
609-
- name: deploy-v2-prod
610-
image: node:18.19
611-
params:
612-
- START_BLOCK
613-
environment:
614-
GRAPHNODE_URL:
615-
from_secret: graphnode-url
616-
IPFS_URL:
617-
from_secret: ipfs-url
618-
ENV: prod
619-
commands:
620-
- cd packages/subgraph
621-
- export SUBGRAPH_NAME=bellecour/dataprotector-v2
622-
- echo "deploying commit $DRONE_COMMIT on subgraph $SUBGRAPH_NAME"
623-
- npm run codegen
624-
- npm run build
625-
- npx graph create --node $GRAPHNODE_URL $SUBGRAPH_NAME
626-
- npx graph deploy --node $GRAPHNODE_URL $SUBGRAPH_NAME --ipfs $IPFS_URL --version-label $(npm pkg get version)
627-
when:
628-
target:
629-
- subgraph-deploy-prod
630-
branch:
631-
- main
632-
633534
---
634535
#pipeline to deploy app whitelist on iexec
635536
kind: pipeline
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Deploy Subgraph
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
include:
12+
- target: staging
13+
subgraph_name: "bellecour/staging-dataprotector-v2"
14+
branch: develop
15+
env_name: staging
16+
graphnode_url: ${{ secrets.GRAPHNODE_URL_STAGING }}
17+
ipfs_url: ${{ secrets.IPFS_URL_STAGING }}
18+
version_method: npm_version
19+
- target: tmp
20+
subgraph_name: "bellecour/tmp-dataprotector-v2"
21+
branch: main
22+
env_name: prod
23+
graphnode_url: ${{ secrets.GRAPHNODE_URL }}
24+
ipfs_url: ${{ secrets.IPFS_URL }}
25+
version_method: commit
26+
- target: prod
27+
subgraph_name: "bellecour/dataprotector-v2"
28+
branch: main
29+
env_name: prod
30+
graphnode_url: ${{ secrets.GRAPHNODE_URL }}
31+
ipfs_url: ${{ secrets.IPFS_URL }}
32+
version_method: npm_version
33+
34+
# Run only if the current branch matches the matrix branch
35+
if: github.ref == format('refs/heads/{0}', matrix.subgraph.branch)
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: actions/setup-node@v4
39+
with:
40+
node-version: 18
41+
42+
- name: Install Dependencies
43+
working-directory: packages/subgraph
44+
run: npm ci
45+
46+
- name: Run Codegen and Build
47+
working-directory: packages/subgraph
48+
run: |
49+
npm run codegen
50+
npm run build
51+
52+
- name: Set Version Label
53+
id: set_version
54+
working-directory: packages/subgraph
55+
run: |
56+
if [ "${{ matrix.subgraph.version_method }}" = "commit" ]; then
57+
echo "version=${GITHUB_SHA}" >> $GITHUB_OUTPUT
58+
else
59+
version=$(npm pkg get version | sed 's/"//g')
60+
echo "version=${version}" >> $GITHUB_OUTPUT
61+
fi
62+
63+
- name: Create Subgraph
64+
working-directory: packages/subgraph
65+
run: |
66+
npx graph create --node ${{ matrix.subgraph.graphnode_url }} ${{ matrix.subgraph.subgraph_name }}
67+
68+
- name: Deploy Subgraph
69+
working-directory: packages/subgraph
70+
run: |
71+
npx graph deploy --node ${{ matrix.subgraph.graphnode_url }} ${{ matrix.subgraph.subgraph_name }} --ipfs ${{ matrix.subgraph.ipfs_url }} --version-label ${{ steps.set_version.outputs.version }}

packages/subgraph/.env.template

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
# environment to use for configuration (prod/staging)
2-
ENV=prod
1+
# The name of the network (e.g., mainnet, arbitrum, etc.)
2+
NETWORK_NAME=...
33

4-
# override the starting block for indexation of all contracts events
5-
# START_BLOCK=0
4+
# The URL of the Graph Node endpoint for self-hosted Graph Node
5+
GRAPHNODE_URL=...
66

7-
# AppRegistry contract address override
8-
# APP_REGISTRY_ADDRESS=0x...
7+
# The URL of the IPFS endpoint for self-hosted IPFS
8+
IPFS_URL=...
99

10-
# DatasetRegistry contract address override
11-
# DATASET_REGISTRY_ADDRESS=0x...
12-
13-
# Dataprotector contract address override
14-
# DATAPROTECTOR_ADDRESS=0x...
15-
16-
# DataprotectorSharing contract address override
17-
# DATAPROTECTOR_SHARING_ADDRESS=0x...
18-
19-
# AddOnlyAppWhitelistRegistry contract address override
20-
# ADD_ONLY_APP_WHITELIST_REGISTRY_ADDRESS=0x...
10+
# The version label for the deployment (e.g., v1.0.0)
11+
VERSION_LABEL=...

packages/subgraph/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ coverage.json
1111
# subgraph
1212
generated
1313
subgraph.yaml
14+
tests/.latest.json

packages/subgraph/README.md

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,69 @@
11
# Subgraph
22

3+
This repository contains the code for the DataProtector subgraph, which indexes blockchain events to make them queryable through a GraphQL API.
4+
35
## Build the Subgraph
46

5-
And you have finishing editing the schema.graphql & subgraph.yaml files. Type the following command
7+
After editing the schema.graphql & subgraph.yaml files, build the subgraph with:
68

79
```bash
810
npm run codegen
911
npm run build
1012
```
1113

12-
Then you have to write ./src/bays.ts files in order to update the graph when new events appear. In this way, it will always be up to date.
14+
Then implement event handlers in the ./src files to keep the graph updated when new events occur on the blockchain.
15+
16+
## Deployment Options
1317

14-
## Local
18+
### Local Development
1519

16-
### Deploy on Local Graph node
20+
To deploy on a local Graph Node:
1721

1822
```bash
1923
npm run create-local
2024
npm run deploy-local
2125
```
2226

23-
### Test Subgrah API
27+
The subgraph will be available at: http://localhost:8000/subgraphs/name/DataProtector/graphql
28+
29+
### Hosted Production Environments
30+
31+
We use CI/CD pipelines to deploy our subgraphs to hosted environments.
32+
33+
#### Docker Image Tags
34+
35+
When building and pushing Docker images, the following tag generation strategy is used:
36+
37+
| Trigger | Environment | Tag Format | Example | Push? |
38+
|---------|-------------|------------|---------|-------|
39+
| Manual workflow dispatch | Production | `{package.json version}` | `1.2.3` | Yes |
40+
| Manual workflow dispatch | Development | `dev-{commit SHA}` | `dev-8e7d3f2` | Yes |
41+
| Push to `main` branch | Production | `{package.json version}` | `1.2.3` | Yes |
42+
| Push to `develop` branch | Development | `dev-{commit SHA}` | `dev-8e7d3f2` | Yes |
43+
| Tag push | N/A | `{tag name}` | `v1.2.3-beta` | Yes |
44+
| Other branch push | Development | `dev-{commit SHA}` | `dev-8e7d3f2` | No |
2445

25-
Deployed to : <http://localhost:8000/subgraphs/name/DataProtector/graphql>
46+
### Self-Hosted Subgraph Deployment Process
2647

27-
Request Example on GraphiQL :
48+
For zero-downtime updates to the production subgraph:
2849

29-
Query for GraphiQL API
50+
1. **Index the New Version (Temporary Deployment)**
51+
- Trigger deployment with target: `subgraph-deploy-tmp`
52+
- This creates a separate instance for indexing
53+
54+
2. **Wait for Indexing Completion**
55+
- Monitor the temporary deployment until it's fully synced
56+
57+
3. **Deploy to Production (Zero Downtime)**
58+
- Once temporary deployment is ready, trigger: `subgraph-deploy-prod`
59+
- This swaps the deployments with no service interruption
60+
61+
4. **Verify the Deployment**
62+
- Access the production subgraph at: https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2/graphql
63+
64+
## Query Examples
65+
66+
### Sample GraphQL Query
3067

3168
```graphql
3269
query MyQuery($requiredSchema: [String!]!, $start: Int!, $range: Int!) {
@@ -57,48 +94,27 @@ query MyQuery($requiredSchema: [String!]!, $start: Int!, $range: Int!) {
5794
}
5895
```
5996

60-
```graphql
61-
Query Variables :
97+
### Query Variables
6298

99+
```json
63100
{
64101
"start": 0,
65102
"range": 1000,
66103
"requiredSchema": []
67104
}
68105
```
69106

70-
## Hosted
71-
72-
You can trigger a deployment using the promote action on the CI.
73-
74-
### Self Hosted Subgraph
75-
76-
To deploy a new version of a subgraph on the iExec self-hosted service, follow these steps:
77-
78-
1. Index the New Subgraph
79-
80-
First, index the new version of the subgraph using the temporary subgraph deployment.
81-
Trigger its deployment with the target:
82-
83-
```sh
84-
subgraph-deploy-tmp
85-
```
86-
87-
2. Wait for Indexing Completion
88-
89-
Once the temporary subgraph has finished indexing, you can proceed to the production deployment.
90-
91-
3. Deploy to Production (No Downtime)
92-
93-
Trigger the production deployment with :
94-
95-
```sh
96-
subgraph-deploy-prod
97-
```
107+
## Development Workflow
98108

99-
This ensures a seamless transition with no downtime.
109+
1. Update schema.graphql and subgraph.yaml as needed
110+
2. Run codegen to generate TypeScript types: `npm run codegen`
111+
3. Implement mapping handlers in src/ files
112+
4. Build the subgraph: `npm run build`
113+
5. Test locally before deploying to production environments
100114

101-
4. Verify the Deployment
115+
## CI/CD Integration
102116

103-
Visit the following URL to check the new version of the subgraph:
104-
<https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2/graphql>
117+
Our repository uses automated workflows to build, test, and deploy the subgraph:
118+
- ABI validation checks ensure contract ABIs are up-to-date
119+
- Docker images are built and pushed with appropriate tags based on the source branch
120+
- Deployment follows a staged approach to ensure zero downtime

packages/subgraph/config/env.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'dotenv/config';
2+
import { z } from 'zod';
3+
4+
const envSchema = z.object({
5+
NETWORK_NAME: z.string().min(1, 'NETWORK_NAME is required').default('bellecour'),
6+
7+
GRAPHNODE_URL: z
8+
.string()
9+
.url('GRAPHNODE_URL must be a valid URL')
10+
.default('http://localhost:8020'),
11+
12+
IPFS_URL: z.string().url('IPFS_URL must be a valid URL').default('http://localhost:5001'),
13+
14+
VERSION_LABEL: z.string().min(1, 'VERSION_LABEL is required').default('bellecour/poco-v5'),
15+
});
16+
17+
export const env = envSchema.parse(process.env);

0 commit comments

Comments
 (0)