Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 782ba794f04f6018d1c33015aea72803a44e4ebc
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Thu Jan 4 15:08:39 2024 +0400

    bump relayer

commit 676f307
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Thu Jan 4 14:49:53 2024 +0400

    rm files

commit dfeb315
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Wed Jan 3 16:28:19 2024 +0400

    trig

commit 8aa3991
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Wed Jan 3 16:25:35 2024 +0400

    remove old csc style cicd

commit 1e6e14e
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Wed Jan 3 15:03:31 2024 +0400

    fix wrong entrypoint

commit 0ce0ddf
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Wed Jan 3 15:03:10 2024 +0400

    rm old csc deploy style

commit 5392466
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Wed Jan 3 14:27:20 2024 +0400

    rm debug to force exit code 1 when fails

commit a5f2921
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Thu Dec 21 21:35:22 2023 +0400

    fix mount path

commit 2041ef3
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Thu Dec 21 21:16:45 2023 +0400

    update for csc

commit 26d190b
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Wed Dec 20 16:06:31 2023 +0400

    update generate sh

commit 8869924
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Tue Dec 19 15:54:30 2023 +0400

    upd dockerfile

commit f3330bf
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Tue Dec 19 15:49:30 2023 +0400

    update new way generation

commit 34f152b
Author: wanwiset25 <wanwiset25@gmail.com>
Date:   Tue Dec 19 15:07:55 2023 +0400

    update config
  • Loading branch information
