Repository navigation
Expand file tree
/
Copy pathget-binary.ts
More file actions
84 lines (77 loc) · 2.8 KB
/
Copy pathget-binary.ts
File metadata and controls
84 lines (77 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Script to launch 2 relay and 2 parachain nodes.
* It contains pre-registered versions to allow easy run using Docker.
*
* ports can be given using --port-prefix xx (default 34) using the following rule:
* - relay 1 - p2p (p2p: XX000, rpcPort: XX001)
* - relay 2 - p2p (p2p: XX010, rpcPort: XX011)
* - para 1 - p2p (p2p: XX100, rpcPort: XX101)
* - para 2 - p2p (p2p: XX110, rpcPort: XX111)
*
*/
import yargs from "yargs";
import * as fs from "node:fs";
import * as path from "path";
import * as child_process from "node:child_process";
import { killAll, run } from "polkadot-launch";
export async function getDockerBuildBinary(
dockerImage: string,
binaryPath: string
): Promise<string> {
if (process.platform != "linux") {
console.error(
`docker binaries are only supported on linux. Use "local" config for compiled binaries`
);
process.exit(1);
}
child_process.execSync(`docker create --name moonbeam-tmp ${dockerImage} && \
docker cp moonbeam-tmp:/moonbeam/moonbeam ${binaryPath} && \
docker rm moonbeam-tmp`);
return binaryPath;
}
export async function getGithubReleaseBinary(url: string, binaryPath: string): Promise<string> {
child_process.execSync(`wget -q ${url}` + ` -O ${binaryPath}`);
return binaryPath;
}
// Downloads the binary and return the filepath
export async function getMoonbeamBinary(binaryTag: string, binaryPath: string): Promise<string> {
if (binaryTag.startsWith(`v`)) {
return getGithubReleaseBinary(
`https://github.com/moonbeam-foundation/moonbeam/releases/download/${binaryTag}/moonbeam`,
binaryPath
);
} else if (binaryTag.startsWith(`sha`)) {
return getDockerBuildBinary(`moonbeamfoundation/moonbeam:${binaryTag}`, binaryPath);
} else if (/^[0-9]/g.test(binaryTag)) {
// sha given without prefix
return getDockerBuildBinary(`moonbeamfoundation/moonbeam:sha-${binaryTag}`, binaryPath);
} else {
const sha = child_process.execSync(`git rev-list -n 1 ${binaryTag}`).toString();
return getDockerBuildBinary(`moonbeamfoundation/moonbeam:sha-${sha.slice(0, 8)}`, binaryPath);
}
}
async function start() {
const argv = yargs(process.argv.slice(2))
.usage("Usage: npm run launch [args]")
.version("1.0.0")
.options({
tag: {
type: "string",
describe: "<sha-xxxx> or <v0.xx.x>",
demandOption: true,
},
"output-dir": {
type: "string",
alias: "o",
describe: "folder to copy the binary to",
default: ".",
},
})
.help().argv;
const binaryPath = path.join(argv["output-dir"], `/moonbeam-${argv.tag}`);
console.log(`Downloading ${argv.tag}...`);
await getMoonbeamBinary(argv.tag, binaryPath);
child_process.execSync(`chmod uog+x ${binaryPath}`);
console.log(`Copied binary ${argv.tag} to ${binaryPath}`);
}
start();