Skip to content

Commit

Permalink
create template tot automate network deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
gfournieriExec committed Jul 5, 2024
1 parent d75d429 commit c6de852
Show file tree
Hide file tree
Showing 4 changed files with 393 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,51 @@ debugging:

_NB_: other blockchains setups are availables in [docker/README.md](./docker/README.md).

Sure, here's a summarized version for your README:

---

## Generating Subgraph and Jenkins Configuration Files

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`.


**Run the script with the network name**:
```bash
./generate_subgraph.sh <network-name>
```

### Configuration

Ensure `config.json` is populated with the required values. Example:

```json
{
"bellecour": {
"STARTBLOCK": 4543300,
"ERC1538_ADDRESS": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"IEXECE_INTERFACE_TOKEN_CORE_ADDRESS": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"APP_REGISTRY_ADDRESS": "0xB1C52075b276f87b1834919167312221d50c9D16",
"DATATSET_REGISTRY_ADDRESS": "0x799DAa22654128d0C64d5b79eac9283008158730",
"WORKERPOOL_REGISTRY_ADDRESS": "0xC76A18c78B7e530A165c5683CB1aB134E21938B4"
}
}
```

### Files Generated

- **subgraph.<network>.yaml**: Subgraph configuration with placeholders replaced.
- **Jenkinsfile.<network>**: Jenkinsfile for deploying the subgraph.

#### Example Command

```bash
./generate_subgraph.sh bellecour
```

This command generates `subgraph.bellecour.yaml` and `Jenkinsfile.bellecour`.


## Resources

- [thegraph docs](https://thegraph.com/docs/en/)
58 changes: 58 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"bellecour": {
"STARTBLOCK": 4543300,
"ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16",
"DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730",
"WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4"
},
"c13": {
"STARTBLOCK": 4543300,
"ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16",
"DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730",
"WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4"
},
"goerli": {
"STARTBLOCK": 2564000,
"ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16",
"DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730",
"WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4"
},
"mainnet": {
"STARTBLOCK": 9917600,
"ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16",
"DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730",
"WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4"
},
"rinkeby": {
"STARTBLOCK": 6355862,
"ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16",
"DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730",
"WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4"
},
"viviani": {
"STARTBLOCK": 5556000,
"ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f",
"APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16",
"DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730",
"WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4"
},
"test": {
"STARTBLOCK": 0,
"ERC1538_ADDRESS" : "0xC129e7917b7c7DeDfAa5Fff1FB18d5D7050fE8ca",
"IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0xC129e7917b7c7DeDfAa5Fff1FB18d5D7050fE8ca",
"APP_REGISTRY_ADDRESS" : "0xbB66c75dc79D21E8A5b9EF5DE346021082469892",
"DATATSET_REGISTRY_ADDRESS" : "0xe325907A7E0E320A4dcBfAC0cBCda120e7788A0D",
"WORKERPOOL_REGISTRY_ADDRESS" : "0xDaecE9E92C2414D1F4AFcf6B79d76A2491dfd6A6"
}
}
69 changes: 69 additions & 0 deletions generate_subgraph.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "jq is required but not installed. Please install jq to proceed."
exit 1
fi

# Function to replace placeholders in the template
generate_yaml() {
local network=$1
local config_file="config.json"
local template_file="subgraph.bellecour.template.yaml"
local output_file="subgraph.${network}.yaml"

# Read values from config.json
local start_block=$(jq -r ".${network}.STARTBLOCK" ${config_file})
local erc1538_address=$(jq -r ".${network}.ERC1538_ADDRESS" ${config_file})
local core_address=$(jq -r ".${network}.IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" ${config_file})
local app_registry_address=$(jq -r ".${network}.APP_REGISTRY_ADDRESS" ${config_file})
local dataset_registry_address=$(jq -r ".${network}.DATATSET_REGISTRY_ADDRESS" ${config_file})
local workerpool_registry_address=$(jq -r ".${network}.WORKERPOOL_REGISTRY_ADDRESS" ${config_file})

# Replace placeholders in the template and create the output file
sed -e "s/#NETWORK_NAME#/network: ${network}/g" \
-e "s/#STARTBLOCK#/startBlock: ${start_block}/g" \
-e "s|#ERC1538_ADDRESS#|address: \"${erc1538_address}\"|g" \
-e "s|#IEXECE_INTERFACE_TOKEN_CORE_ADDRESS#|address: \"${core_address}\"|g" \
-e "s|#APP_REGISTRY_ADDRESS#|address: \"${app_registry_address}\"|g" \
-e "s|#DATATSET_REGISTRY_ADDRESS#|address: \"${dataset_registry_address}\"|g" \
-e "s|#WORKERPOOL_REGISTRY_ADDRESS#|address: \"${workerpool_registry_address}\"|g" \
${template_file} > ${output_file}

echo "Generated ${output_file}"
}


# Function to create the Jenkinsfile
generate_jenkinsfile() {
local network=$1
local jenkinsfile="Jenkinsfile_Subgraph_${network}"

cat <<EOL > ${jenkinsfile}
//Readme @ http://gitlab.iex.ec:30000/iexec/jenkins-library
@Library('[email protected]') _
deploySubGraph(
targetRemoteHost : 'azubgrpvx-thegraph-${network}.public.az2.internal',
subgraphFolder: './',
subgraphFilename: 'subgraph.${network}.yaml',
subgraphVersionLabel: 'v1.0.0-rc.1',
subgraphLabel: '${network}/poco-v5'
)
EOL

echo "Generated ${jenkinsfile}"
}

# Check if the user provided a network name
if [ -z "$1" ]; then
echo "Usage: $0 <network-name>"
exit 1
fi

network_name=$1

# Generate the YAML file for the specified network
generate_yaml ${network_name}
generate_jenkinsfile ${network_name}
Loading

0 comments on commit c6de852

Please sign in to comment.