@milaboratories/pl-deployments 1.2.0 → 1.2.1
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/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -30
- package/dist/index.mjs.map +1 -1
- package/dist/ssh/ssh.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ssh/ssh.ts +15 -0
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import A from "node:os";
|
|
|
15
15
|
import at, { Client as F } from "ssh2";
|
|
16
16
|
import H from "node:net";
|
|
17
17
|
import ct from "node:dns";
|
|
18
|
-
import { randomBytes as
|
|
18
|
+
import { randomBytes as x } from "node:crypto";
|
|
19
19
|
import { generateSshPlConfigs as lt, getFreePort as v } from "@milaboratories/pl-config";
|
|
20
20
|
import { z as p } from "zod";
|
|
21
21
|
function ht(s, r) {
|
|
@@ -23,7 +23,7 @@ function ht(s, r) {
|
|
|
23
23
|
cmd: ${JSON.stringify([r.cmd, ...r.args])}
|
|
24
24
|
wd: ${r.opts.cwd}`), s.info(" spawning child process"), Q(r.cmd, r.args, r.opts);
|
|
25
25
|
}
|
|
26
|
-
async function
|
|
26
|
+
async function O(s) {
|
|
27
27
|
try {
|
|
28
28
|
return process.kill(s, 0), !0;
|
|
29
29
|
} catch {
|
|
@@ -35,12 +35,12 @@ function J(s) {
|
|
|
35
35
|
}
|
|
36
36
|
async function M(s, r) {
|
|
37
37
|
let e = 0;
|
|
38
|
-
for (; await
|
|
38
|
+
for (; await O(s); )
|
|
39
39
|
if (await b(100), e += 100, e > r)
|
|
40
40
|
throw new Error(`The process did not stopped after ${r} ms.`);
|
|
41
41
|
}
|
|
42
42
|
const dt = ["linux", "macos", "windows"];
|
|
43
|
-
function
|
|
43
|
+
function k(s) {
|
|
44
44
|
switch (s.toLowerCase()) {
|
|
45
45
|
case "darwin":
|
|
46
46
|
return "macos";
|
|
@@ -72,7 +72,7 @@ function S(s) {
|
|
|
72
72
|
}
|
|
73
73
|
const wt = "https://cdn.platforma.bio/software", ft = "https://cdn-ga.pl-open.science/software";
|
|
74
74
|
async function pt(s, r, t, e, i, o) {
|
|
75
|
-
const n = G(t, e, r, S(i),
|
|
75
|
+
const n = G(t, e, r, S(i), k(o)), { archiveUrl: c, alternativeArchiveGAUrl: a, archivePath: l } = n;
|
|
76
76
|
try {
|
|
77
77
|
await C(s, c, l), n.wasDownloadedFrom = c;
|
|
78
78
|
} catch {
|
|
@@ -81,7 +81,7 @@ async function pt(s, r, t, e, i, o) {
|
|
|
81
81
|
return n;
|
|
82
82
|
}
|
|
83
83
|
async function mt(s, r, t, e, i, o) {
|
|
84
|
-
const n = G(t, e, r, S(i),
|
|
84
|
+
const n = G(t, e, r, S(i), k(o)), { archiveUrl: c, alternativeArchiveGAUrl: a, archivePath: l, archiveType: h, targetFolder: u, baseName: $ } = n;
|
|
85
85
|
try {
|
|
86
86
|
await C(s, c, l), n.wasDownloadedFrom = c;
|
|
87
87
|
} catch {
|
|
@@ -166,7 +166,7 @@ async function Pt(s, r, t) {
|
|
|
166
166
|
switch (t.type) {
|
|
167
167
|
case "Download":
|
|
168
168
|
const e = await mt(s, r, "pl", `pl-${t.version}`, A.arch(), A.platform());
|
|
169
|
-
return d.join(e.baseName, "binaries", St[
|
|
169
|
+
return d.join(e.baseName, "binaries", St[k(A.platform())]);
|
|
170
170
|
case "Local":
|
|
171
171
|
return t.path;
|
|
172
172
|
default:
|
|
@@ -196,7 +196,7 @@ function At() {
|
|
|
196
196
|
function Ft(s, r, t) {
|
|
197
197
|
return s[r] = t, t;
|
|
198
198
|
}
|
|
199
|
-
async function
|
|
199
|
+
async function N(s, r) {
|
|
200
200
|
const t = At();
|
|
201
201
|
try {
|
|
202
202
|
return await r((i, o) => Ft(t, i, o), t);
|
|
@@ -215,7 +215,7 @@ class Dt {
|
|
|
215
215
|
this.logger = r, this.workingDir = t, this.startOptions = e, this.initialStartHistory = i, this.onClose = o, this.onError = n, this.onCloseAndError = c, this.onCloseAndErrorNoStop = a;
|
|
216
216
|
}
|
|
217
217
|
async start() {
|
|
218
|
-
await
|
|
218
|
+
await N(this.logger, async (r, t) => {
|
|
219
219
|
this.wasStopped = !1;
|
|
220
220
|
const e = ht(this.logger, this.startOptions);
|
|
221
221
|
e.on("error", (o) => {
|
|
@@ -239,7 +239,7 @@ class Dt {
|
|
|
239
239
|
return this.wasStopped;
|
|
240
240
|
}
|
|
241
241
|
async isAlive() {
|
|
242
|
-
return await
|
|
242
|
+
return await O(f(this.pid));
|
|
243
243
|
}
|
|
244
244
|
debugInfo() {
|
|
245
245
|
return {
|
|
@@ -259,10 +259,10 @@ async function fr(s, r) {
|
|
|
259
259
|
closeOld: !0,
|
|
260
260
|
...r
|
|
261
261
|
};
|
|
262
|
-
return await
|
|
262
|
+
return await N(s, async (e, i) => {
|
|
263
263
|
e("startOptions", { ...t, config: "too wordy" });
|
|
264
264
|
const o = d.resolve(t.workingDir);
|
|
265
|
-
t.closeOld && e("closeOld", await
|
|
265
|
+
t.closeOld && e("closeOld", await xt(s, o));
|
|
266
266
|
const n = d.join(o, bt);
|
|
267
267
|
s.info(`writing configuration '${n}'...`), await m.writeFile(n, t.config);
|
|
268
268
|
const c = d.join(o, "binaries"), a = await Pt(s, c, t.plBinary), h = {
|
|
@@ -295,17 +295,17 @@ async function fr(s, r) {
|
|
|
295
295
|
return await u.start(), u;
|
|
296
296
|
});
|
|
297
297
|
}
|
|
298
|
-
async function
|
|
299
|
-
return await
|
|
300
|
-
const i = t("pidFilePath", L(r)), o = t("pid", await Ct(i)), n = t("wasAlive", await
|
|
298
|
+
async function xt(s, r) {
|
|
299
|
+
return await N(s, async (t, e) => {
|
|
300
|
+
const i = t("pidFilePath", L(r)), o = t("pid", await Ct(i)), n = t("wasAlive", await O(o));
|
|
301
301
|
return o !== void 0 && n && (t("stopped", J(o)), t("waitStopped", await M(o, 1e4))), e;
|
|
302
302
|
});
|
|
303
303
|
}
|
|
304
|
-
const
|
|
304
|
+
const Ot = {
|
|
305
305
|
keepaliveInterval: 6e4,
|
|
306
306
|
keepaliveCountMax: 10
|
|
307
307
|
};
|
|
308
|
-
class
|
|
308
|
+
class B {
|
|
309
309
|
constructor(r, t) {
|
|
310
310
|
w(this, "config");
|
|
311
311
|
w(this, "homeDir");
|
|
@@ -319,9 +319,9 @@ class N {
|
|
|
319
319
|
*/
|
|
320
320
|
static async init(r, t) {
|
|
321
321
|
const e = {
|
|
322
|
-
...
|
|
322
|
+
...Ot,
|
|
323
323
|
...t
|
|
324
|
-
}, i = new
|
|
324
|
+
}, i = new B(r, new F());
|
|
325
325
|
return await i.connect(e), i;
|
|
326
326
|
}
|
|
327
327
|
getForwardedServers() {
|
|
@@ -341,7 +341,7 @@ class N {
|
|
|
341
341
|
* @returns A promise that resolves when the connection is established or rejects on error.
|
|
342
342
|
*/
|
|
343
343
|
async connect(r) {
|
|
344
|
-
return this.config = r, await
|
|
344
|
+
return this.config = r, await kt(this.client, r);
|
|
345
345
|
}
|
|
346
346
|
/**
|
|
347
347
|
* Executes a command on the SSH server.
|
|
@@ -408,7 +408,7 @@ class N {
|
|
|
408
408
|
* @returns { server: net.Server } A promise resolving with the created server instance.
|
|
409
409
|
*/
|
|
410
410
|
async forwardPort(r, t) {
|
|
411
|
-
const e = `ssh.forward:${r.localPort}:${r.remotePort}.id_${
|
|
411
|
+
const e = `ssh.forward:${r.localPort}:${r.remotePort}.id_${x(1).toString("hex")}`;
|
|
412
412
|
t = t ?? this.config;
|
|
413
413
|
const i = new X((o) => new Promise((n, c) => {
|
|
414
414
|
const a = new F();
|
|
@@ -422,7 +422,7 @@ class N {
|
|
|
422
422
|
}));
|
|
423
423
|
return await i.ensure(), new Promise((o, n) => {
|
|
424
424
|
const c = H.createServer({ pauseOnConnect: !0 }, async (a) => {
|
|
425
|
-
const l = `${e}.sock_${
|
|
425
|
+
const l = `${e}.sock_${x(1).toString("hex")}`;
|
|
426
426
|
let h;
|
|
427
427
|
try {
|
|
428
428
|
h = await i.ensure();
|
|
@@ -430,6 +430,7 @@ class N {
|
|
|
430
430
|
this.logger.info(`${l}.persistentClient.catch: ${$}`), a.end();
|
|
431
431
|
return;
|
|
432
432
|
}
|
|
433
|
+
h.setNoDelay(!0), a.setNoDelay(!0);
|
|
433
434
|
let u;
|
|
434
435
|
try {
|
|
435
436
|
u = await Rt(this.logger, h, "127.0.0.1", 0, "127.0.0.1", r.remotePort);
|
|
@@ -743,14 +744,14 @@ class N {
|
|
|
743
744
|
this.closeForwardedPorts(), this.client.end();
|
|
744
745
|
}
|
|
745
746
|
}
|
|
746
|
-
async function
|
|
747
|
+
async function kt(s, r, t, e) {
|
|
747
748
|
return new Promise((i, o) => {
|
|
748
749
|
s.on("ready", () => {
|
|
749
750
|
i(s);
|
|
750
751
|
}), s.on("error", (n) => {
|
|
751
752
|
o(new Error(`ssh.connect: error occurred: ${n}`));
|
|
752
753
|
}), s.on("close", () => {
|
|
753
|
-
}), s.connect(r);
|
|
754
|
+
}), s.connect(r), s.setNoDelay(!0);
|
|
754
755
|
});
|
|
755
756
|
}
|
|
756
757
|
async function Rt(s, r, t, e, i, o) {
|
|
@@ -758,7 +759,7 @@ async function Rt(s, r, t, e, i, o) {
|
|
|
758
759
|
r.forwardOut(t, e, i, o, (a, l) => a ? (s.error(`forwardOut.error: ${a}`), c(a)) : n(l));
|
|
759
760
|
});
|
|
760
761
|
}
|
|
761
|
-
const
|
|
762
|
+
const Nt = "minio-2024-12-18T13-15-44Z", Bt = "supervisord-0.7.3", Ut = "supervisord_0.7.3_Linux_64-bit";
|
|
762
763
|
function g(s) {
|
|
763
764
|
return d.join(s, ".platforma_ssh");
|
|
764
765
|
}
|
|
@@ -823,7 +824,7 @@ async function Mt(s, r, t, e) {
|
|
|
823
824
|
return c.allAlive || (c.minio || s.warn("Minio is not running on the server"), c.platforma || s.warn("Platforma is not running on the server")), c;
|
|
824
825
|
}
|
|
825
826
|
function Gt(s, r, t, e, i, o, n) {
|
|
826
|
-
const c = Object.entries(r).map(([h, u]) => `${h}="${u}"`).join(","), a =
|
|
827
|
+
const c = Object.entries(r).map(([h, u]) => `${h}="${u}"`).join(","), a = x(16).toString("hex"), l = t;
|
|
827
828
|
return `
|
|
828
829
|
[supervisord]
|
|
829
830
|
logfile=${e}/supervisord.log
|
|
@@ -913,7 +914,7 @@ class q {
|
|
|
913
914
|
}
|
|
914
915
|
static async init(r, t) {
|
|
915
916
|
try {
|
|
916
|
-
const e = await
|
|
917
|
+
const e = await B.init(r, t);
|
|
917
918
|
return new q(r, e, f(t.username));
|
|
918
919
|
} catch (e) {
|
|
919
920
|
throw r.error(`Connection error in SshClient.init: ${e}`), e;
|
|
@@ -1051,7 +1052,7 @@ class q {
|
|
|
1051
1052
|
e,
|
|
1052
1053
|
i,
|
|
1053
1054
|
"supervisord",
|
|
1054
|
-
|
|
1055
|
+
Bt
|
|
1055
1056
|
);
|
|
1056
1057
|
o.push(c);
|
|
1057
1058
|
const a = _t(e, i.arch), l = await this.downloadAndUntar(
|
|
@@ -1059,7 +1060,7 @@ class q {
|
|
|
1059
1060
|
e,
|
|
1060
1061
|
i,
|
|
1061
1062
|
"minio",
|
|
1062
|
-
|
|
1063
|
+
Nt
|
|
1063
1064
|
);
|
|
1064
1065
|
return o.push(l), await this.sshClient.chmod(a, 488), {
|
|
1065
1066
|
history: o,
|
|
@@ -1193,7 +1194,7 @@ export {
|
|
|
1193
1194
|
bt as LocalConfigYaml,
|
|
1194
1195
|
Dt as LocalPl,
|
|
1195
1196
|
P as PortPair,
|
|
1196
|
-
|
|
1197
|
+
B as SshClient,
|
|
1197
1198
|
q as SshPl,
|
|
1198
1199
|
Lt as SshPlPorts,
|
|
1199
1200
|
R as getDefaultPlVersion,
|