diff --git a/.gitignore b/.gitignore index 37c75ed..bd5172e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ build generated yarn.lock test/.bin -subgraph.yaml subgraph.test.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a3ea43..2a60463 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## vNEXT +- Rewrite Jenkins CI for future migration (#36) + ## v1.1.0 - Support deal sponsor - Add `sponsor` to `deal`. (#31) - Update deployment hosts: diff --git a/Jenkinsfile b/Jenkinsfile index c2d0824..bf291ae 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,63 +1,67 @@ -@Library('global-jenkins-library@2.7.7') _ +//Readme @ http://gitlab.iex.ec:30000/iexec/jenkins-library +@Library('global-jenkins-library@feature/subgraph-networks') _ def userInput node { - docker.image('node:20-alpine').inside('--user root') { - stage('Setup') { - checkout scm + stage('Choose deployment parameters') { + timeout(time: 5, unit: 'MINUTES') { + userInput = input( + id: 'deployment-params', + message: 'Select deployment parameters', + parameters: [ + choice( + name: 'networkName', + choices: ['bellecour'], + description: 'Select the target network' + ), + choice( + name: 'environment', + choices: ['staging','tmp','prod'], + description: 'Select deployment environment' + ), + string( + name: 'versionLabel', + defaultValue: 'v1.0.0', + description: 'Version label for the deployment' + ), + string( + name: 'subgraphName', + defaultValue: 'poco-v5', + description: 'Name of the subgraph' + ) + ] + ) } - stage('Choose network and host') { - timeout(time: 5, unit: 'MINUTES') { - userInput = input( - id: 'select-deployment', - message: 'Select environment & service', - parameters: [ - string(name: 'network', description: 'Target network name of the subgraph'), - string(name: 'targetRemoteHost', description: 'Hostname where to deploy the subgraph') - ] - ) - } - echo "Selected network: '${userInput.network}'" - echo "Selected hostname: '${userInput.targetRemoteHost}'" - } - - stage('Setup Docker Image') { - sh 'apk add jq bash' - } - - stage('Generate subgraph file') { - sh """ - bash generate_subgraph_file.sh '${userInput.network}' - """ - - // Validate subgraph file generation - sh """ - FILE=./subgraph.${userInput.network}.yaml - if test -f "\$FILE"; then - echo "Subgraph file generated successfully" - else - echo "Failed to generate subgraph file" - exit 1 - fi - """ - } - - stage('Build') { - sh """ - yarn global add @graphprotocol/graph-cli && - cd ./ && - yarn install && - graph codegen subgraph.${userInput.network}.yaml && - graph build subgraph.${userInput.network}.yaml && - graph create ${userInput.network}/poco-v5 --node http://${userInput.targetRemoteHost}:8020 && - graph deploy ${userInput.network}/poco-v5 subgraph.${userInput.network}.yaml --node http://${userInput.targetRemoteHost}:8020 --ipfs http://${userInput.targetRemoteHost}:5001 --version-label v1.0.0-rc.1 - """ - } - - stage('The End') { - echo 'The end.' - } + // Define host mappings + def hosts = [ + 'staging': [ + 'graphNode': 'azubgrpbx-thegraph-staging.public.az2.internal', + 'ipfs': 'ipfs-upload.stagingv8.iex.ec', + 'env' : 'staging-' + ], + 'tmp': [ + 'graphNode': 'azubgrpbp-thegraph.public.az2.internal', + 'ipfs': 'ipfs-upload.v8-bellecour.iex.ec', + 'env' : 'tmp-' + ], + 'prod': [ + 'graphNode': 'azubgrpbp-thegraph.public.az2.internal', + 'ipfs': 'ipfs-upload.v8-bellecour.iex.ec', + 'env' : '' + ] + ] + + // Call deploySubGraph with user inputs + deploySubGraph( + targetRemoteHostGraphNode: hosts[userInput.environment].graphNode, + targetRemoteHostIPFS: hosts[userInput.environment].ipfs, + subgraphFolder: './', + networkName: userInput.networkName, + deployEnv: hosts[userInput.environment].env, + subgraphName: userInput.subgraphName, + subgraphVersionLabel: userInput.versionLabel + ) } } diff --git a/Jenkinsfile_Subgraph_bellecour_stagingv8 b/Jenkinsfile_Subgraph_bellecour_stagingv8 deleted file mode 100644 index 8208816..0000000 --- a/Jenkinsfile_Subgraph_bellecour_stagingv8 +++ /dev/null @@ -1,11 +0,0 @@ -//Readme @ http://gitlab.iex.ec:30000/iexec/jenkins-library - -@Library('global-jenkins-library@2.8.1') _ -deploySubGraph( - targetRemoteHostGraphNode : 'azubgrpbx-thegraph-staging.public.az2.internal', - targetRemoteHostIPFS : 'ipfs-upload.stagingv8.iex.ec', - subgraphFolder: './', - subgraphFilename: 'subgraph.bellecour.yaml', - subgraphVersionLabel: 'v1.1.0', - subgraphLabel: 'bellecour/poco-v5' -) diff --git a/README.md b/README.md index 2240884..2261e09 100644 --- a/README.md +++ b/README.md @@ -62,45 +62,70 @@ _NB_: other blockchains setups are availables in [docker/README.md](./docker/REA --- -## Generating Subgraph and Jenkins Configuration Files +Here's the revised "Generating Subgraph and Jenkins Configuration Files" section for your README: -This project includes a bash script, `generate_subgraph.sh`, to automate the creation of subgraph YAML configuration files and Jenkinsfiles based on the network settings in `config.json`. +## Deployment Configuration -**Run the script with the network name**: -```bash -bash generate_subgraph_file.sh -``` +### Jenkins Pipeline Deployment + +The project uses a Jenkins pipeline for automated deployment of the subgraph. The deployment can be triggered through Jenkins with interactive parameter selection. + +#### Available Parameters + +- **Network**: Choose the target blockchain network +- **Environment**: Select deployment environment + - `staging`: Deploy to staging environment + - `tmp`: Deploy to temporary environment + - `prod`: Deploy to production environment +- **Version Label**: Specify the version of the deployment (e.g., `v1.0.0`) +- **Subgraph Name**: Name of the subgraph (default: `poco-v5`) + +#### Environment-specific Configurations -### Configuration +Each environment has specific host configurations: -Ensure `config.json` is populated with the required values. Example: +### Adding New Networks + +To add support for a new network, update the `networks.json` file with the network configuration: ```json { - "bellecour": { - "START_BLOCK": 4543300, - "ERC1538_ADDRESS": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", - "IEXECE_INTERFACE_TOKEN_CORE_ADDRESS": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", - "APP_REGISTRY_ADDRESS": "0xB1C52075b276f87b1834919167312221d50c9D16", - "DATATSET_REGISTRY_ADDRESS": "0x799DAa22654128d0C64d5b79eac9283008158730", - "WORKERPOOL_REGISTRY_ADDRESS": "0xC76A18c78B7e530A165c5683CB1aB134E21938B4" + "network-name": { + "ERC1538": { + "address": "0x...", + "startBlock": 1234567 + }, + "Core": { + "address": "0x...", + "startBlock": 1234567 + }, + "AppRegistry": { + "address": "0x...", + "startBlock": 1234567 + }, + "DatasetRegistry": { + "address": "0x...", + "startBlock": 1234567 + }, + "WorkerpoolRegistry": { + "address": "0x...", + "startBlock": 1234567 + } } } ``` -### Files Generated - -- **subgraph..yaml**: Subgraph configuration with placeholders replaced. - -#### Example Command - -```bash -bash generate_subgraph_file.sh bellecour +Also, update the Jenkins pipeline choices to include the new network: +```groovy +choice( + name: 'networkName', + choices: ['bellecour', 'new-network'], + description: 'Select the target network' +) ``` -This command generates `subgraph.bellecour.yaml`. - +The deployment process will automatically generate the appropriate subgraph configuration using the network-specific addresses and start blocks from `networks.json`. ## Resources diff --git a/networks.json b/networks.json index 9497c64..7b7d1d3 100644 --- a/networks.json +++ b/networks.json @@ -42,5 +42,27 @@ "address": "0xC76A18c78B7e530A165c5683CB1aB134E21938B4", "startBlock": 4543300 } + }, + "mainnet": { + "ERC1538": { + "address": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "startBlock": 9917600 + }, + "Core": { + "address": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "startBlock": 9917600 + }, + "AppRegistry": { + "address": "0xB1C52075b276f87b1834919167312221d50c9D16", + "startBlock": 9917600 + }, + "DatasetRegistry": { + "address": "0x799DAa22654128d0C64d5b79eac9283008158730", + "startBlock": 9917600 + }, + "WorkerpoolRegistry": { + "address": "0xC76A18c78B7e530A165c5683CB1aB134E21938B4", + "startBlock": 9917600 + } } } diff --git a/subgraph.yaml b/subgraph.yaml new file mode 100644 index 0000000..5367360 --- /dev/null +++ b/subgraph.yaml @@ -0,0 +1,194 @@ +# SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH +# SPDX-License-Identifier: Apache-2.0 + +specVersion: 0.0.4 +description: iExecPoCoV5 +repository: https://github.com/iExecBlockchainComputing/PoCo-subgraph +schema: + file: ./schema.graphql +dataSources: + - name: ERC1538 + kind: ethereum/contract + source: + abi: ERC1538 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - ERC1538Module + - ERC1538Function + - ERC1538FunctionUpdateEvent + - ERC1538CommitMessageEvent + abis: + - name: ERC1538 + file: node_modules/@iexec/solidity/build/contracts/IERC1538.json + eventHandlers: + - event: CommitMessage(string) + handler: handleCommitMessage + - event: FunctionUpdate(indexed bytes4,indexed address,indexed address,string) + handler: handleFunctionUpdate + file: ./src/ERC1538/ERC1538.ts + + - name: Core + kind: ethereum/contract + source: + abi: IexecInterfaceToken + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Category + - Account + - AppOrder + - DatasetOrder + - WorkerpoolOrder + - RequesterOrder + - Deal + - SchedulerNotice + - Task + - Contribution + - TaskInitialize + - TaskContribute + - TaskConsensus + - TaskReveal + - TaskReopen + - TaskFinalize + - TaskClaimed + - AccurateContribution + - FaultyContribution + - Transfer + - Reward + - Seize + - Lock + - Unlock + abis: + - name: IexecInterfaceToken + file: node_modules/@iexec/poco/artifacts/contracts/IexecInterfaceNative.sol/IexecInterfaceNative.json + eventHandlers: + - event: CreateCategory(uint256,string,string,uint256) + handler: handleCreateCategory + - event: OrdersMatched(bytes32,bytes32,bytes32,bytes32,bytes32,uint256) + handler: handleOrdersMatched + - event: SchedulerNotice(indexed address,bytes32) + handler: handleSchedulerNotice + - event: TaskInitialize(indexed bytes32,indexed address) + handler: handleTaskInitialize + - event: TaskContribute(indexed bytes32,indexed address,bytes32) + handler: handleTaskContribute + - event: TaskConsensus(indexed bytes32,bytes32) + handler: handleTaskConsensus + - event: TaskReveal(indexed bytes32,indexed address,bytes32) + handler: handleTaskReveal + - event: TaskReopen(indexed bytes32) + handler: handleTaskReopen + - event: TaskFinalize(indexed bytes32,bytes) + handler: handleTaskFinalize + - event: TaskClaimed(indexed bytes32) + handler: handleTaskClaimed + - event: AccurateContribution(indexed address,indexed bytes32) + handler: handleAccurateContribution + - event: FaultyContribution(indexed address,indexed bytes32) + handler: handleFaultyContribution + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransfer + - event: Reward(address,uint256,bytes32) + handler: handleReward + - event: Seize(address,uint256,bytes32) + handler: handleSeize + - event: Lock(address,uint256) + handler: handleLock + - event: Unlock(address,uint256) + handler: handleUnlock + callHandlers: # require trace_filter access + - function: matchOrders((address,uint256,uint256,bytes32,address,address,address,bytes32,bytes),(address,uint256,uint256,bytes32,address,address,address,bytes32,bytes),(address,uint256,uint256,bytes32,uint256,uint256,address,address,address,bytes32,bytes),(address,uint256,address,uint256,address,uint256,address,uint256,bytes32,uint256,uint256,address,address,string,bytes32,bytes)) + handler: handleMatchOrders + file: ./src/Modules/index.ts + + # =============================== App registry ================================ + - name: AppRegistry + kind: ethereum/contract + source: + abi: AppRegistry + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - App + - AppTransfer + abis: + - name: App + file: node_modules/@iexec/poco/build/contracts/App.json + - name: AppRegistry + file: node_modules/@iexec/poco/build/contracts/AppRegistry.json + eventHandlers: + - event: Transfer(indexed address,indexed address,indexed uint256) + handler: handleTransferApp + file: ./src/Registries/index.ts + + # ============================= Dataset registry ============================== + - name: DatasetRegistry + kind: ethereum/contract + source: + abi: DatasetRegistry + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Dataset + - DatasetTransfer + abis: + - name: Dataset + file: node_modules/@iexec/poco/build/contracts/Dataset.json + - name: DatasetRegistry + file: node_modules/@iexec/poco/build/contracts/DatasetRegistry.json + eventHandlers: + - event: Transfer(indexed address,indexed address,indexed uint256) + handler: handleTransferDataset + file: ./src/Registries/index.ts + + # ============================ Workerpool registry ============================ + - name: WorkerpoolRegistry + kind: ethereum/contract + source: + abi: WorkerpoolRegistry + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Workerpool + - WorkerpoolTransfer + abis: + - name: Workerpool + file: node_modules/@iexec/poco/build/contracts/Workerpool.json + - name: WorkerpoolRegistry + file: node_modules/@iexec/poco/build/contracts/WorkerpoolRegistry.json + eventHandlers: + - event: Transfer(indexed address,indexed address,indexed uint256) + handler: handleTransferWorkerpool + file: ./src/Registries/index.ts + +# ============================ Workerpool template ============================ +templates: + - name: Workerpool + kind: ethereum/contract + source: + abi: Workerpool + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Workerpool + - PolicyChange + abis: + - name: Workerpool + file: node_modules/@iexec/poco/build/contracts/Workerpool.json + eventHandlers: + - event: PolicyUpdate(uint256,uint256,uint256,uint256) + handler: handlePolicyUpdate + file: ./src/Registries/index.ts