Skip to content

Commit

Permalink
Add extra binaries in the setup command (#1208)
Browse files Browse the repository at this point in the history
Co-authored-by: Javier Viola <[email protected]>
  • Loading branch information
wirednkod and pepoviola authored Sep 21, 2023
1 parent 8ab2a1d commit 285460f
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 22 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ This allows to use the `setup` script, making everything ready for a ZombieNet d
You can use the following arguments:

`--help` shows the different options and commands for using the Zombienet CLI.
`--binaries` or `-b`: enables providing the binaries that you want to be downloaded and installed during the setup. Possible options: `polkadot`, `polkadot-parachain`.

`--binaries` or `-b`: enables providing the binaries that you want to be downloaded and installed during the setup. Possible options: `all`, `polkadot`, `polkadot-parachain`. *Note:* Downloading `polkadot` will automatically download also the binaries of `polkadot-prepare-worker`, `polkadot-execute-worker`. Since Polkadot v1.0 all 3 binaries are needed for the node to run as a validator;
For example:

```bash
Expand Down
2 changes: 1 addition & 1 deletion javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ This allows to use the `setup` script, making everything ready for a ZombieNet d
You can use the following arguments:

`--help` shows the different options and commands for using the Zombienet CLI.
`--binaries` or `-b`: enables providing the binaries that you want to be downloaded and installed during the setup. Possible options: `polkadot`, `polkadot-parachain`.
`--binaries` or `-b`: enables providing the binaries that you want to be downloaded and installed during the setup. Possible options: `all`, `polkadot`, `polkadot-parachain`. *Note:* Downloading `polkadot` will automatically download also the binaries of `polkadot-prepare-worker`, `polkadot-execute-worker`. Since Polkadot v1.0 all 3 binaries are needed for the node to run as a validator;

For example:

Expand Down
6 changes: 3 additions & 3 deletions javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ This allows to use the `setup` script, making everything ready for a ZombieNet d
You can use the following arguments:

`--help` shows the different options and commands for using the Zombienet CLI.
`--binaries` or `-b`: enables providing the binaries that you want to be downloaded and installed during the setup. Possible options: `polkadot`, `polkadot-parachain`.
`--binaries` or `-b`: enables providing the binaries that you want to be downloaded and installed during the setup. Possible options: `all`, `polkadot`, `polkadot-parachain`. *Note:* Downloading `polkadot` will automatically download also the binaries of `polkadot-prepare-worker`, `polkadot-execute-worker`. Since Polkadot v1.0 all 3 binaries are needed for the node to run as a validator;

For example:

Expand Down
90 changes: 77 additions & 13 deletions javascript/packages/cli/src/actions/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ interface OptIf {
[key: string]: { name: string; url?: string; size?: string };
}

const POLKADOT_SDK = "polkadot-sdk";
const POLKADOT = "polkadot";
const POLKADOT_PREPARE_WORKER = "polkadot-prepare-worker";
const POLKADOT_EXECUTE_WORKER = "polkadot-execute-worker";
const POLKADOT_PARACHAIN = "polkadot-parachain";

const POSSIBLE_BINARIES = [POLKADOT, POLKADOT_PARACHAIN];
const POLKADOT_WORKERS = [POLKADOT_PREPARE_WORKER, POLKADOT_EXECUTE_WORKER];

const options: OptIf = {};
/**
* Setup - easily download latest artifacts and make them executable in order to use them with zombienet
Expand All @@ -16,8 +25,7 @@ const options: OptIf = {};
* @returns
*/
export async function setup(params: any, opts?: any) {
const POSSIBLE_BINARIES = ["polkadot", "polkadot-parachain"];

console.log("process.platform", process.platform);
// If the platform is MacOS then the repos needs to be cloned and run locally by the user
// as polkadot and/or polkadot-parachain do not release a valid binaries for MacOS
if (process.platform === "darwin") {
Expand All @@ -44,10 +52,10 @@ export async function setup(params: any, opts?: any) {

console.log(decorators.green("Gathering latest releases' versions...\n"));
await new Promise<void>((resolve) => {
latestPolkadotReleaseURL("polkadot", "polkadot").then(
latestPolkadotReleaseURL(POLKADOT_SDK, POLKADOT).then(
(res: [string, string]) => {
options.polkadot = {
name: "polkadot",
options[POLKADOT] = {
name: POLKADOT,
url: res[0],
size: res[1],
};
Expand All @@ -57,10 +65,10 @@ export async function setup(params: any, opts?: any) {
});

await new Promise<void>((resolve) => {
latestPolkadotReleaseURL("cumulus", "polkadot-parachain").then(
latestPolkadotReleaseURL(POLKADOT_SDK, POLKADOT_PREPARE_WORKER).then(
(res: [string, string]) => {
options["polkadot-parachain"] = {
name: "polkadot-parachain",
options[POLKADOT_PREPARE_WORKER] = {
name: POLKADOT_PREPARE_WORKER,
url: res[0],
size: res[1],
};
Expand All @@ -69,28 +77,78 @@ export async function setup(params: any, opts?: any) {
);
});

await new Promise<void>((resolve) => {
latestPolkadotReleaseURL(POLKADOT_SDK, POLKADOT_EXECUTE_WORKER).then(
(res: [string, string]) => {
options[POLKADOT_EXECUTE_WORKER] = {
name: POLKADOT_EXECUTE_WORKER,
url: res[0],
size: res[1],
};
resolve();
},
);
});

await new Promise<void>((resolve) => {
latestPolkadotReleaseURL(POLKADOT_SDK, POLKADOT_PARACHAIN).then(
(res: [string, string]) => {
options[POLKADOT_PARACHAIN] = {
name: POLKADOT_PARACHAIN,
url: res[0],
size: res[1],
};
resolve();
},
);
});

// If the platform is MacOS then the polkadot repo needs to be cloned and run locally by the user
// as polkadot do not release a binary for MacOS
if (params[0] === "all") {
params = [POLKADOT, POLKADOT_PARACHAIN];
}

if (params.length === 0) {
console.log(decorators.green("No binaries to download. Exiting..."));
return;
}
let count = 0;

console.log("Setup will start to download binaries:");

params.forEach((a: any) => {
if (!POSSIBLE_BINARIES.includes(a)) {
params = params.filter((param: any) => param !== a);
console.log(
decorators.red(
`"${a}" is not one of the possible options for this setup and will be skipped;`,
),
decorators.green(` Valid options: polkadot polkadot-parachain`),
decorators.green(
` Valid options: 'polkadot', 'polkadot-parachain', 'all'`,
),
);
return;
}
const size = parseInt(options[a]?.size || "0", 10);
count += size;
console.log("-", a, "\t Approx. size ", size, " MB");
let size = 0;
if (a === POLKADOT) {
size = parseInt(options[a]?.size || "0", 10);
count += size;
console.log("-", a, "\t\t\t Approx. size ", size, " MB");

POLKADOT_WORKERS.forEach((b) => {
params.push(b);
size = parseInt(options[b]?.size || "0", 10);
count += size;
console.log("-", b, "\t Approx. size ", size, " MB");
});
} else {
size = parseInt(options[a]?.size || "0", 10);
count += size;
console.log("-", a, "\t\t Approx. size ", size, " MB");
}
});
console.log("Total approx. size: ", count, "MB");
console.log("Total approx. size:\t\t\t ", count, "MB");
if (!opts?.yes) {
const response = await askQuestion(
decorators.yellow("\nDo you want to continue? (y/n)"),
Expand Down Expand Up @@ -212,6 +270,12 @@ const latestPolkadotReleaseURL = async (
return Boolean(obj);
});

if (!release) {
throw Error(
`In repo '${repo}', there is no release for: '${name}'! Exiting...`,
);
}

const { tag_name } = release;

if (!tag_name) {
Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ program
"<binaries...>",
`the binaries that you want to be downloaded, provided in a row without any separators;\nThey are downloaded in current directory and appropriate executable permissions are assigned.\nPossible options: 'polkadot', 'polkadot-parachain'\n${decorators.blue(
"zombienet setup polkadot polkadot-parachain",
)}`,
)}\nNote: Downloading 'polkadot' downloads also 'polkadot-prepare-worker' and 'polkadot-execute-worker'`,
)
.addOption(new Option("-y, --yes", "Bypass confirmation"))
.action(asyncAction(setup));
Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/orchestrator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ This allows to use the `setup` script, making everything ready for a ZombieNet d
You can use the following arguments:

`--help` shows the different options and commands for using the Zombienet CLI.
`--binaries` or `-b`: enables providing the binaries that you want to be downloaded and installed during the setup. Possible options: `polkadot`, `polkadot-parachain`.
`--binaries` or `-b`: enables providing the binaries that you want to be downloaded and installed during the setup. Possible options: `all`, `polkadot`, `polkadot-parachain`. *Note:* Downloading `polkadot` will automatically download also the binaries of `polkadot-prepare-worker`, `polkadot-execute-worker`. Since Polkadot v1.0 all 3 binaries are needed for the node to run as a validator;

For example:

Expand Down

0 comments on commit 285460f

Please sign in to comment.