wanwiset25 committed Jan 4, 2024
1 parent 6ce78d4 commit ac9ad1c
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 152 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ jobs:
echo "name=xinfinorg/subnet-generator:${{github.ref_name}}" >> $GITHUB_OUTPUT
fi
- name: Load Subnet commit/branch config (used for genesis gen)
id: commit
run: |
cat docker/puppeth_csc_commit.env
echo commit=$(cat docker/puppeth_csc_commit.env) >> $GITHUB_OUTPUT
- name: Build and push image
run: |
docker build . --file docker/Dockerfile \
Expand Down
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ subnet/bootnodes/*
subnet/logs
subnet/relayer
subnet/stats-service
subnet/deployment-generator/script/gen.env*
XDC-Subnet
keys.json
node_modules
subnet/deployment-generator/generated
subnet/deployment-generator/script/gen.env*
subnet/scripts/faucet/*.env
package-lock.json
package-lock.json
generated
*.env
34 changes: 2 additions & 32 deletions subnet/deployment-generator/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,12 @@

FROM golang:1.14 as builder

ARG SUBNET_BRANCH=master

RUN git clone https://github.com/XinFinOrg/XDC-Subnet

#it is called 'BRANCH' but commits also work
RUN cd XDC-Subnet && git checkout ${SUBNET_BRANCH} && make puppeth





FROM node:18.15

ARG SUBNET_BRANCH=master
ARG IMAGE_NAME=latest
#inject build arg as ENV
ENV SUBNET_BRANCH=${SUBNET_BRANCH}
ENV IMAGE_NAME=${IMAGE_NAME}
RUN echo SUBNET_BRANCH=${SUBNET_BRANCH}
RUN echo IMAGE_NAME=${IMAGE_NAME}

WORKDIR /app

COPY --from=builder /go/XDC-Subnet/build/bin/puppeth /bin/puppeth
# COPY --from=builder /go/XDC-Subnet/mainnet_contract /app/contract

#this step here for caching
# RUN cd contract && yarn

COPY ./script /app/script
COPY ./src /app/src
COPY ./docker/start.sh /app/start.sh
COPY ./docker/deploy_csc.sh /app/deploy_csc.sh

RUN chmod +x /app/start.sh
RUN chmod +x /app/deploy_csc.sh

RUN cd script && npm install
RUN cd src && npm install

ENTRYPOINT ["bash","/app/start.sh"]
33 changes: 0 additions & 33 deletions subnet/deployment-generator/docker/deploy_csc.sh

This file was deleted.

1 change: 0 additions & 1 deletion subnet/deployment-generator/docker/puppeth_csc_commit.env

This file was deleted.

10 changes: 1 addition & 9 deletions subnet/deployment-generator/docker/start.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
#!/bin/bash
node /app/script/gen.js && puppeth --file /app/generated/genesis_input.yml --out /app/generated/


if [[ -n "${SLEEP}" ]]; then
echo "sleep ${SLEEP}"
sleep ${SLEEP}
else
echo "docker run finished"
fi
node /app/src/gen.js
23 changes: 23 additions & 0 deletions subnet/deployment-generator/script/docker.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CONFIG_PATH=~/subnet
#your current directory


#genesis config
NETWORK_NAME=localsubnet
NUM_MACHINE=1
NUM_SUBNET=3
MAIN_IP=192.168.1.1

#parentchain config
PARENTCHAIN=devnet
PARENTCHAIN_WALLET_PK=0x1111111111111111111111111111111111111111111111111111111111111111

# OS=mac

#docker image versions, default to stable
# VERSION_SUBNET
# VERSION_BOOTNODE
# VERSION_OBSERVER
# VERSION_RELAYER
# VERSION_STATS
# VERSION_FRONTEND
46 changes: 46 additions & 0 deletions subnet/deployment-generator/script/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
VERSION_GENERATOR="generator-csc"
VERSION_CSC="generator-update"
VERSION_SUBNET="feature-puppeth-docker-2"

current_dir="$(cd "$(dirname "$0")" && pwd)"
echo 'checking for docker.env'
if [ ! -f "docker.env" ]; then
echo 'docker.env not found'
exit 1
fi

if ! grep -q "CONFIG_PATH" "docker.env"; then
line="#current directory"$'\n'"CONFIG_PATH=$(pwd)"
echo "$line" | cat - "docker.env" > temp && mv temp "docker.env"
echo 'added CONFIG_PATH to docker.env'
fi

echo 'checking docker images'
if [[ -z "$(docker images -q xinfinorg/subnet-generator:$VERSION_GENERATOR)" ]]; then # || echo "doesn't exist"
docker pull xinfinorg/subnet-generator:$VERSION_GENERATOR
fi
if [[ -z "$(docker images -q xinfinorg/csc:$VERSION_CSC)" ]]; then # || echo "doesn't exist"
docker pull xinfinorg/csc:$VERSION_CSC
fi
if [[ -z "$(docker images -q xinfinorg/xdcsubnets:$VERSION_SUBNET)" ]]; then # || echo "doesn't exist"
docker pull xinfinorg/xdcsubnets:$VERSION_SUBNET
fi

echo ''
echo 'generating configs'
mkdir -p generated
docker run --env-file docker.env -v $current_dir/generated:/app/generated xinfinorg/subnet-generator:$VERSION_GENERATOR || gen_success=false
if [[ $gen_success == false ]]; then
echo 'configs generation failed'
exit 1
fi

echo 'generating genesis.json'
docker run -v $current_dir/generated/:/app/generated/ --entrypoint 'bash' xinfinorg/xdcsubnets:$VERSION_SUBNET /work/puppeth.sh || pup_success=false
if [[ $pup_success == false ]]; then
echo 'genesis.json generation failed'
exit 1
fi

echo 'subnet generation successful'
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ const { off } = require('process');
dotenv.config({ path: `${__dirname}/gen.env` });
// console.log(__dirname)

var config = {
let config = {
deployment_path: (process.env.CONFIG_PATH || ''),
num_machines: parseInt(process.env.NUM_MACHINE),
num_subnet: parseInt(process.env.NUM_SUBNET),
ip_1: (process.env.MAIN_IP || ''),
network_name: (process.env.NETWORK_NAME),
network_id: parseInt(process.env.NETWORK_ID || Math.floor(Math.random() * (65536 - 1) + 1)),
secret_string: (process.env.SERVICES_SECRET || crypto.randomBytes(10).toString('hex')),
relayer_mode: (process.env.RELAYER_MODE || 'full'), //full or lite
relayer_mode: (process.env.RELAYER_MODE || 'full'), //full or lite //in upgradable csc both are deployed
docker_image_name: (process.env.IMAGE_NAME || 'xinfinorg/subnet-generator:latest'),
operating_system: (process.env.OS || 'linux'),
version: {
subnet: (process.env.VERSION_SUBNET || 'v0.2.1'),
bootnode: (process.env.VERSION_BOOTNODE || 'v0.2.1'),
observer: (process.env.VERSION_OBSERVER || 'latest'),
relayer: (process.env.VERSION_RELAYER || 'v0.2.1'),
// observer: (process.env.VERSION_OBSERVER || 'latest'),
relayer: (process.env.VERSION_RELAYER || 'v0.2.2'),
stats: (process.env.VERSION_STATS || 'v0.1.8'),
frontend: (process.env.VERSION_FRONTEND || 'v0.1.8'),
// csc: (process.env.VERSION_CSC || 'v0.1.1'),
csc: (process.env.VERSION_CSC || 'v0.1.1'),
// zero: (process.env.VERSION_ZERO || 'v0.1.1')
},
parentnet:{
Expand Down Expand Up @@ -92,15 +92,16 @@ function configSanityCheck(config){
process.exit(1)
}

if (!(config.parentnet.network === 'devnet' ||
config.parentnet.network === 'testnet' ||
config.parentnet.network === 'mainnet' )){
var official_urls = {
if (config.parentnet.network === 'devnet' ||
config.parentnet.network === 'testnet' ||
config.parentnet.network === 'mainnet' ){
let official_urls = {
'devnet':'https://devnetstats.apothem.network/devnet' ,
'testnet':'https://erpc.apothem.network/' ,
'mainnet': 'https://devnetstats.apothem.network/mainnet' //confirm url
}
config.parentnet.url = official_urls[config.parentnet.network]
} else {
console.log('PARENTNET must be devnet, testnet, or mainnet ')
process.exit(1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Object.freeze(config)
// const output_path = `${__dirname}/../generated/`


keys = gen_other.genSubnetKeys()
let keys = gen_other.genSubnetKeys()

var num_per_machine = Array(config.num_machines)
let num_per_machine = Array(config.num_machines)
//integer division
for (let i=0; i<config.num_machines; i++){
num_per_machine[i] = Math.floor(config.num_subnet / config.num_machines)
Expand All @@ -33,13 +33,13 @@ for (let i=0; i<config.num_subnet%config.num_machines; i++) {
num_per_machine.reverse() //let first machines host services, put fewer subnets

//gen docker-compose
doc = {
let doc = {
'version': '3.7',
'services': {
}
}

start_num = 1
let start_num = 1
for (let i=1; i<=config.num_machines; i++){
var subnet_nodes = gen_compose.genSubnetNodes(machine_id=i, num=num_per_machine[i-1], start_num=start_num)
start_num+=num_per_machine[i-1]
Expand All @@ -50,11 +50,13 @@ for (let i=1; i<=config.num_machines; i++){
}

//gen subnets configs
subnet_services = gen_compose.genServices(machine_id=1)
let subnet_services = gen_compose.genServices(machine_id=1)
Object.entries(subnet_services).forEach(entry => {
const [key, value] = entry;
doc['services'][key]=value
});
//checkpoint smartcontract deployment config
let deployment_json = gen_other.genDeploymentJson(keys)

if (config.operating_system === 'mac'){
doc, ip_record = gen_compose.injectMacConfig(doc)
Expand All @@ -63,30 +65,24 @@ if (config.operating_system === 'mac'){
for (let i=1; i<=config.num_subnet; i++){
subnetconf.push(gen_env.genSubnetConfigMac(i, keys, ip_record))
}
//checkpoint smartcontract deployment config
deployment_json = gen_other.genDeploymentJsonMac(keys, ip_record)

} else if(config.operating_system === 'linux'){
commonconf = gen_env.genServicesConfig()
subnetconf=[]
for (let i=1; i<=config.num_subnet; i++){
subnetconf.push(gen_env.genSubnetConfig(i, keys))
}
//checkpoint smartcontract deployment config
deployment_json = gen_other.genDeploymentJson(keys)

} else {
console.log(`ERROR: unknown OS ${config.operating_system} not supported`)
process.exit(1)
}

compose_content = yaml.dump(doc,{})
compose_conf = gen_compose.genComposeEnv()
let compose_content = yaml.dump(doc,{})
let compose_conf = gen_compose.genComposeEnv()

//deployment commands list
commands = gen_other.genCommands()
genesis_input = gen_other.genGenesisInputFile(config.network_name, config.network_id, config.num_subnet, keys)
genesis_input_file = yaml.dump(genesis_input, {})
let commands = gen_other.genCommands()
let genesis_input = gen_other.genGenesisInputFile(config.network_name, config.network_id, config.num_subnet, keys)
let genesis_input_file = yaml.dump(genesis_input, {})

writeGenerated(config.generator.output_path)

Expand Down Expand Up @@ -119,7 +115,7 @@ function writeGenerated(output_dir){
}
});

keys_json = JSON.stringify(keys, null, 2);
let keys_json = JSON.stringify(keys, null, 2);
fs.writeFile(`${output_dir}/keys.json`, keys_json, (err) => {
if (err) {
console.error('Error writing key file:', err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function genServices(machine_id) {
'image': `xinfinorg/xdc-relayer:${config.version.relayer}`,
'restart': 'always',
'env_file': config_path,
'ports': ['4000:4000'],
'profiles': [machine]
}
stats = {
Expand All @@ -93,7 +94,7 @@ function genServices(machine_id) {
},

bootnode=genBootNode(machine_id),
observer=genObserver(machine_id),
// observer=genObserver(machine_id),


services = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ CHECKPOINT_CONTRACT=0x0000000000000000000000000000000000000000
SLACK_WEBHOOK=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
CORS_ALLOW_ORIGIN=*
# Parent Chain Observe Node
PARENTNET_NODE_NAME=mainnet_observer
PRIVATE_KEYS=1111111111111111111111111111111111111111111111111111111111111111
# Frontend
VITE_SUBNET_URL=http://127.0.0.1:3000
Expand Down
Loading

0 comments on commit ac9ad1c

Please sign in to comment.