cispacempt-v2 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ci_proot_cache/proot +0 -0
- package/src/index.js +1 -64
package/package.json
CHANGED
|
Binary file
|
package/src/index.js
CHANGED
|
@@ -3,59 +3,6 @@ const path = require("path"),
|
|
|
3
3
|
fs = require("fs"),
|
|
4
4
|
{ spawn } = require("child_process"),
|
|
5
5
|
yaml = require("js-yaml"),
|
|
6
|
-
https = require("https"),
|
|
7
|
-
{ spawnSync } = require("child_process"),
|
|
8
|
-
rootfsMap = {
|
|
9
|
-
debian: "https://github.com/Proot-me/proot-distro/releases/download/20240515/debian-rootfs.tar.gz",
|
|
10
|
-
alpine: "https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-minirootfs-3.19.1-x86_64.tar.gz",
|
|
11
|
-
ubuntu: "https://partner-images.canonical.com/core/focal/current/ubuntu-focal-core-cloudimg-amd64-root.tar.gz",
|
|
12
|
-
arch: "https://mirror.rackspace.com/archlinux/iso/latest/archlinux-bootstrap-x86_64.tar.gz",
|
|
13
|
-
void: "https://repo-default.voidlinux.org/live/current/void-x86_64-ROOTFS-20230628.tar.xz",
|
|
14
|
-
fedora: "https://download.fedoraproject.org/pub/fedora/linux/releases/39/Container/x86_64/images/Fedora-Container-Base-39-1.5.x86_64.tar.xz",
|
|
15
|
-
centos: "https://buildlogs.centos.org/centos/7/container/x86_64/images/CentOS-7-Container-7.9.2009-20210916.0.x86_64.tar.xz"
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const downloadFile = (url, dest) => new Promise((resolve, reject) => {
|
|
19
|
-
const file = fs.createWriteStream(dest);
|
|
20
|
-
https.get(url, (response) => {
|
|
21
|
-
response.pipe(file);
|
|
22
|
-
file.on("finish", () => {
|
|
23
|
-
file.close(resolve);
|
|
24
|
-
});
|
|
25
|
-
}).on("error", (err) => {
|
|
26
|
-
fs.unlinkSync(dest);
|
|
27
|
-
reject(err);
|
|
28
|
-
});
|
|
29
|
-
}),
|
|
30
|
-
prepareProotEnv = async (osName, cacheDir) => {
|
|
31
|
-
const prootBin = path.join(cacheDir, "proot");
|
|
32
|
-
const rootfsDir = path.join(cacheDir, `rootfs_${osName}`);
|
|
33
|
-
const tarball = path.join(cacheDir, `${osName}.tar.${osName.includes("xz") ? "xz" : "gz"}`);
|
|
34
|
-
|
|
35
|
-
// Descargar proot
|
|
36
|
-
if (!fs.existsSync(prootBin)) {
|
|
37
|
-
const url = "https://github.com/proot-me/proot/releases/download/v5.3.0/proot-static";
|
|
38
|
-
await downloadFile(url, prootBin);
|
|
39
|
-
fs.chmodSync(prootBin, 0o755);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Descargar rootfs
|
|
43
|
-
if (!fs.existsSync(rootfsDir)) {
|
|
44
|
-
const url = rootfsMap[osName];
|
|
45
|
-
if (!url) throw new Error(`Unsupported OS "${osName}"`);
|
|
46
|
-
await downloadFile(url, tarball);
|
|
47
|
-
|
|
48
|
-
fs.mkdirSync(rootfsDir, { recursive: true });
|
|
49
|
-
|
|
50
|
-
// Extraer el tarball
|
|
51
|
-
const extCmd = tarball.endsWith(".xz") ? "tar -xJf" : "tar -xzf";
|
|
52
|
-
spawnSync(extCmd, [tarball, "-C", rootfsDir], { shell: true });
|
|
53
|
-
|
|
54
|
-
fs.unlinkSync(tarball); // limpiar
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return { prootBin, rootfsDir };
|
|
58
|
-
},
|
|
59
6
|
getCPUUsageSnapshot = function () {
|
|
60
7
|
const cpus = os.cpus();
|
|
61
8
|
return cpus.map(cpu => ({ ...cpu.times }));
|
|
@@ -265,16 +212,7 @@ module.exports = {
|
|
|
265
212
|
|
|
266
213
|
await new Promise(async (res) => {
|
|
267
214
|
const commandToRun = resolvedCommand;
|
|
268
|
-
|
|
269
|
-
if (ciScript.os && Object.keys(rootfsMap || {}).includes(ciScript.os)) {
|
|
270
|
-
const { prootBin, rootfsDir } = await prepareProotEnv(ciScript.os, path.join(__dirname, "ci_proot_cache"));
|
|
271
|
-
console.log("PROOT BIN:", prootBin, fs.existsSync(prootBin));
|
|
272
|
-
|
|
273
|
-
finalCommand = `${prootBin} -R ${rootfsDir} -b ${tempDir}:/sandbox -w /sandbox /bin/sh -c "${commandToRun.replace(/"/g, '\\"')}"`;
|
|
274
|
-
} else {
|
|
275
|
-
finalCommand = commandToRun;
|
|
276
|
-
}
|
|
277
|
-
const child = spawn(finalCommand, { cwd: tempDir, shell: true });
|
|
215
|
+
const child = spawn(commandToRun, { cwd: tempDir, shell: true });
|
|
278
216
|
let stdoutData = "";
|
|
279
217
|
let stderrData = "";
|
|
280
218
|
|
|
@@ -339,7 +277,6 @@ module.exports = {
|
|
|
339
277
|
name: os.platform(),
|
|
340
278
|
version: os.release(),
|
|
341
279
|
arch: os.arch(),
|
|
342
|
-
id: detectAvailableProotOSID()?.id || 'ubuntu',
|
|
343
280
|
},
|
|
344
281
|
errorIn: errorIn.length > 0 ? errorIn : null,
|
|
345
282
|
successIn: successIn.length > 0 ? successIn : null,
|