@milaboratories/pl-deployments 1.1.6 → 1.1.7
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/common/pl_binary.d.ts +2 -0
- package/dist/common/pl_binary.d.ts.map +1 -1
- package/dist/common/pl_binary_download.d.ts +2 -4
- package/dist/common/pl_binary_download.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +141 -138
- package/dist/index.mjs.map +1 -1
- package/dist/local/pl.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/common/pl_binary.ts +11 -2
- package/src/common/pl_binary_download.ts +26 -55
- package/src/local/pl.ts +3 -1
- package/src/ssh/__tests__/pl-docker.test.ts +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Z = (s, t, r) => t in s ?
|
|
1
|
+
var q = Object.defineProperty;
|
|
2
|
+
var Z = (s, t, r) => t in s ? q(s, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[t] = r;
|
|
3
3
|
var w = (s, t, r) => Z(s, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { spawn as V } from "node:child_process";
|
|
5
|
-
import { sleep as
|
|
6
|
-
import
|
|
5
|
+
import { sleep as F, fileExists as m, assertNever as _, notEmpty as p, RetryablePromise as Y } from "@milaboratories/ts-helpers";
|
|
6
|
+
import A from "node:fs";
|
|
7
7
|
import f, { readFile as Q } from "node:fs/promises";
|
|
8
8
|
import d from "upath";
|
|
9
9
|
import { request as X } from "undici";
|
|
@@ -11,35 +11,35 @@ import { Readable as rr, Writable as tr } from "node:stream";
|
|
|
11
11
|
import { text as er } from "node:stream/consumers";
|
|
12
12
|
import * as ir from "tar";
|
|
13
13
|
import or from "decompress";
|
|
14
|
-
import
|
|
15
|
-
import sr, { Client as
|
|
16
|
-
import
|
|
14
|
+
import C from "node:os";
|
|
15
|
+
import sr, { Client as E } from "ssh2";
|
|
16
|
+
import I from "node:net";
|
|
17
17
|
import nr from "node:dns";
|
|
18
|
-
import { randomBytes as
|
|
18
|
+
import { randomBytes as D } from "node:crypto";
|
|
19
19
|
import { generateSshPlConfigs as ar, getFreePort as y } from "@milaboratories/pl-config";
|
|
20
20
|
function cr(s, t) {
|
|
21
21
|
return s.info(`Running:
|
|
22
22
|
cmd: ${JSON.stringify([t.cmd, ...t.args])}
|
|
23
23
|
wd: ${t.opts.cwd}`), s.info(" spawning child process"), V(t.cmd, t.args, t.opts);
|
|
24
24
|
}
|
|
25
|
-
async function
|
|
25
|
+
async function b(s) {
|
|
26
26
|
try {
|
|
27
27
|
return process.kill(s, 0), !0;
|
|
28
28
|
} catch {
|
|
29
29
|
return !1;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function j(s) {
|
|
33
33
|
return process.kill(s, "SIGINT");
|
|
34
34
|
}
|
|
35
|
-
async function
|
|
35
|
+
async function H(s, t) {
|
|
36
36
|
let e = 0;
|
|
37
|
-
for (; await
|
|
38
|
-
if (await
|
|
37
|
+
for (; await b(s); )
|
|
38
|
+
if (await F(100), e += 100, e > t)
|
|
39
39
|
throw new Error(`The process did not stopped after ${t} ms.`);
|
|
40
40
|
}
|
|
41
41
|
const lr = ["linux", "macos", "windows"];
|
|
42
|
-
function
|
|
42
|
+
function x(s) {
|
|
43
43
|
switch (s.toLowerCase()) {
|
|
44
44
|
case "darwin":
|
|
45
45
|
return "macos";
|
|
@@ -69,36 +69,37 @@ function P(s) {
|
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
const dr = "https://cdn.platforma.bio/software", ur = "https://cdn-ga.pl-open.science/software";
|
|
73
|
+
async function wr(s, t, r, e, i, o) {
|
|
74
|
+
const n = M(r, e, t, P(i), x(o)), { archiveUrl: c, alternativeArchiveGAUrl: a, archivePath: l } = n;
|
|
75
|
+
try {
|
|
76
|
+
await v(s, c, l), n.wasDownloadedFrom = c;
|
|
77
|
+
} catch {
|
|
78
|
+
await v(s, a, l), n.wasDownloadedFrom = a;
|
|
79
|
+
}
|
|
80
|
+
return n;
|
|
75
81
|
}
|
|
76
|
-
async function
|
|
77
|
-
const
|
|
78
|
-
|
|
82
|
+
async function fr(s, t, r, e, i, o) {
|
|
83
|
+
const n = M(r, e, t, P(i), x(o)), { archiveUrl: c, alternativeArchiveGAUrl: a, archivePath: l, archiveType: h, targetFolder: u, baseName: g } = n;
|
|
84
|
+
try {
|
|
85
|
+
await v(s, c, l), n.wasDownloadedFrom = c;
|
|
86
|
+
} catch {
|
|
87
|
+
await v(s, a, l), n.wasDownloadedFrom = a;
|
|
88
|
+
}
|
|
89
|
+
return await mr(s, l, h, u), n;
|
|
79
90
|
}
|
|
80
|
-
function
|
|
81
|
-
const o = `${t}-${e}`, n =
|
|
91
|
+
function M(s, t, r, e, i) {
|
|
92
|
+
const o = `${t}-${e}`, n = gr[i], c = `${o}.${n}`, a = `${dr}/${s}/${i}/${c}`, l = `${ur}/${s}/${i}/${c}`, h = d.join(r, c), u = d.join(r, o);
|
|
82
93
|
return {
|
|
83
94
|
archiveUrl: a,
|
|
84
|
-
|
|
95
|
+
alternativeArchiveGAUrl: l,
|
|
96
|
+
archivePath: h,
|
|
85
97
|
archiveType: n,
|
|
86
|
-
targetFolder:
|
|
98
|
+
targetFolder: u,
|
|
87
99
|
baseName: o
|
|
88
100
|
};
|
|
89
101
|
}
|
|
90
|
-
function
|
|
91
|
-
const i = `pl-${s}-${r}`, o = M[e], n = `${i}.${o}`, c = `https://cdn.platforma.bio/software/pl/${e}/${n}`, a = d.join(t, n), l = d.join(t, i), h = d.join(i, "binaries", gr[e]);
|
|
92
|
-
return {
|
|
93
|
-
archiveUrl: c,
|
|
94
|
-
archivePath: a,
|
|
95
|
-
archiveType: o,
|
|
96
|
-
targetFolder: l,
|
|
97
|
-
binaryPath: h,
|
|
98
|
-
baseName: i
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
async function H(s, t, r) {
|
|
102
|
+
async function v(s, t, r) {
|
|
102
103
|
const e = {};
|
|
103
104
|
e.dstArchive = r;
|
|
104
105
|
try {
|
|
@@ -112,7 +113,7 @@ async function H(s, t, r) {
|
|
|
112
113
|
const n = await er(i);
|
|
113
114
|
throw e.errorMsg = `failed to download archive: ${o}, response: ${n.slice(0, 1e3)}`, s.error(e.errorMsg), new Error(e.errorMsg);
|
|
114
115
|
}
|
|
115
|
-
return e.tmpPath = r + ".tmp", await rr.toWeb(i).pipeTo(tr.toWeb(
|
|
116
|
+
return e.tmpPath = r + ".tmp", await rr.toWeb(i).pipeTo(tr.toWeb(A.createWriteStream(e.tmpPath))), e.wroteTmp = !0, e.tmpExisted = await m(e.tmpPath), await f.rename(e.tmpPath, r), e.renamed = !0, e.newExisted = await m(r), e;
|
|
116
117
|
} catch (i) {
|
|
117
118
|
const o = `downloadArchive: error ${JSON.stringify(i)} occurred, state: ${JSON.stringify(e)}`;
|
|
118
119
|
throw s.error(o), new Error(o);
|
|
@@ -145,63 +146,65 @@ async function mr(s, t, r, e) {
|
|
|
145
146
|
await or(t, e);
|
|
146
147
|
break;
|
|
147
148
|
default:
|
|
148
|
-
|
|
149
|
+
_(r);
|
|
149
150
|
}
|
|
150
151
|
await f.writeFile(i, "ok"), s.info(" ... unpack done.");
|
|
151
152
|
}
|
|
152
|
-
const
|
|
153
|
+
const gr = {
|
|
153
154
|
linux: "tgz",
|
|
154
155
|
macos: "tgz",
|
|
155
156
|
windows: "zip"
|
|
156
|
-
}, gr = {
|
|
157
|
-
linux: "platforma",
|
|
158
|
-
macos: "platforma",
|
|
159
|
-
windows: "platforma.exe"
|
|
160
157
|
};
|
|
161
|
-
function
|
|
158
|
+
function O() {
|
|
162
159
|
return "1.18.3";
|
|
163
160
|
}
|
|
164
161
|
function yr() {
|
|
165
|
-
return { type: "Download", version:
|
|
162
|
+
return { type: "Download", version: O() };
|
|
166
163
|
}
|
|
167
164
|
async function $r(s, t, r) {
|
|
168
165
|
switch (r.type) {
|
|
169
166
|
case "Download":
|
|
170
|
-
|
|
167
|
+
const e = await fr(s, t, "pl", `pl-${r.version}`, C.arch(), C.platform());
|
|
168
|
+
return d.join(e.baseName, "binaries", Pr[x(C.platform())]);
|
|
171
169
|
case "Local":
|
|
172
170
|
return r.path;
|
|
173
171
|
default:
|
|
174
|
-
|
|
172
|
+
_(r);
|
|
175
173
|
}
|
|
176
174
|
}
|
|
175
|
+
const Pr = {
|
|
176
|
+
linux: "platforma",
|
|
177
|
+
macos: "platforma",
|
|
178
|
+
windows: "platforma.exe"
|
|
179
|
+
};
|
|
177
180
|
function J(s) {
|
|
178
181
|
return d.join(s, "pl_pid");
|
|
179
182
|
}
|
|
180
|
-
async function
|
|
183
|
+
async function vr(s) {
|
|
181
184
|
if (!await m(s))
|
|
182
185
|
return;
|
|
183
186
|
const t = await f.readFile(s);
|
|
184
187
|
return Number(t.toString());
|
|
185
188
|
}
|
|
186
|
-
async function
|
|
189
|
+
async function Sr(s, t) {
|
|
187
190
|
await f.writeFile(s, JSON.stringify(t));
|
|
188
191
|
}
|
|
189
|
-
function
|
|
192
|
+
function Cr() {
|
|
190
193
|
return {};
|
|
191
194
|
}
|
|
192
|
-
function
|
|
195
|
+
function Er(s, t, r) {
|
|
193
196
|
return s[t] = r, r;
|
|
194
197
|
}
|
|
195
|
-
async function
|
|
196
|
-
const r =
|
|
198
|
+
async function k(s, t) {
|
|
199
|
+
const r = Cr();
|
|
197
200
|
try {
|
|
198
|
-
return await t((i, o) =>
|
|
201
|
+
return await t((i, o) => Er(r, i, o), r);
|
|
199
202
|
} catch (e) {
|
|
200
203
|
throw s.error(`error ${e} while doing traced operation, state: ${JSON.stringify(r)}`), e;
|
|
201
204
|
}
|
|
202
205
|
}
|
|
203
|
-
const
|
|
204
|
-
class
|
|
206
|
+
const Fr = "config-local.yaml";
|
|
207
|
+
class Ar {
|
|
205
208
|
constructor(t, r, e, i, o, n, c, a) {
|
|
206
209
|
w(this, "instance");
|
|
207
210
|
w(this, "pid");
|
|
@@ -211,7 +214,7 @@ class Fr {
|
|
|
211
214
|
this.logger = t, this.workingDir = r, this.startOptions = e, this.initialStartHistory = i, this.onClose = o, this.onError = n, this.onCloseAndError = c, this.onCloseAndErrorNoStop = a;
|
|
212
215
|
}
|
|
213
216
|
async start() {
|
|
214
|
-
await
|
|
217
|
+
await k(this.logger, async (t, r) => {
|
|
215
218
|
this.wasStopped = !1;
|
|
216
219
|
const e = cr(this.logger, this.startOptions);
|
|
217
220
|
e.on("error", (o) => {
|
|
@@ -222,20 +225,20 @@ class Fr {
|
|
|
222
225
|
this.logger.warn(`platforma was closed, started opts: ${JSON.stringify(this.debugInfo())}`), this.onClose !== void 0 && this.onClose(this), this.onCloseAndError !== void 0 && this.onCloseAndError(this), this.onCloseAndErrorNoStop !== void 0 && !this.wasStopped && this.onCloseAndErrorNoStop(this);
|
|
223
226
|
}), t("started", !0);
|
|
224
227
|
const i = t("pidFile", J(this.workingDir));
|
|
225
|
-
t("pid", p(e.pid)), t("pidWritten", await
|
|
228
|
+
t("pid", p(e.pid)), t("pidWritten", await Sr(i, p(e.pid))), this.nRuns++, this.instance = e, this.pid = e.pid, this.lastRunHistory = r;
|
|
226
229
|
});
|
|
227
230
|
}
|
|
228
231
|
stop() {
|
|
229
|
-
this.wasStopped = !0,
|
|
232
|
+
this.wasStopped = !0, j(p(this.pid));
|
|
230
233
|
}
|
|
231
234
|
async waitStopped() {
|
|
232
|
-
await
|
|
235
|
+
await H(p(this.pid), 15e3);
|
|
233
236
|
}
|
|
234
237
|
stopped() {
|
|
235
238
|
return this.wasStopped;
|
|
236
239
|
}
|
|
237
240
|
async isAlive() {
|
|
238
|
-
return await
|
|
241
|
+
return await b(p(this.pid));
|
|
239
242
|
}
|
|
240
243
|
debugInfo() {
|
|
241
244
|
return {
|
|
@@ -248,21 +251,21 @@ class Fr {
|
|
|
248
251
|
};
|
|
249
252
|
}
|
|
250
253
|
}
|
|
251
|
-
async function
|
|
254
|
+
async function st(s, t) {
|
|
252
255
|
const r = {
|
|
253
256
|
plBinary: yr(),
|
|
254
257
|
spawnOptions: {},
|
|
255
258
|
closeOld: !0,
|
|
256
259
|
...t
|
|
257
260
|
};
|
|
258
|
-
return await
|
|
261
|
+
return await k(s, async (e, i) => {
|
|
259
262
|
e("startOptions", { ...r, config: "too wordy" });
|
|
260
263
|
const o = d.resolve(r.workingDir);
|
|
261
264
|
r.closeOld && e("closeOld", await Dr(s, o));
|
|
262
|
-
const n = d.join(o,
|
|
265
|
+
const n = d.join(o, Fr);
|
|
263
266
|
s.info(`writing configuration '${n}'...`), await f.writeFile(n, r.config);
|
|
264
|
-
const c =
|
|
265
|
-
cmd: e("binaryPath", d.join("binaries",
|
|
267
|
+
const c = d.join(o, "binaries"), a = await $r(s, c, r.plBinary), h = {
|
|
268
|
+
cmd: e("binaryPath", d.join("binaries", a)),
|
|
266
269
|
args: ["-config", n],
|
|
267
270
|
opts: {
|
|
268
271
|
env: { ...process.env },
|
|
@@ -274,34 +277,34 @@ async function it(s, t) {
|
|
|
274
277
|
}
|
|
275
278
|
};
|
|
276
279
|
e("processOpts", {
|
|
277
|
-
cmd:
|
|
278
|
-
args:
|
|
279
|
-
cwd:
|
|
280
|
+
cmd: h.cmd,
|
|
281
|
+
args: h.args,
|
|
282
|
+
cwd: h.opts.cwd
|
|
280
283
|
});
|
|
281
|
-
const
|
|
284
|
+
const u = new Ar(
|
|
282
285
|
s,
|
|
283
286
|
r.workingDir,
|
|
284
|
-
|
|
287
|
+
h,
|
|
285
288
|
i,
|
|
286
289
|
r.onClose,
|
|
287
290
|
r.onError,
|
|
288
291
|
r.onCloseAndError,
|
|
289
292
|
r.onCloseAndErrorNoStop
|
|
290
293
|
);
|
|
291
|
-
return await
|
|
294
|
+
return await u.start(), u;
|
|
292
295
|
});
|
|
293
296
|
}
|
|
294
297
|
async function Dr(s, t) {
|
|
295
|
-
return await
|
|
296
|
-
const i = r("pidFilePath", J(t)), o = r("pid", await
|
|
297
|
-
return o !== void 0 && n && (r("stopped",
|
|
298
|
+
return await k(s, async (r, e) => {
|
|
299
|
+
const i = r("pidFilePath", J(t)), o = r("pid", await vr(i)), n = r("wasAlive", await b(o));
|
|
300
|
+
return o !== void 0 && n && (r("stopped", j(o)), r("waitStopped", await H(o, 1e4))), e;
|
|
298
301
|
});
|
|
299
302
|
}
|
|
300
303
|
const br = {
|
|
301
304
|
keepaliveInterval: 6e4,
|
|
302
305
|
keepaliveCountMax: 10
|
|
303
306
|
};
|
|
304
|
-
class
|
|
307
|
+
class R {
|
|
305
308
|
constructor(t, r) {
|
|
306
309
|
w(this, "config");
|
|
307
310
|
w(this, "homeDir");
|
|
@@ -317,7 +320,7 @@ class x {
|
|
|
317
320
|
const e = {
|
|
318
321
|
...br,
|
|
319
322
|
...r
|
|
320
|
-
}, i = new
|
|
323
|
+
}, i = new R(t, new E());
|
|
321
324
|
return await i.connect(e), i;
|
|
322
325
|
}
|
|
323
326
|
getForwardedServers() {
|
|
@@ -337,7 +340,7 @@ class x {
|
|
|
337
340
|
* @returns A promise that resolves when the connection is established or rejects on error.
|
|
338
341
|
*/
|
|
339
342
|
async connect(t) {
|
|
340
|
-
return this.config = t, await
|
|
343
|
+
return this.config = t, await xr(this.client, t);
|
|
341
344
|
}
|
|
342
345
|
/**
|
|
343
346
|
* Executes a command on the SSH server.
|
|
@@ -369,7 +372,7 @@ class x {
|
|
|
369
372
|
static async getAuthTypes(t, r) {
|
|
370
373
|
return new Promise((e) => {
|
|
371
374
|
let i = "";
|
|
372
|
-
const o = new
|
|
375
|
+
const o = new E();
|
|
373
376
|
o.on("ready", () => {
|
|
374
377
|
o.end();
|
|
375
378
|
const n = this.extractAuthMethods(i);
|
|
@@ -404,10 +407,10 @@ class x {
|
|
|
404
407
|
* @returns { server: net.Server } A promise resolving with the created server instance.
|
|
405
408
|
*/
|
|
406
409
|
async forwardPort(t, r) {
|
|
407
|
-
const e = `ssh.forward:${t.localPort}:${t.remotePort}.id_${
|
|
410
|
+
const e = `ssh.forward:${t.localPort}:${t.remotePort}.id_${D(1).toString("hex")}`;
|
|
408
411
|
r = r ?? this.config;
|
|
409
412
|
const i = new Y((o) => new Promise((n, c) => {
|
|
410
|
-
const a = new
|
|
413
|
+
const a = new E();
|
|
411
414
|
a.on("ready", () => {
|
|
412
415
|
this.logger.info(`${e}.client.ready`), n(a);
|
|
413
416
|
}), a.on("error", (l) => {
|
|
@@ -417,8 +420,8 @@ class x {
|
|
|
417
420
|
}), a.connect(r);
|
|
418
421
|
}));
|
|
419
422
|
return await i.ensure(), new Promise((o, n) => {
|
|
420
|
-
const c =
|
|
421
|
-
const l = `${e}.sock_${
|
|
423
|
+
const c = I.createServer({ pauseOnConnect: !0 }, async (a) => {
|
|
424
|
+
const l = `${e}.sock_${D(1).toString("hex")}`;
|
|
422
425
|
let h;
|
|
423
426
|
try {
|
|
424
427
|
h = await i.ensure();
|
|
@@ -428,7 +431,7 @@ class x {
|
|
|
428
431
|
}
|
|
429
432
|
let u;
|
|
430
433
|
try {
|
|
431
|
-
u = await
|
|
434
|
+
u = await Or(this.logger, h, "127.0.0.1", 0, "127.0.0.1", t.remotePort);
|
|
432
435
|
} catch (g) {
|
|
433
436
|
this.logger.error(`${l}.forwardOut.err: ${g}`), a.end();
|
|
434
437
|
return;
|
|
@@ -635,14 +638,14 @@ class x {
|
|
|
635
638
|
}
|
|
636
639
|
async __uploadDirectory(t, r, e, i = 432) {
|
|
637
640
|
return new Promise((o, n) => {
|
|
638
|
-
|
|
641
|
+
A.readdir(r, async (c, a) => {
|
|
639
642
|
if (c)
|
|
640
643
|
return n(new Error(`ssh.__uploadDir: err ${c}, localDir: ${r}, remoteDir: ${e}`));
|
|
641
644
|
try {
|
|
642
645
|
await this.__createRemoteDirectory(t, e);
|
|
643
646
|
for (const l of a) {
|
|
644
647
|
const h = d.join(r, l), u = `${e}/${l}`;
|
|
645
|
-
|
|
648
|
+
A.lstatSync(h).isDirectory() ? await this.__uploadDirectory(t, h, u, i) : await this.uploadFileUsingExistingSftp(t, h, u, i);
|
|
646
649
|
}
|
|
647
650
|
o();
|
|
648
651
|
} catch (l) {
|
|
@@ -740,7 +743,7 @@ class x {
|
|
|
740
743
|
this.closeForwardedPorts(), this.client.end();
|
|
741
744
|
}
|
|
742
745
|
}
|
|
743
|
-
async function
|
|
746
|
+
async function xr(s, t, r, e) {
|
|
744
747
|
return new Promise((i, o) => {
|
|
745
748
|
s.on("ready", () => {
|
|
746
749
|
i(s);
|
|
@@ -750,70 +753,70 @@ async function Ar(s, t, r, e) {
|
|
|
750
753
|
}), s.connect(t);
|
|
751
754
|
});
|
|
752
755
|
}
|
|
753
|
-
async function
|
|
756
|
+
async function Or(s, t, r, e, i, o) {
|
|
754
757
|
return new Promise((n, c) => {
|
|
755
758
|
t.forwardOut(r, e, i, o, (a, l) => a ? (s.error(`forwardOut.error: ${a}`), c(a)) : n(l));
|
|
756
759
|
});
|
|
757
760
|
}
|
|
758
|
-
const
|
|
761
|
+
const kr = "minio-2024-12-18T13-15-44Z", Rr = "supervisord-0.7.3", Ur = "supervisord_0.7.3_Linux_64-bit";
|
|
759
762
|
function $(s) {
|
|
760
763
|
return d.join(s, "platforma_ssh");
|
|
761
764
|
}
|
|
762
|
-
function
|
|
765
|
+
function S(s) {
|
|
763
766
|
return d.join(s, "platforma_ssh", "binaries");
|
|
764
767
|
}
|
|
765
768
|
function Nr(s, t) {
|
|
766
|
-
return d.join(
|
|
769
|
+
return d.join(S(s), `pl-${O()}-${P(t)}`);
|
|
767
770
|
}
|
|
768
771
|
function L(s, t) {
|
|
769
772
|
return d.join(Nr(s, t), "binaries");
|
|
770
773
|
}
|
|
771
|
-
function
|
|
774
|
+
function N(s, t) {
|
|
772
775
|
return d.join(L(s, t), "platforma");
|
|
773
776
|
}
|
|
774
|
-
function
|
|
777
|
+
function Br(s, t) {
|
|
775
778
|
return d.join(L(s, t), "free-port");
|
|
776
779
|
}
|
|
777
780
|
function z(s, t) {
|
|
778
|
-
return d.join(
|
|
781
|
+
return d.join(S(s), `minio-2024-12-18T13-15-44Z-${P(t)}`);
|
|
779
782
|
}
|
|
780
783
|
function Tr(s, t) {
|
|
781
784
|
return d.join(z(s, t), "minio");
|
|
782
785
|
}
|
|
783
|
-
function
|
|
784
|
-
return d.join(
|
|
786
|
+
function _r(s, t) {
|
|
787
|
+
return d.join(S(s), `supervisord-0.7.3-${P(t)}`, Ur);
|
|
785
788
|
}
|
|
786
|
-
function
|
|
787
|
-
return d.join(
|
|
789
|
+
function G(s, t) {
|
|
790
|
+
return d.join(_r(s, t), "supervisord");
|
|
788
791
|
}
|
|
789
|
-
function
|
|
792
|
+
function W(s) {
|
|
790
793
|
return d.join($(s), "supervisor.conf");
|
|
791
794
|
}
|
|
792
|
-
function
|
|
795
|
+
function B(s) {
|
|
793
796
|
return d.join($(s), "connection.txt");
|
|
794
797
|
}
|
|
795
|
-
async function
|
|
796
|
-
const e = await
|
|
798
|
+
async function Ir(s, t, r) {
|
|
799
|
+
const e = await U(s, t, r, "--daemon");
|
|
797
800
|
if (e.stderr)
|
|
798
801
|
throw new Error(`Can not run ssh Platforma ${e.stderr}`);
|
|
799
802
|
}
|
|
800
803
|
async function jr(s, t, r) {
|
|
801
|
-
const e = await
|
|
804
|
+
const e = await U(s, t, r, "ctl shutdown");
|
|
802
805
|
if (e.stderr)
|
|
803
806
|
throw new Error(`Can not stop ssh Platforma ${e.stderr}`);
|
|
804
807
|
}
|
|
805
|
-
async function
|
|
806
|
-
const i = await
|
|
808
|
+
async function Hr(s, t, r, e) {
|
|
809
|
+
const i = await U(t, r, e, "ctl status");
|
|
807
810
|
if (i.stderr)
|
|
808
811
|
return s.info(`supervisord ctl status: stderr occurred: ${i.stderr}, stdout: ${i.stdout}`), !1;
|
|
809
812
|
const o = {
|
|
810
|
-
platforma:
|
|
811
|
-
minio:
|
|
813
|
+
platforma: T(i.stdout, "platforma"),
|
|
814
|
+
minio: T(i.stdout, "minio")
|
|
812
815
|
};
|
|
813
816
|
return o.platforma && o.minio ? !0 : (o.minio || s.warn("Minio is not running on the server"), o.platforma || s.warn("Platforma is not running on the server"), !1);
|
|
814
817
|
}
|
|
815
|
-
function
|
|
816
|
-
const c = Object.entries(t).map(([h, u]) => `${h}="${u}"`).join(","), a =
|
|
818
|
+
function Mr(s, t, r, e, i, o, n) {
|
|
819
|
+
const c = Object.entries(t).map(([h, u]) => `${h}="${u}"`).join(","), a = D(16).toString("hex"), l = r;
|
|
817
820
|
return `
|
|
818
821
|
[supervisord]
|
|
819
822
|
logfile=${e}/supervisord.log
|
|
@@ -845,18 +848,18 @@ directory=${e}
|
|
|
845
848
|
autorestart=true
|
|
846
849
|
`;
|
|
847
850
|
}
|
|
848
|
-
async function
|
|
849
|
-
const i =
|
|
851
|
+
async function U(s, t, r, e) {
|
|
852
|
+
const i = G(t, r), o = W(t), n = `${i} --configuration ${o} ${e}`;
|
|
850
853
|
return await s.exec(n);
|
|
851
854
|
}
|
|
852
|
-
function
|
|
855
|
+
function T(s, t) {
|
|
853
856
|
return ((i) => i.replace(/\x1B\[[0-9;]*m/g, ""))(s).split(`
|
|
854
857
|
`).some((i) => {
|
|
855
858
|
const [o, n] = i.trim().split(/\s{2,}/);
|
|
856
859
|
return o === t && n === "Running";
|
|
857
860
|
});
|
|
858
861
|
}
|
|
859
|
-
class
|
|
862
|
+
class K {
|
|
860
863
|
constructor(t, r, e) {
|
|
861
864
|
w(this, "initState", {});
|
|
862
865
|
this.logger = t, this.sshClient = r, this.username = e;
|
|
@@ -869,8 +872,8 @@ class q {
|
|
|
869
872
|
}
|
|
870
873
|
static async init(t, r) {
|
|
871
874
|
try {
|
|
872
|
-
const e = await
|
|
873
|
-
return new
|
|
875
|
+
const e = await R.init(t, r);
|
|
876
|
+
return new K(t, e, p(r.username));
|
|
874
877
|
} catch (e) {
|
|
875
878
|
throw t.error(`Connection error in SshClient.init: ${e}`), e;
|
|
876
879
|
}
|
|
@@ -881,7 +884,7 @@ class q {
|
|
|
881
884
|
async isAlive() {
|
|
882
885
|
const t = await this.getArch(), r = await this.getUserHomeDirectory();
|
|
883
886
|
try {
|
|
884
|
-
return await
|
|
887
|
+
return await Hr(this.logger, this.sshClient, r, t.arch);
|
|
885
888
|
} catch {
|
|
886
889
|
return !1;
|
|
887
890
|
}
|
|
@@ -889,7 +892,7 @@ class q {
|
|
|
889
892
|
async start() {
|
|
890
893
|
const t = await this.getArch(), r = await this.getUserHomeDirectory();
|
|
891
894
|
try {
|
|
892
|
-
return await
|
|
895
|
+
return await Ir(this.sshClient, r, t.arch), await this.checkIsAliveWithInterval();
|
|
893
896
|
} catch (e) {
|
|
894
897
|
const i = `ssh.start: error occurred ${e}`;
|
|
895
898
|
throw this.logger.error(i), new Error(i);
|
|
@@ -947,7 +950,7 @@ class q {
|
|
|
947
950
|
await this.sshClient.writeFileOnTheServer(c, a), this.logger.info(`Created file ${c}`);
|
|
948
951
|
for (const c of i.dirsToCreate)
|
|
949
952
|
await this.sshClient.createRemoteDirectory(c), this.logger.info(`Created directory ${c}`);
|
|
950
|
-
const o =
|
|
953
|
+
const o = Mr(
|
|
951
954
|
i.minioConfig.storageDir,
|
|
952
955
|
i.minioConfig.envs,
|
|
953
956
|
await this.getFreePortForPlatformaOnServer(r.remoteHome, r.arch),
|
|
@@ -956,14 +959,14 @@ class q {
|
|
|
956
959
|
r.binPaths.minioRelPath,
|
|
957
960
|
r.binPaths.downloadedPl
|
|
958
961
|
);
|
|
959
|
-
if (!await this.sshClient.writeFileOnTheServer(
|
|
962
|
+
if (!await this.sshClient.writeFileOnTheServer(W(r.remoteHome), o))
|
|
960
963
|
throw new Error(`Can not write supervisord config on the server ${$(r.remoteHome)}`);
|
|
961
964
|
return r.connectionInfo = {
|
|
962
965
|
plUser: i.plUser,
|
|
963
966
|
plPassword: i.plPassword,
|
|
964
967
|
ports: r.ports
|
|
965
968
|
}, await this.sshClient.writeFileOnTheServer(
|
|
966
|
-
|
|
969
|
+
B(r.remoteHome),
|
|
967
970
|
JSON.stringify(r.connectionInfo, void 0, 2)
|
|
968
971
|
), await this.start(), r.started = !0, this.initState = r, {
|
|
969
972
|
plUser: i.plUser,
|
|
@@ -983,7 +986,7 @@ class q {
|
|
|
983
986
|
r,
|
|
984
987
|
e,
|
|
985
988
|
"pl",
|
|
986
|
-
`pl-${
|
|
989
|
+
`pl-${O()}`
|
|
987
990
|
);
|
|
988
991
|
i.push(o);
|
|
989
992
|
const n = await this.downloadAndUntar(
|
|
@@ -991,7 +994,7 @@ class q {
|
|
|
991
994
|
r,
|
|
992
995
|
e,
|
|
993
996
|
"supervisord",
|
|
994
|
-
|
|
997
|
+
Rr
|
|
995
998
|
);
|
|
996
999
|
i.push(n);
|
|
997
1000
|
const c = Tr(r, e.arch), a = await this.downloadAndUntar(
|
|
@@ -999,12 +1002,12 @@ class q {
|
|
|
999
1002
|
r,
|
|
1000
1003
|
e,
|
|
1001
1004
|
"minio",
|
|
1002
|
-
|
|
1005
|
+
kr
|
|
1003
1006
|
);
|
|
1004
1007
|
return i.push(a), await this.sshClient.chmod(c, 488), {
|
|
1005
1008
|
history: i,
|
|
1006
1009
|
minioRelPath: c,
|
|
1007
|
-
downloadedPl:
|
|
1010
|
+
downloadedPl: N(r, e.arch)
|
|
1008
1011
|
};
|
|
1009
1012
|
} catch (o) {
|
|
1010
1013
|
const n = `SshPl.downloadBinariesAndUploadToServer: error ${o} occurred, state: ${JSON.stringify(i)}`;
|
|
@@ -1017,12 +1020,12 @@ class q {
|
|
|
1017
1020
|
* For this reason, we extract all to the remote server. */
|
|
1018
1021
|
async downloadAndUntar(t, r, e, i, o) {
|
|
1019
1022
|
const n = {};
|
|
1020
|
-
n.binBasePath =
|
|
1023
|
+
n.binBasePath = S(r), await this.sshClient.createRemoteDirectory(n.binBasePath), n.binBasePathCreated = !0;
|
|
1021
1024
|
let c = null;
|
|
1022
1025
|
const a = 5;
|
|
1023
1026
|
for (let h = 1; h <= a; h++)
|
|
1024
1027
|
try {
|
|
1025
|
-
c = await
|
|
1028
|
+
c = await wr(
|
|
1026
1029
|
this.logger,
|
|
1027
1030
|
t,
|
|
1028
1031
|
i,
|
|
@@ -1032,7 +1035,7 @@ class q {
|
|
|
1032
1035
|
);
|
|
1033
1036
|
break;
|
|
1034
1037
|
} catch (u) {
|
|
1035
|
-
if (await
|
|
1038
|
+
if (await F(300), h == a)
|
|
1036
1039
|
throw new Error(`downloadAndUntar: ${a} attempts, last error: ${u}`);
|
|
1037
1040
|
}
|
|
1038
1041
|
n.downloadResult = p(c), n.localArchivePath = d.resolve(n.downloadResult.archivePath), n.remoteDir = d.join(n.binBasePath, n.downloadResult.baseName), n.remoteArchivePath = n.remoteDir + ".tgz", await this.sshClient.createRemoteDirectory(n.remoteDir), await this.sshClient.uploadFile(n.localArchivePath, n.remoteArchivePath);
|
|
@@ -1044,20 +1047,20 @@ class q {
|
|
|
1044
1047
|
return n.plUntarDone = !0, n;
|
|
1045
1048
|
}
|
|
1046
1049
|
async needDownload(t, r) {
|
|
1047
|
-
const e =
|
|
1050
|
+
const e = G(t, r.arch), i = z(t, r.arch), o = N(t, r.arch);
|
|
1048
1051
|
return !await this.sshClient.checkFileExists(o) || !await this.sshClient.checkFileExists(i) || !await this.sshClient.checkFileExists(e);
|
|
1049
1052
|
}
|
|
1050
1053
|
async checkIsAliveWithInterval(t = 1e3, r = 15, e = !0) {
|
|
1051
1054
|
const i = r * t;
|
|
1052
1055
|
let o = 0, n = await this.isAlive();
|
|
1053
1056
|
for (; e ? !n : n; ) {
|
|
1054
|
-
if (await
|
|
1057
|
+
if (await F(t), o += t, o > i)
|
|
1055
1058
|
throw new Error(`isAliveWithInterval: The process did not ${e ? "started" : "stopped"} after ${i} ms.`);
|
|
1056
1059
|
n = await this.isAlive();
|
|
1057
1060
|
}
|
|
1058
1061
|
}
|
|
1059
1062
|
async getUserCredentials(t) {
|
|
1060
|
-
const r = await this.sshClient.readFile(
|
|
1063
|
+
const r = await this.sshClient.readFile(B(t));
|
|
1061
1064
|
return JSON.parse(r);
|
|
1062
1065
|
}
|
|
1063
1066
|
async fetchPorts(t, r) {
|
|
@@ -1086,7 +1089,7 @@ class q {
|
|
|
1086
1089
|
}
|
|
1087
1090
|
async getLocalFreePort() {
|
|
1088
1091
|
return new Promise((t) => {
|
|
1089
|
-
const r =
|
|
1092
|
+
const r = I.createServer();
|
|
1090
1093
|
r.listen(0, () => {
|
|
1091
1094
|
const e = r.address().port;
|
|
1092
1095
|
r.close((i) => t(e));
|
|
@@ -1094,7 +1097,7 @@ class q {
|
|
|
1094
1097
|
});
|
|
1095
1098
|
}
|
|
1096
1099
|
async getFreePortForPlatformaOnServer(t, r) {
|
|
1097
|
-
const e =
|
|
1100
|
+
const e = Br(t, r.arch), { stdout: i, stderr: o } = await this.sshClient.exec(`${e}`);
|
|
1098
1101
|
if (o)
|
|
1099
1102
|
throw new Error(`getFreePortForPlatformaOnServer: stderr is not empty: ${o}, stdout: ${i}`);
|
|
1100
1103
|
return +i;
|
|
@@ -1120,11 +1123,11 @@ class q {
|
|
|
1120
1123
|
}
|
|
1121
1124
|
}
|
|
1122
1125
|
export {
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1126
|
+
Fr as LocalConfigYaml,
|
|
1127
|
+
Ar as LocalPl,
|
|
1128
|
+
R as SshClient,
|
|
1129
|
+
K as SshPl,
|
|
1130
|
+
O as getDefaultPlVersion,
|
|
1131
|
+
st as localPlatformaInit
|
|
1129
1132
|
};
|
|
1130
1133
|
//# sourceMappingURL=index.mjs.map
|