Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator v1.1.0 #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and update image
on:
push:
branches:
- main
- master
- generator*
paths:
- deployment-generator/**
Expand All @@ -18,7 +18,7 @@ jobs:
environment: DockerHub
defaults:
run:
working-directory: subnet/deployment-generator
working-directory: deployment-generator
steps:
- name: Check out code
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion deployment-generator/scripts/docker-down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ if [[ -z $1 ]]; then
exit
fi

docker compose --env-file ../docker-compose.env --profile $1 down
docker compose --profile $1 down

4 changes: 2 additions & 2 deletions deployment-generator/scripts/docker-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ if [[ -z $1 ]]; then
exit
fi

docker compose --env-file ../docker-compose.env --profile $1 pull
docker compose --env-file ../docker-compose.env --profile $1 up -d
docker compose --env-file --profile $1 pull
docker compose --env-file --profile $1 up -d

4 changes: 2 additions & 2 deletions deployment-generator/scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
VERSION_GENERATOR="v1.0.1"
VERSION_GENERATOR="v1.1.0"
VERSION_GENESIS="v0.3.1"

current_dir="$(cd "$(dirname "$0")" && pwd)"
Expand All @@ -11,7 +11,7 @@ docker pull xinfinorg/xdcsubnets:$VERSION_GENESIS

echo ''
echo 'go to http://localhost:5210 to access Subnet Configuration Generator UI'
echo 'or use ssh tunnel if this is running on your server'
echo 'or use ssh tunnel if this is running on your server (VSCode Remote Explorer will do this automatically)'
echo 'ssh -N -L localhost:5210:localhost:5210 <username>@<ip_address> -i <private_key_file>'
mkdir -p generated/scripts
docker run -p 5210:5210 -v $current_dir/generated:/app/generated xinfinorg/subnet-generator:$VERSION_GENERATOR
Expand Down
3 changes: 0 additions & 3 deletions deployment-generator/scripts/test.sh

This file was deleted.

13 changes: 2 additions & 11 deletions deployment-generator/src/config_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const config = {
relayer_mode: process.env.RELAYER_MODE || "full",
docker_image_name:
process.env.IMAGE_NAME || "xinfinorg/subnet-generator:latest",
operating_system: process.env.OS || "linux",
version: {
subnet: process.env.VERSION_SUBNET || "v0.3.1",
bootnode: process.env.VERSION_BOOTNODE || "v0.3.1",
Expand Down Expand Up @@ -73,8 +72,8 @@ function configSanityCheck(config) {
process.exit(1);
}

if (config.num_machines === 0 || config.num_subnet === 0) {
console.log("NUM_MACHINE and NUM_SUBNET cannot be 0");
if (config.num_machines < 1 || config.num_subnet < 1) {
console.log("NUM_MACHINE and NUM_SUBNET must be 1 or more");
process.exit(1);
}

Expand Down Expand Up @@ -197,14 +196,6 @@ function configSanityCheck(config) {
config.keys.subnets_addr = output_wallet;
}

if (config.operating_system === "mac") {
if (config.num_machines !== 1) {
console.log(
"OS=mac requires NUM_MACHINE=1. Due to Docker network limitation, Subnets on MacOS can only communicate within its own machine. This option is intended for single machine testing environment only"
);
process.exit();
}
}

if (config.zero.zero_mode == "one-directional"){
try {
Expand Down
11 changes: 2 additions & 9 deletions deployment-generator/src/gen.env
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@

NETWORK_NAME=4
NETWORK_NAME=gg
NUM_SUBNET=3
OS=mac
PARENTNET=testnet
PARENTNET_WALLET_PK=0x1111111111111111111111111111111111111111111111111111111111111111
PARENTNET_WALLET_PK=0x4da0711c4780696f725dc6ad44751b6a9e15a80a0bcb41eca6bf4510de64172f
RELAYER_MODE=full

MAIN_IP=127.0.0.1
NUM_MACHINE=1



XDC_ZERO=one-directional
PARENTNET_ZERO_WALLET_PK=jk


SUBNET_URL=https://erpc.apothem.network/
32 changes: 6 additions & 26 deletions deployment-generator/src/gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,15 @@ Object.entries(subnet_services).forEach((entry) => {
// checkpoint smartcontract deployment config
let deployment_json = gen_other.genDeploymentJson(keys);

if (config.operating_system === "mac") {
doc, (ip_record = gen_compose.injectMacConfig(doc));
commonconf = gen_env.genServicesConfigMac(ip_record);
subnetconf = [];
for (let i = 1; i <= config.num_subnet; i++) {
subnetconf.push(gen_env.genSubnetConfigMac(i, keys, ip_record));
}
deployconf = gen_env.genContractDeployEnvMac();
} 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));
}
deployconf = gen_env.genContractDeployEnv();
} else {
console.log(`ERROR: unknown OS ${config.operating_system} not supported`);
process.exit(1);
doc, ip_record = gen_compose.injectNetworkConfig(doc);
commonconf = gen_env.genServicesConfig(ip_record);
subnetconf = [];
for (let i = 1; i <= config.num_subnet; i++) {
subnetconf.push(gen_env.genSubnetConfig(i, keys, ip_record));
}
deployconf = gen_env.genContractDeployEnv(ip_record);

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

// deployment commands list
const commands = gen_other.genCommands();
Expand Down Expand Up @@ -154,13 +141,6 @@ function writeGenerated(output_dir) {
);
}

fs.writeFileSync(`${output_dir}/docker-compose.env`, compose_conf, (err) => {
if (err) {
console.error(err);
exit();
}
});

deployment_json = JSON.stringify(deployment_json, null, 2);
fs.writeFileSync(
`${output_dir}/deployment.config.json`,
Expand Down
57 changes: 23 additions & 34 deletions deployment-generator/src/gen_compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ Object.freeze(config);
module.exports = {
genSubnetNodes,
genBootNode,
genObserver,
genServices,
genComposeEnv,
injectMacConfig,
injectNetworkConfig,
};

function genSubnetNodes(machine_id, num, start_num = 1) {
let subnet_nodes = {};
for (let i = start_num; i < start_num + num; i++) {
const node_name = "subnet" + i.toString();
const volume = "./xdcchain" + i.toString() + ":/work/xdcchain";
const config_path = "${SUBNET_CONFIG_PATH}/subnet" + i.toString() + ".env";
const config_path = "${PWD}/subnet" + i.toString() + ".env";
const compose_profile = "machine" + machine_id.toString();
const port = 20302 + i;
const rpcport = 8544 + i;
Expand All @@ -25,24 +23,27 @@ function genSubnetNodes(machine_id, num, start_num = 1) {
image: `xinfinorg/xdcsubnets:${config.version.subnet}`,
volumes: [
volume,
"${SUBNET_CONFIG_PATH}/genesis.json:/work/genesis.json",
"${PWD}/genesis.json:/work/genesis.json",
],
restart: "always",
network_mode: "host",
env_file: [config_path],
profiles: [compose_profile],
ports: [
`${port}:${port}`,
`${rpcport}:${rpcport}`,
`${wsport}:${wsport}`,
`${port}:${port}/tcp`,
`${port}:${port}/udp`,
`${rpcport}:${rpcport}/tcp`,
`${rpcport}:${rpcport}/udp`,
`${wsport}:${wsport}/tcp`,
`${wsport}:${wsport}/udp`,
],
};
}
return subnet_nodes;
}

function genBootNode(machine_id) {
let config_path = "${SUBNET_CONFIG_PATH}/common.env";
let config_path = "${PWD}/common.env";
const machine = "machine" + machine_id.toString();
const bootnode = {
image: `xinfinorg/xdcsubnets:${config.version.bootnode}`,
Expand All @@ -57,21 +58,8 @@ function genBootNode(machine_id) {
return bootnode;
}

function genObserver(machine_id) {
const config_path = "${SUBNET_CONFIG_PATH}/common.env";
const machine = "machine" + machine_id.toString();
const observer = {
image: `xinfinorg/devnet:${config.version.observer}`,
restart: "always",
env_file: config_path,
ports: ["20302:30303", "7545:8545", "7555:8555"],
profiles: [machine],
};
return observer;
}

function genServices(machine_id) {
const config_path = "${SUBNET_CONFIG_PATH}/common.env";
const config_path = "${PWD}/common.env";
const machine = "services";
const frontend = {
image: `xinfinorg/subnet-frontend:${config.version.frontend}`,
Expand Down Expand Up @@ -110,13 +98,7 @@ function genServices(machine_id) {
return services;
}

function genComposeEnv() {
// conf_path = `SUBNET_CONFIG_PATH=${config.deployment_path}/generated/`;
conf_path = `SUBNET_CONFIG_PATH=$PWD`
return conf_path;
}

function injectMacConfig(compose_object) {
function injectNetworkConfig(compose_object) {
// networks:
// docker_net:
// driver: bridge
Expand All @@ -139,14 +121,21 @@ function injectMacConfig(compose_object) {
let record_services_ip = {};

const ip_string_base = "192.168.25.";
let start_ip = 11;
let start_ip_subnet = 11;
let start_ip_service = 51;
Object.entries(compose_object["services"]).forEach((entry) => {
const [key, value] = entry;
const component_ip = ip_string_base + parseInt(start_ip);
start_ip += 1;
let component_ip;
if (key.startsWith("subnet")){
component_ip = ip_string_base + parseInt(start_ip_subnet);
start_ip_subnet += 1;
} else {
component_ip = ip_string_base + parseInt(start_ip_service);
start_ip_service += 1;
}
if (!net.isIP(component_ip)) {
console.log(
`ERROR: found invalid IP assignment ${component_ip} in mac mode`
`ERROR: found invalid IP assignment ${component_ip}`
);
process.exit(1);
}
Expand Down
Loading