@milaboratories/pl-deployments 1.1.4 → 1.1.5
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 +13 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +301 -284
- package/dist/index.mjs.map +1 -1
- package/dist/ssh/ssh.d.ts +2 -2
- package/dist/ssh/ssh.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/ssh/__tests__/common-utils.ts +1 -1
- package/src/ssh/ssh.ts +117 -54
package/dist/index.mjs
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { spawn as
|
|
5
|
-
import { sleep as
|
|
1
|
+
var G = Object.defineProperty;
|
|
2
|
+
var Z = (s, r, t) => r in s ? G(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t;
|
|
3
|
+
var w = (s, r, t) => Z(s, typeof r != "symbol" ? r + "" : r, t);
|
|
4
|
+
import { spawn as V } from "node:child_process";
|
|
5
|
+
import { sleep as C, fileExists as m, assertNever as T, notEmpty as f, RetryablePromise as Y } from "@milaboratories/ts-helpers";
|
|
6
6
|
import E from "node:fs";
|
|
7
|
-
import
|
|
7
|
+
import p, { readFile as Q } from "node:fs/promises";
|
|
8
8
|
import u from "upath";
|
|
9
|
-
import { request as
|
|
10
|
-
import { Readable as
|
|
11
|
-
import { text as
|
|
12
|
-
import * as
|
|
13
|
-
import
|
|
9
|
+
import { request as X } from "undici";
|
|
10
|
+
import { Readable as tt, Writable as rt } from "node:stream";
|
|
11
|
+
import { text as et } from "node:stream/consumers";
|
|
12
|
+
import * as it from "tar";
|
|
13
|
+
import ot from "decompress";
|
|
14
14
|
import k from "node:os";
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
function
|
|
15
|
+
import st, { Client as S } from "ssh2";
|
|
16
|
+
import B from "node:net";
|
|
17
|
+
import nt from "node:dns";
|
|
18
|
+
import { randomBytes as F } from "node:crypto";
|
|
19
|
+
import { generateSshPlConfigs as at, getFreePort as y } from "@milaboratories/pl-config";
|
|
20
|
+
function ct(s, r) {
|
|
21
21
|
return s.info(`Running:
|
|
22
22
|
cmd: ${JSON.stringify([r.cmd, ...r.args])}
|
|
23
|
-
wd: ${r.opts.cwd}`), s.info(" spawning child process"),
|
|
23
|
+
wd: ${r.opts.cwd}`), s.info(" spawning child process"), V(r.cmd, r.args, r.opts);
|
|
24
24
|
}
|
|
25
|
-
async function
|
|
25
|
+
async function D(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 _(s) {
|
|
33
33
|
return process.kill(s, "SIGINT");
|
|
34
34
|
}
|
|
35
|
-
async function
|
|
35
|
+
async function j(s, r) {
|
|
36
36
|
let e = 0;
|
|
37
|
-
for (; await
|
|
38
|
-
if (await
|
|
37
|
+
for (; await D(s); )
|
|
38
|
+
if (await C(100), e += 100, e > r)
|
|
39
39
|
throw new Error(`The process did not stopped after ${r} ms.`);
|
|
40
40
|
}
|
|
41
|
-
const
|
|
42
|
-
function
|
|
41
|
+
const lt = ["linux", "macos", "windows"];
|
|
42
|
+
function I(s) {
|
|
43
43
|
switch (s.toLowerCase()) {
|
|
44
44
|
case "darwin":
|
|
45
45
|
return "macos";
|
|
@@ -49,12 +49,12 @@ function H(s) {
|
|
|
49
49
|
return "windows";
|
|
50
50
|
default:
|
|
51
51
|
throw new Error(
|
|
52
|
-
`operating system '${s}' is not currently supported by Platforma ecosystem. The list of OSes supported: ` + JSON.stringify(
|
|
52
|
+
`operating system '${s}' is not currently supported by Platforma ecosystem. The list of OSes supported: ` + JSON.stringify(lt)
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
const
|
|
57
|
-
function
|
|
56
|
+
const ht = ["amd64", "arm64"];
|
|
57
|
+
function P(s) {
|
|
58
58
|
switch (s) {
|
|
59
59
|
case "aarch64":
|
|
60
60
|
case "aarch64_be":
|
|
@@ -65,155 +65,155 @@ function $(s) {
|
|
|
65
65
|
return "amd64";
|
|
66
66
|
default:
|
|
67
67
|
throw new Error(
|
|
68
|
-
`processor architecture '${s}' is not currently supported by Platforma ecosystem. The list of architectures supported: ` + JSON.stringify(
|
|
68
|
+
`processor architecture '${s}' is not currently supported by Platforma ecosystem. The list of architectures supported: ` + JSON.stringify(ht)
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
async function
|
|
73
|
-
const n =
|
|
74
|
-
return await
|
|
72
|
+
async function ut(s, r, t, e, i, o) {
|
|
73
|
+
const n = wt(t, e, r, P(i), I(o)), { archiveUrl: c, archivePath: a } = n;
|
|
74
|
+
return await H(s, c, a), n;
|
|
75
75
|
}
|
|
76
|
-
async function
|
|
77
|
-
const o =
|
|
78
|
-
return await
|
|
76
|
+
async function dt(s, r, t, e, i) {
|
|
77
|
+
const o = pt(t, r, P(e), I(i)), { archiveUrl: n, archivePath: c, archiveType: a, targetFolder: l, binaryPath: h } = o;
|
|
78
|
+
return await H(s, n, c), await mt(s, c, a, l), o;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
const o = `${r}-${e}`, n =
|
|
80
|
+
function wt(s, r, t, e, i) {
|
|
81
|
+
const o = `${r}-${e}`, n = M[i], c = `${o}.${n}`, a = `https://cdn.platforma.bio/software/${s}/${i}/${c}`, l = u.join(t, c), h = u.join(t, o);
|
|
82
82
|
return {
|
|
83
|
-
archiveUrl:
|
|
83
|
+
archiveUrl: a,
|
|
84
84
|
archivePath: l,
|
|
85
85
|
archiveType: n,
|
|
86
86
|
targetFolder: h,
|
|
87
87
|
baseName: o
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
const i = `pl-${s}-${t}`, o =
|
|
90
|
+
function pt(s, r, t, e) {
|
|
91
|
+
const i = `pl-${s}-${t}`, o = M[e], n = `${i}.${o}`, c = `https://cdn.platforma.bio/software/pl/${e}/${n}`, a = u.join(r, n), l = u.join(r, i), h = u.join(i, "binaries", gt[e]);
|
|
92
92
|
return {
|
|
93
|
-
archiveUrl:
|
|
94
|
-
archivePath:
|
|
93
|
+
archiveUrl: c,
|
|
94
|
+
archivePath: a,
|
|
95
95
|
archiveType: o,
|
|
96
96
|
targetFolder: l,
|
|
97
97
|
binaryPath: h,
|
|
98
98
|
baseName: i
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
-
async function
|
|
101
|
+
async function H(s, r, t) {
|
|
102
102
|
const e = {};
|
|
103
103
|
e.dstArchive = t;
|
|
104
104
|
try {
|
|
105
|
-
if (e.fileExisted = await
|
|
105
|
+
if (e.fileExisted = await m(t), e.fileExisted)
|
|
106
106
|
return s.info(`Platforma Backend archive download skipped: '${t}' already exists`), e;
|
|
107
|
-
await
|
|
107
|
+
await p.mkdir(u.dirname(t), { recursive: !0 }), e.dirnameCreated = !0, s.info(`Downloading archive:
|
|
108
108
|
URL: ${r}
|
|
109
109
|
Save to: ${t}`);
|
|
110
|
-
const { body: i, statusCode: o } = await
|
|
110
|
+
const { body: i, statusCode: o } = await X(r);
|
|
111
111
|
if (e.statusCode = o, o != 200) {
|
|
112
|
-
const n = await
|
|
112
|
+
const n = await et(i);
|
|
113
113
|
throw e.errorMsg = `failed to download archive: ${o}, response: ${n.slice(0, 1e3)}`, s.error(e.errorMsg), new Error(e.errorMsg);
|
|
114
114
|
}
|
|
115
|
-
return e.tmpPath = t + ".tmp", await
|
|
115
|
+
return e.tmpPath = t + ".tmp", await tt.toWeb(i).pipeTo(rt.toWeb(E.createWriteStream(e.tmpPath))), e.wroteTmp = !0, e.tmpExisted = await m(e.tmpPath), await p.rename(e.tmpPath, t), e.renamed = !0, e.newExisted = await m(t), e;
|
|
116
116
|
} catch (i) {
|
|
117
117
|
const o = `downloadArchive: error ${JSON.stringify(i)} occurred, state: ${JSON.stringify(e)}`;
|
|
118
118
|
throw s.error(o), new Error(o);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
const
|
|
122
|
-
async function
|
|
123
|
-
if (s.info("extracting archive..."), s.info(` archive path: '${r}'`), s.info(` target dir: '${e}'`), !await
|
|
121
|
+
const ft = ".ok";
|
|
122
|
+
async function mt(s, r, t, e) {
|
|
123
|
+
if (s.info("extracting archive..."), s.info(` archive path: '${r}'`), s.info(` target dir: '${e}'`), !await m(r)) {
|
|
124
124
|
const o = `Platforma Backend binary archive not found at '${r}'`;
|
|
125
125
|
throw s.error(o), new Error(o);
|
|
126
126
|
}
|
|
127
|
-
const i = u.join(e,
|
|
128
|
-
if (await
|
|
127
|
+
const i = u.join(e, ft);
|
|
128
|
+
if (await m(i)) {
|
|
129
129
|
s.info(`Platforma Backend binaries unpack skipped: '${e}' exists`);
|
|
130
130
|
return;
|
|
131
131
|
}
|
|
132
|
-
switch (await
|
|
132
|
+
switch (await m(e) && (s.info(`Removing previous incompletely unpacked folder: '${e}'`), await p.rm(e, { recursive: !0 })), s.info(` creating target dir '${e}'`), await p.mkdir(e, { recursive: !0 }), s.info(
|
|
133
133
|
`Unpacking Platforma Backend archive:
|
|
134
134
|
Archive: ${r}
|
|
135
135
|
Target dir: ${e}`
|
|
136
136
|
), t) {
|
|
137
137
|
case "tgz":
|
|
138
|
-
await
|
|
138
|
+
await it.x({
|
|
139
139
|
file: r,
|
|
140
140
|
cwd: e,
|
|
141
141
|
gzip: !0
|
|
142
142
|
});
|
|
143
143
|
break;
|
|
144
144
|
case "zip":
|
|
145
|
-
await
|
|
145
|
+
await ot(r, e);
|
|
146
146
|
break;
|
|
147
147
|
default:
|
|
148
|
-
|
|
148
|
+
T(t);
|
|
149
149
|
}
|
|
150
|
-
await
|
|
150
|
+
await p.writeFile(i, "ok"), s.info(" ... unpack done.");
|
|
151
151
|
}
|
|
152
|
-
const
|
|
152
|
+
const M = {
|
|
153
153
|
linux: "tgz",
|
|
154
154
|
macos: "tgz",
|
|
155
155
|
windows: "zip"
|
|
156
|
-
},
|
|
156
|
+
}, gt = {
|
|
157
157
|
linux: "platforma",
|
|
158
158
|
macos: "platforma",
|
|
159
159
|
windows: "platforma.exe"
|
|
160
160
|
};
|
|
161
|
-
function
|
|
161
|
+
function b() {
|
|
162
162
|
return "1.18.3";
|
|
163
163
|
}
|
|
164
|
-
function
|
|
165
|
-
return { type: "Download", version:
|
|
164
|
+
function yt() {
|
|
165
|
+
return { type: "Download", version: b() };
|
|
166
166
|
}
|
|
167
|
-
async function
|
|
167
|
+
async function $t(s, r, t) {
|
|
168
168
|
switch (t.type) {
|
|
169
169
|
case "Download":
|
|
170
|
-
return (await
|
|
170
|
+
return (await dt(s, r, t.version, k.arch(), k.platform())).binaryPath;
|
|
171
171
|
case "Local":
|
|
172
172
|
return t.path;
|
|
173
173
|
default:
|
|
174
|
-
|
|
174
|
+
T(t);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function J(s) {
|
|
178
178
|
return u.join(s, "pl_pid");
|
|
179
179
|
}
|
|
180
|
-
async function
|
|
181
|
-
if (!await
|
|
180
|
+
async function Pt(s) {
|
|
181
|
+
if (!await m(s))
|
|
182
182
|
return;
|
|
183
|
-
const r = await
|
|
183
|
+
const r = await p.readFile(s);
|
|
184
184
|
return Number(r.toString());
|
|
185
185
|
}
|
|
186
|
-
async function
|
|
187
|
-
await
|
|
186
|
+
async function vt(s, r) {
|
|
187
|
+
await p.writeFile(s, JSON.stringify(r));
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function St() {
|
|
190
190
|
return {};
|
|
191
191
|
}
|
|
192
|
-
function
|
|
192
|
+
function Ct(s, r, t) {
|
|
193
193
|
return s[r] = t, t;
|
|
194
194
|
}
|
|
195
|
-
async function
|
|
196
|
-
const t =
|
|
195
|
+
async function A(s, r) {
|
|
196
|
+
const t = St();
|
|
197
197
|
try {
|
|
198
|
-
return await r((i, o) =>
|
|
198
|
+
return await r((i, o) => Ct(t, i, o), t);
|
|
199
199
|
} catch (e) {
|
|
200
200
|
throw s.error(`error ${e} while doing traced operation, state: ${JSON.stringify(t)}`), e;
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
const
|
|
204
|
-
class
|
|
205
|
-
constructor(r, t, e, i, o, n,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this.logger = r, this.workingDir = t, this.startOptions = e, this.initialStartHistory = i, this.onClose = o, this.onError = n, this.onCloseAndError =
|
|
203
|
+
const Et = "config-local.yaml";
|
|
204
|
+
class Ft {
|
|
205
|
+
constructor(r, t, e, i, o, n, c, a) {
|
|
206
|
+
w(this, "instance");
|
|
207
|
+
w(this, "pid");
|
|
208
|
+
w(this, "nRuns", 0);
|
|
209
|
+
w(this, "lastRunHistory", {});
|
|
210
|
+
w(this, "wasStopped", !1);
|
|
211
|
+
this.logger = r, this.workingDir = t, this.startOptions = e, this.initialStartHistory = i, this.onClose = o, this.onError = n, this.onCloseAndError = c, this.onCloseAndErrorNoStop = a;
|
|
212
212
|
}
|
|
213
213
|
async start() {
|
|
214
|
-
await
|
|
214
|
+
await A(this.logger, async (r, t) => {
|
|
215
215
|
this.wasStopped = !1;
|
|
216
|
-
const e =
|
|
216
|
+
const e = ct(this.logger, this.startOptions);
|
|
217
217
|
e.on("error", (o) => {
|
|
218
218
|
this.logger.error(
|
|
219
219
|
`error '${o}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`
|
|
@@ -221,21 +221,21 @@ class Et {
|
|
|
221
221
|
}), e.on("close", () => {
|
|
222
222
|
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
223
|
}), r("started", !0);
|
|
224
|
-
const i = r("pidFile",
|
|
225
|
-
r("pid",
|
|
224
|
+
const i = r("pidFile", J(this.workingDir));
|
|
225
|
+
r("pid", f(e.pid)), r("pidWritten", await vt(i, f(e.pid))), this.nRuns++, this.instance = e, this.pid = e.pid, this.lastRunHistory = t;
|
|
226
226
|
});
|
|
227
227
|
}
|
|
228
228
|
stop() {
|
|
229
|
-
this.wasStopped = !0,
|
|
229
|
+
this.wasStopped = !0, _(f(this.pid));
|
|
230
230
|
}
|
|
231
231
|
async waitStopped() {
|
|
232
|
-
await
|
|
232
|
+
await j(f(this.pid), 15e3);
|
|
233
233
|
}
|
|
234
234
|
stopped() {
|
|
235
235
|
return this.wasStopped;
|
|
236
236
|
}
|
|
237
237
|
async isAlive() {
|
|
238
|
-
return await
|
|
238
|
+
return await D(f(this.pid));
|
|
239
239
|
}
|
|
240
240
|
debugInfo() {
|
|
241
241
|
return {
|
|
@@ -248,21 +248,21 @@ class Et {
|
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
-
async function
|
|
251
|
+
async function ir(s, r) {
|
|
252
252
|
const t = {
|
|
253
|
-
plBinary:
|
|
253
|
+
plBinary: yt(),
|
|
254
254
|
spawnOptions: {},
|
|
255
255
|
closeOld: !0,
|
|
256
256
|
...r
|
|
257
257
|
};
|
|
258
|
-
return await
|
|
258
|
+
return await A(s, async (e, i) => {
|
|
259
259
|
e("startOptions", { ...t, config: "too wordy" });
|
|
260
260
|
const o = u.resolve(t.workingDir);
|
|
261
|
-
t.closeOld && e("closeOld", await
|
|
262
|
-
const n = u.join(o,
|
|
263
|
-
s.info(`writing configuration '${n}'...`), await
|
|
264
|
-
const
|
|
265
|
-
cmd: e("binaryPath", u.join("binaries",
|
|
261
|
+
t.closeOld && e("closeOld", await Dt(s, o));
|
|
262
|
+
const n = u.join(o, Et);
|
|
263
|
+
s.info(`writing configuration '${n}'...`), await p.writeFile(n, t.config);
|
|
264
|
+
const c = await $t(s, u.join(o, "binaries"), t.plBinary), l = {
|
|
265
|
+
cmd: e("binaryPath", u.join("binaries", c)),
|
|
266
266
|
args: ["-config", n],
|
|
267
267
|
opts: {
|
|
268
268
|
env: { ...process.env },
|
|
@@ -278,7 +278,7 @@ async function Xt(s, r) {
|
|
|
278
278
|
args: l.args,
|
|
279
279
|
cwd: l.opts.cwd
|
|
280
280
|
});
|
|
281
|
-
const h = new
|
|
281
|
+
const h = new Ft(
|
|
282
282
|
s,
|
|
283
283
|
t.workingDir,
|
|
284
284
|
l,
|
|
@@ -291,20 +291,20 @@ async function Xt(s, r) {
|
|
|
291
291
|
return await h.start(), h;
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
|
-
async function
|
|
295
|
-
return await
|
|
296
|
-
const i = t("pidFilePath",
|
|
297
|
-
return o !== void 0 && n && (t("stopped",
|
|
294
|
+
async function Dt(s, r) {
|
|
295
|
+
return await A(s, async (t, e) => {
|
|
296
|
+
const i = t("pidFilePath", J(r)), o = t("pid", await Pt(i)), n = t("wasAlive", await D(o));
|
|
297
|
+
return o !== void 0 && n && (t("stopped", _(o)), t("waitStopped", await j(o, 1e4))), e;
|
|
298
298
|
});
|
|
299
299
|
}
|
|
300
|
-
const
|
|
300
|
+
const bt = {
|
|
301
301
|
keepaliveInterval: 6e4,
|
|
302
302
|
keepaliveCountMax: 10
|
|
303
303
|
};
|
|
304
|
-
class
|
|
304
|
+
class x {
|
|
305
305
|
constructor(r, t) {
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
w(this, "config");
|
|
307
|
+
w(this, "homeDir");
|
|
308
308
|
this.logger = r, this.client = t;
|
|
309
309
|
}
|
|
310
310
|
/**
|
|
@@ -314,9 +314,9 @@ class D {
|
|
|
314
314
|
*/
|
|
315
315
|
static async init(r, t) {
|
|
316
316
|
const e = {
|
|
317
|
-
...
|
|
317
|
+
...bt,
|
|
318
318
|
...t
|
|
319
|
-
}, i = new
|
|
319
|
+
}, i = new x(r, new S());
|
|
320
320
|
return await i.connect(e), i;
|
|
321
321
|
}
|
|
322
322
|
getFullHostName() {
|
|
@@ -333,15 +333,7 @@ class D {
|
|
|
333
333
|
* @returns A promise that resolves when the connection is established or rejects on error.
|
|
334
334
|
*/
|
|
335
335
|
async connect(r) {
|
|
336
|
-
return this.config = r,
|
|
337
|
-
this.client.on("ready", () => {
|
|
338
|
-
t(void 0);
|
|
339
|
-
}).on("error", (i) => {
|
|
340
|
-
e(new Error(`ssh.connect: error occurred: ${i}`));
|
|
341
|
-
}).on("timeout", () => {
|
|
342
|
-
e(new Error("timeout was occurred while waiting for SSH connection."));
|
|
343
|
-
}).connect(r);
|
|
344
|
-
});
|
|
336
|
+
return this.config = r, await At(this.client, r);
|
|
345
337
|
}
|
|
346
338
|
/**
|
|
347
339
|
* Executes a command on the SSH server.
|
|
@@ -353,13 +345,13 @@ class D {
|
|
|
353
345
|
this.client.exec(r, (i, o) => {
|
|
354
346
|
if (i)
|
|
355
347
|
return e(`ssh.exec: ${r}, error occurred: ${i}`);
|
|
356
|
-
let n = "",
|
|
357
|
-
o.on("close", (
|
|
358
|
-
|
|
359
|
-
}).on("data", (
|
|
360
|
-
n +=
|
|
361
|
-
}).stderr.on("data", (
|
|
362
|
-
|
|
348
|
+
let n = "", c = "";
|
|
349
|
+
o.on("close", (a) => {
|
|
350
|
+
a === 0 ? t({ stdout: n, stderr: c }) : e(new Error(`Command ${r} exited with code ${a}`));
|
|
351
|
+
}).on("data", (a) => {
|
|
352
|
+
n += a.toString();
|
|
353
|
+
}).stderr.on("data", (a) => {
|
|
354
|
+
c += a.toString();
|
|
363
355
|
});
|
|
364
356
|
});
|
|
365
357
|
});
|
|
@@ -373,7 +365,7 @@ class D {
|
|
|
373
365
|
static async getAuthTypes(r, t) {
|
|
374
366
|
return new Promise((e) => {
|
|
375
367
|
let i = "";
|
|
376
|
-
const o = new
|
|
368
|
+
const o = new S();
|
|
377
369
|
o.on("ready", () => {
|
|
378
370
|
o.end();
|
|
379
371
|
const n = this.extractAuthMethods(i);
|
|
@@ -408,40 +400,50 @@ class D {
|
|
|
408
400
|
* @returns { server: net.Server } A promise resolving with the created server instance.
|
|
409
401
|
*/
|
|
410
402
|
async forwardPort(r, t) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
403
|
+
const e = `ssh.forward:${r.localPort}:${r.remotePort}.id_${F(1).toString("hex")}`;
|
|
404
|
+
t = t ?? this.config;
|
|
405
|
+
const i = new Y((o) => new Promise((n, c) => {
|
|
406
|
+
const a = new S();
|
|
407
|
+
a.on("ready", () => {
|
|
408
|
+
this.logger.info(`${e}.client.ready`), n(a);
|
|
409
|
+
}), a.on("error", (l) => {
|
|
410
|
+
this.logger.info(`${e}.client.error: ${l}`), o.reset(), c(l);
|
|
411
|
+
}), a.on("close", () => {
|
|
412
|
+
this.logger.info(`${e}.client.closed`), o.reset();
|
|
413
|
+
}), a.connect(t);
|
|
414
|
+
}));
|
|
415
|
+
return await i.ensure(), new Promise((o, n) => {
|
|
416
|
+
const c = B.createServer({ pauseOnConnect: !0 }, async (a) => {
|
|
417
|
+
const l = `${e}.sock_${F(1).toString("hex")}`;
|
|
418
|
+
let h;
|
|
419
|
+
try {
|
|
420
|
+
h = await i.ensure();
|
|
421
|
+
} catch (g) {
|
|
422
|
+
this.logger.info(`${l}.persistentClient.catch: ${g}`), a.end();
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
let d;
|
|
426
|
+
try {
|
|
427
|
+
d = await xt(this.logger, h, "127.0.0.1", 0, "127.0.0.1", r.remotePort);
|
|
428
|
+
} catch (g) {
|
|
429
|
+
this.logger.error(`${l}.forwardOut.err: ${g}`), a.end();
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
a.pipe(d), d.pipe(a), a.resume(), d.on("error", (g) => {
|
|
433
|
+
this.logger.error(`${l}.stream.error: ${g}`), a.end(), d.end();
|
|
434
|
+
}), d.on("close", () => {
|
|
435
|
+
a.end(), d.end();
|
|
436
|
+
}), a.on("close", () => {
|
|
437
|
+
this.logger.info(`${l}.localSocket: closed`), a.end(), d.end();
|
|
439
438
|
});
|
|
440
|
-
})
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
439
|
+
});
|
|
440
|
+
c.listen(r.localPort, "127.0.0.1", () => {
|
|
441
|
+
this.logger.info(`${e}.server: started listening`), o({ server: c });
|
|
442
|
+
}), c.on("error", (a) => {
|
|
443
|
+
c.close(), n(new Error(`${e}.server: error: ${JSON.stringify(a)}`));
|
|
444
|
+
}), c.on("close", () => {
|
|
445
|
+
this.logger.info(`${e}.server: closed ${JSON.stringify(r)}`);
|
|
446
|
+
});
|
|
445
447
|
});
|
|
446
448
|
}
|
|
447
449
|
/**
|
|
@@ -451,7 +453,7 @@ class D {
|
|
|
451
453
|
*/
|
|
452
454
|
static async checkHostAvailability(r) {
|
|
453
455
|
return new Promise((t) => {
|
|
454
|
-
|
|
456
|
+
nt.lookup(r, (e) => {
|
|
455
457
|
t(!e);
|
|
456
458
|
});
|
|
457
459
|
});
|
|
@@ -464,7 +466,7 @@ class D {
|
|
|
464
466
|
static async isPassphraseRequiredForKey(r) {
|
|
465
467
|
return new Promise((t, e) => {
|
|
466
468
|
try {
|
|
467
|
-
return
|
|
469
|
+
return st.utils.parseKey(r) instanceof Error && t(!0), t(!1);
|
|
468
470
|
} catch (i) {
|
|
469
471
|
console.log("Error parsing privateKey"), e(new Error(`ssh.isPassphraseRequiredForKey: err ${i}`));
|
|
470
472
|
}
|
|
@@ -481,10 +483,10 @@ class D {
|
|
|
481
483
|
return await this.withSftp(async (e) => new Promise((i, o) => {
|
|
482
484
|
e.fastPut(r, t, (n) => {
|
|
483
485
|
if (n) {
|
|
484
|
-
const
|
|
486
|
+
const c = new Error(
|
|
485
487
|
`ssh.uploadFile: err: ${n}, localPath: ${r}, remotePath: ${t}`
|
|
486
488
|
);
|
|
487
|
-
return o(
|
|
489
|
+
return o(c);
|
|
488
490
|
}
|
|
489
491
|
i(!0);
|
|
490
492
|
});
|
|
@@ -513,12 +515,12 @@ class D {
|
|
|
513
515
|
}
|
|
514
516
|
async getForderStructure(r, t, e = { files: [], directories: [] }) {
|
|
515
517
|
return new Promise((i, o) => {
|
|
516
|
-
r.readdir(t, async (n,
|
|
518
|
+
r.readdir(t, async (n, c) => {
|
|
517
519
|
if (n)
|
|
518
520
|
return o(n);
|
|
519
|
-
for (const
|
|
520
|
-
const l = `${t}/${
|
|
521
|
-
if (
|
|
521
|
+
for (const a of c) {
|
|
522
|
+
const l = `${t}/${a.filename}`;
|
|
523
|
+
if (a.attrs.isDirectory()) {
|
|
522
524
|
e.directories.push(l);
|
|
523
525
|
try {
|
|
524
526
|
await this.getForderStructure(r, l, e);
|
|
@@ -598,20 +600,20 @@ class D {
|
|
|
598
600
|
}
|
|
599
601
|
async writeFile(r, t, e, i = 432) {
|
|
600
602
|
return new Promise((o, n) => {
|
|
601
|
-
r.writeFile(t, e, { mode: i }, (
|
|
602
|
-
if (
|
|
603
|
-
return n(new Error(`ssh.writeFile: err ${
|
|
603
|
+
r.writeFile(t, e, { mode: i }, (c) => {
|
|
604
|
+
if (c)
|
|
605
|
+
return n(new Error(`ssh.writeFile: err ${c}, remotePath: ${t}`));
|
|
604
606
|
o(!0);
|
|
605
607
|
});
|
|
606
608
|
});
|
|
607
609
|
}
|
|
608
610
|
uploadFileUsingExistingSftp(r, t, e, i = 432) {
|
|
609
611
|
return new Promise((o, n) => {
|
|
610
|
-
|
|
611
|
-
this.writeFile(r, e,
|
|
612
|
+
Q(t).then(async (c) => {
|
|
613
|
+
this.writeFile(r, e, c, i).then(() => {
|
|
612
614
|
o(void 0);
|
|
613
|
-
}).catch((
|
|
614
|
-
const l = `uploadFileUsingExistingSftp: error ${
|
|
615
|
+
}).catch((a) => {
|
|
616
|
+
const l = `uploadFileUsingExistingSftp: error ${a} occurred`;
|
|
615
617
|
this.logger.error(l), n(new Error(l));
|
|
616
618
|
});
|
|
617
619
|
});
|
|
@@ -619,14 +621,14 @@ class D {
|
|
|
619
621
|
}
|
|
620
622
|
async __uploadDirectory(r, t, e, i = 432) {
|
|
621
623
|
return new Promise((o, n) => {
|
|
622
|
-
E.readdir(t, async (
|
|
623
|
-
if (
|
|
624
|
-
return n(new Error(`ssh.__uploadDir: err ${
|
|
624
|
+
E.readdir(t, async (c, a) => {
|
|
625
|
+
if (c)
|
|
626
|
+
return n(new Error(`ssh.__uploadDir: err ${c}, localDir: ${t}, remoteDir: ${e}`));
|
|
625
627
|
try {
|
|
626
628
|
await this.__createRemoteDirectory(r, e);
|
|
627
|
-
for (const l of
|
|
628
|
-
const h = u.join(t, l),
|
|
629
|
-
E.lstatSync(h).isDirectory() ? await this.__uploadDirectory(r, h,
|
|
629
|
+
for (const l of a) {
|
|
630
|
+
const h = u.join(t, l), d = `${e}/${l}`;
|
|
631
|
+
E.lstatSync(h).isDirectory() ? await this.__uploadDirectory(r, h, d, i) : await this.uploadFileUsingExistingSftp(r, h, d, i);
|
|
630
632
|
}
|
|
631
633
|
o();
|
|
632
634
|
} catch (l) {
|
|
@@ -659,18 +661,18 @@ class D {
|
|
|
659
661
|
return new Promise((e, i) => {
|
|
660
662
|
const o = t.split("/");
|
|
661
663
|
let n = "";
|
|
662
|
-
const
|
|
663
|
-
if (
|
|
664
|
+
const c = (a) => {
|
|
665
|
+
if (a >= o.length)
|
|
664
666
|
return e();
|
|
665
|
-
n += `${o[
|
|
667
|
+
n += `${o[a]}/`, r.stat(n, (l) => {
|
|
666
668
|
l ? r.mkdir(n, (h) => {
|
|
667
669
|
if (h)
|
|
668
670
|
return i(new Error(`ssh.__createRemDir: err ${h}, remotePath: ${t}`));
|
|
669
|
-
a
|
|
670
|
-
}) : a
|
|
671
|
+
c(a + 1);
|
|
672
|
+
}) : c(a + 1);
|
|
671
673
|
});
|
|
672
674
|
};
|
|
673
|
-
|
|
675
|
+
c(0);
|
|
674
676
|
});
|
|
675
677
|
}
|
|
676
678
|
/**
|
|
@@ -686,18 +688,18 @@ class D {
|
|
|
686
688
|
for (const n of i) {
|
|
687
689
|
o += `${n}/`;
|
|
688
690
|
try {
|
|
689
|
-
await new Promise((
|
|
691
|
+
await new Promise((c, a) => {
|
|
690
692
|
e.stat(o, (l) => {
|
|
691
|
-
if (!l) return
|
|
693
|
+
if (!l) return c();
|
|
692
694
|
e.mkdir(o, { mode: t }, (h) => {
|
|
693
695
|
if (h)
|
|
694
|
-
return
|
|
695
|
-
|
|
696
|
+
return a(new Error(`ssh.createRemoteDir: err ${h}, remotePath: ${r}`));
|
|
697
|
+
c();
|
|
696
698
|
});
|
|
697
699
|
});
|
|
698
700
|
});
|
|
699
|
-
} catch (
|
|
700
|
-
throw console.error(`Failed to create directory: ${o}`,
|
|
701
|
+
} catch (c) {
|
|
702
|
+
throw console.error(`Failed to create directory: ${o}`, c), c;
|
|
701
703
|
}
|
|
702
704
|
}
|
|
703
705
|
});
|
|
@@ -724,65 +726,80 @@ class D {
|
|
|
724
726
|
this.client.end();
|
|
725
727
|
}
|
|
726
728
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
+
async function At(s, r, t, e) {
|
|
730
|
+
return new Promise((i, o) => {
|
|
731
|
+
s.on("ready", () => {
|
|
732
|
+
i(s);
|
|
733
|
+
}), s.on("error", (n) => {
|
|
734
|
+
o(new Error(`ssh.connect: error occurred: ${n}`));
|
|
735
|
+
}), s.on("close", () => {
|
|
736
|
+
}), s.connect(r);
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
async function xt(s, r, t, e, i, o) {
|
|
740
|
+
return new Promise((n, c) => {
|
|
741
|
+
r.forwardOut(t, e, i, o, (a, l) => a ? (s.error(`forwardOut.error: ${a}`), c(a)) : n(l));
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
const Ot = "minio-2024-12-18T13-15-44Z", kt = "supervisord-0.7.3", Rt = "supervisord_0.7.3_Linux_64-bit";
|
|
745
|
+
function $(s) {
|
|
729
746
|
return u.join(s, "platforma_ssh");
|
|
730
747
|
}
|
|
731
|
-
function
|
|
748
|
+
function v(s) {
|
|
732
749
|
return u.join(s, "platforma_ssh", "binaries");
|
|
733
750
|
}
|
|
734
|
-
function
|
|
735
|
-
return u.join(
|
|
751
|
+
function Nt(s, r) {
|
|
752
|
+
return u.join(v(s), `pl-${b()}-${P(r)}`);
|
|
736
753
|
}
|
|
737
|
-
function
|
|
738
|
-
return u.join(
|
|
754
|
+
function L(s, r) {
|
|
755
|
+
return u.join(Nt(s, r), "binaries");
|
|
739
756
|
}
|
|
740
|
-
function
|
|
741
|
-
return u.join(
|
|
757
|
+
function R(s, r) {
|
|
758
|
+
return u.join(L(s, r), "platforma");
|
|
742
759
|
}
|
|
743
|
-
function
|
|
744
|
-
return u.join(
|
|
760
|
+
function Ut(s, r) {
|
|
761
|
+
return u.join(L(s, r), "free-port");
|
|
745
762
|
}
|
|
746
|
-
function
|
|
747
|
-
return u.join(
|
|
763
|
+
function z(s, r) {
|
|
764
|
+
return u.join(v(s), `minio-2024-12-18T13-15-44Z-${P(r)}`);
|
|
748
765
|
}
|
|
749
|
-
function
|
|
750
|
-
return u.join(
|
|
766
|
+
function Tt(s, r) {
|
|
767
|
+
return u.join(z(s, r), "minio");
|
|
751
768
|
}
|
|
752
|
-
function
|
|
753
|
-
return u.join(
|
|
769
|
+
function Bt(s, r) {
|
|
770
|
+
return u.join(v(s), `supervisord-0.7.3-${P(r)}`, Rt);
|
|
754
771
|
}
|
|
755
|
-
function
|
|
756
|
-
return u.join(
|
|
772
|
+
function W(s, r) {
|
|
773
|
+
return u.join(Bt(s, r), "supervisord");
|
|
757
774
|
}
|
|
758
|
-
function
|
|
759
|
-
return u.join(
|
|
775
|
+
function K(s) {
|
|
776
|
+
return u.join($(s), "supervisor.conf");
|
|
760
777
|
}
|
|
761
|
-
function
|
|
762
|
-
return u.join(
|
|
778
|
+
function N(s) {
|
|
779
|
+
return u.join($(s), "connection.txt");
|
|
763
780
|
}
|
|
764
|
-
async function
|
|
765
|
-
const e = await
|
|
781
|
+
async function _t(s, r, t) {
|
|
782
|
+
const e = await O(s, r, t, "--daemon");
|
|
766
783
|
if (e.stderr)
|
|
767
784
|
throw new Error(`Can not run ssh Platforma ${e.stderr}`);
|
|
768
785
|
}
|
|
769
|
-
async function
|
|
770
|
-
const e = await
|
|
786
|
+
async function jt(s, r, t) {
|
|
787
|
+
const e = await O(s, r, t, "ctl shutdown");
|
|
771
788
|
if (e.stderr)
|
|
772
789
|
throw new Error(`Can not stop ssh Platforma ${e.stderr}`);
|
|
773
790
|
}
|
|
774
|
-
async function
|
|
775
|
-
const i = await
|
|
791
|
+
async function It(s, r, t, e) {
|
|
792
|
+
const i = await O(r, t, e, "ctl status");
|
|
776
793
|
if (i.stderr)
|
|
777
794
|
return s.info(`supervisord ctl status: stderr occurred: ${i.stderr}, stdout: ${i.stdout}`), !1;
|
|
778
795
|
const o = {
|
|
779
|
-
platforma:
|
|
780
|
-
minio:
|
|
796
|
+
platforma: U(i.stdout, "platforma"),
|
|
797
|
+
minio: U(i.stdout, "minio")
|
|
781
798
|
};
|
|
782
799
|
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);
|
|
783
800
|
}
|
|
784
|
-
function
|
|
785
|
-
const
|
|
801
|
+
function Ht(s, r, t, e, i, o, n) {
|
|
802
|
+
const c = Object.entries(r).map(([h, d]) => `${h}="${d}"`).join(","), a = F(16).toString("hex"), l = t;
|
|
786
803
|
return `
|
|
787
804
|
[supervisord]
|
|
788
805
|
logfile=${e}/supervisord.log
|
|
@@ -792,12 +809,12 @@ pidfile=${e}/supervisord.pid
|
|
|
792
809
|
[inet_http_server]
|
|
793
810
|
port=127.0.0.1:${l}
|
|
794
811
|
username=default-user
|
|
795
|
-
password=${
|
|
812
|
+
password=${a}
|
|
796
813
|
|
|
797
814
|
[supervisorctl]
|
|
798
815
|
serverurl=http://127.0.0.1:${l}
|
|
799
816
|
username=default-user
|
|
800
|
-
password=${
|
|
817
|
+
password=${a}
|
|
801
818
|
|
|
802
819
|
[program:platforma]
|
|
803
820
|
autostart=true
|
|
@@ -808,26 +825,26 @@ autorestart=true
|
|
|
808
825
|
|
|
809
826
|
[program:minio]
|
|
810
827
|
autostart=true
|
|
811
|
-
environment=${
|
|
828
|
+
environment=${c}
|
|
812
829
|
command=${o} server ${s}
|
|
813
830
|
directory=${e}
|
|
814
831
|
autorestart=true
|
|
815
832
|
`;
|
|
816
833
|
}
|
|
817
|
-
async function
|
|
818
|
-
const i =
|
|
834
|
+
async function O(s, r, t, e) {
|
|
835
|
+
const i = W(r, t), o = K(r), n = `${i} --configuration ${o} ${e}`;
|
|
819
836
|
return await s.exec(n);
|
|
820
837
|
}
|
|
821
|
-
function
|
|
838
|
+
function U(s, r) {
|
|
822
839
|
return ((i) => i.replace(/\x1B\[[0-9;]*m/g, ""))(s).split(`
|
|
823
840
|
`).some((i) => {
|
|
824
841
|
const [o, n] = i.trim().split(/\s{2,}/);
|
|
825
842
|
return o === r && n === "Running";
|
|
826
843
|
});
|
|
827
844
|
}
|
|
828
|
-
class
|
|
845
|
+
class q {
|
|
829
846
|
constructor(r, t, e) {
|
|
830
|
-
|
|
847
|
+
w(this, "initState", {});
|
|
831
848
|
this.logger = r, this.sshClient = t, this.username = e;
|
|
832
849
|
}
|
|
833
850
|
info() {
|
|
@@ -838,8 +855,8 @@ class W {
|
|
|
838
855
|
}
|
|
839
856
|
static async init(r, t) {
|
|
840
857
|
try {
|
|
841
|
-
const e = await
|
|
842
|
-
return new
|
|
858
|
+
const e = await x.init(r, t);
|
|
859
|
+
return new q(r, e, f(t.username));
|
|
843
860
|
} catch (e) {
|
|
844
861
|
throw r.error(`Connection error in SshClient.init: ${e}`), e;
|
|
845
862
|
}
|
|
@@ -847,7 +864,7 @@ class W {
|
|
|
847
864
|
async isAlive() {
|
|
848
865
|
const r = await this.getArch(), t = await this.getUserHomeDirectory();
|
|
849
866
|
try {
|
|
850
|
-
return await
|
|
867
|
+
return await It(this.logger, this.sshClient, t, r.arch);
|
|
851
868
|
} catch {
|
|
852
869
|
return !1;
|
|
853
870
|
}
|
|
@@ -855,7 +872,7 @@ class W {
|
|
|
855
872
|
async start() {
|
|
856
873
|
const r = await this.getArch(), t = await this.getUserHomeDirectory();
|
|
857
874
|
try {
|
|
858
|
-
return await
|
|
875
|
+
return await _t(this.sshClient, t, r.arch), await this.checkIsAliveWithInterval();
|
|
859
876
|
} catch (e) {
|
|
860
877
|
const i = `ssh.start: error occurred ${e}`;
|
|
861
878
|
throw this.logger.error(i), new Error(i);
|
|
@@ -864,7 +881,7 @@ class W {
|
|
|
864
881
|
async stop() {
|
|
865
882
|
const r = await this.getArch(), t = await this.getUserHomeDirectory();
|
|
866
883
|
try {
|
|
867
|
-
return await
|
|
884
|
+
return await jt(this.sshClient, t, r.arch), await this.checkIsAliveWithInterval(void 0, void 0, !1);
|
|
868
885
|
} catch (e) {
|
|
869
886
|
const i = `ssh.stop: error occurred ${e}`;
|
|
870
887
|
throw this.logger.error(i), new Error(i);
|
|
@@ -872,7 +889,7 @@ class W {
|
|
|
872
889
|
}
|
|
873
890
|
async reset() {
|
|
874
891
|
const r = await this.getUserHomeDirectory();
|
|
875
|
-
return this.logger.info("pl.reset: Stop Platforma on the server"), await this.stop(), this.logger.info(`pl.reset: Deleting Platforma workDir ${r} on the server`), await this.sshClient.deleteFolder(
|
|
892
|
+
return this.logger.info("pl.reset: Stop Platforma on the server"), await this.stop(), this.logger.info(`pl.reset: Deleting Platforma workDir ${r} on the server`), await this.sshClient.deleteFolder($(r)), !0;
|
|
876
893
|
}
|
|
877
894
|
async platformaInit(r) {
|
|
878
895
|
const t = { localWorkdir: r };
|
|
@@ -889,9 +906,9 @@ class W {
|
|
|
889
906
|
);
|
|
890
907
|
if (t.binPaths = { ...e, history: void 0 }, t.downloadedBinaries = e.history, t.ports = await this.fetchPorts(t.remoteHome, t.arch), !t.ports.debug.remote || !t.ports.grpc.remote || !t.ports.minioPort.remote || !t.ports.minioConsolePort.remote || !t.ports.monitoring.remote)
|
|
891
908
|
throw new Error("SshPl.platformaInit: remote ports are not defined");
|
|
892
|
-
const i = await
|
|
909
|
+
const i = await at({
|
|
893
910
|
logger: this.logger,
|
|
894
|
-
workingDir:
|
|
911
|
+
workingDir: $(t.remoteHome),
|
|
895
912
|
portsMode: {
|
|
896
913
|
type: "customWithMinio",
|
|
897
914
|
ports: {
|
|
@@ -909,11 +926,11 @@ class W {
|
|
|
909
926
|
}
|
|
910
927
|
});
|
|
911
928
|
t.generatedConfig = { ...i, filesToCreate: { skipped: "it is too wordy" } };
|
|
912
|
-
for (const [
|
|
913
|
-
await this.sshClient.writeFileOnTheServer(
|
|
914
|
-
for (const
|
|
915
|
-
await this.sshClient.createRemoteDirectory(
|
|
916
|
-
const o =
|
|
929
|
+
for (const [c, a] of Object.entries(i.filesToCreate))
|
|
930
|
+
await this.sshClient.writeFileOnTheServer(c, a), this.logger.info(`Created file ${c}`);
|
|
931
|
+
for (const c of i.dirsToCreate)
|
|
932
|
+
await this.sshClient.createRemoteDirectory(c), this.logger.info(`Created directory ${c}`);
|
|
933
|
+
const o = Ht(
|
|
917
934
|
i.minioConfig.storageDir,
|
|
918
935
|
i.minioConfig.envs,
|
|
919
936
|
await this.getFreePortForPlatformaOnServer(t.remoteHome, t.arch),
|
|
@@ -922,14 +939,14 @@ class W {
|
|
|
922
939
|
t.binPaths.minioRelPath,
|
|
923
940
|
t.binPaths.downloadedPl
|
|
924
941
|
);
|
|
925
|
-
if (!await this.sshClient.writeFileOnTheServer(
|
|
926
|
-
throw new Error(`Can not write supervisord config on the server ${
|
|
942
|
+
if (!await this.sshClient.writeFileOnTheServer(K(t.remoteHome), o))
|
|
943
|
+
throw new Error(`Can not write supervisord config on the server ${$(t.remoteHome)}`);
|
|
927
944
|
return t.connectionInfo = {
|
|
928
945
|
plUser: i.plUser,
|
|
929
946
|
plPassword: i.plPassword,
|
|
930
947
|
ports: t.ports
|
|
931
948
|
}, await this.sshClient.writeFileOnTheServer(
|
|
932
|
-
|
|
949
|
+
N(t.remoteHome),
|
|
933
950
|
JSON.stringify(t.connectionInfo, void 0, 2)
|
|
934
951
|
), await this.start(), t.started = !0, this.initState = t, {
|
|
935
952
|
plUser: i.plUser,
|
|
@@ -949,7 +966,7 @@ class W {
|
|
|
949
966
|
t,
|
|
950
967
|
e,
|
|
951
968
|
"pl",
|
|
952
|
-
`pl-${
|
|
969
|
+
`pl-${b()}`
|
|
953
970
|
);
|
|
954
971
|
i.push(o);
|
|
955
972
|
const n = await this.downloadAndUntar(
|
|
@@ -957,20 +974,20 @@ class W {
|
|
|
957
974
|
t,
|
|
958
975
|
e,
|
|
959
976
|
"supervisord",
|
|
960
|
-
|
|
977
|
+
kt
|
|
961
978
|
);
|
|
962
979
|
i.push(n);
|
|
963
|
-
const
|
|
980
|
+
const c = Tt(t, e.arch), a = await this.downloadAndUntar(
|
|
964
981
|
r,
|
|
965
982
|
t,
|
|
966
983
|
e,
|
|
967
984
|
"minio",
|
|
968
|
-
|
|
985
|
+
Ot
|
|
969
986
|
);
|
|
970
|
-
return i.push(
|
|
987
|
+
return i.push(a), await this.sshClient.chmod(c, 488), {
|
|
971
988
|
history: i,
|
|
972
|
-
minioRelPath:
|
|
973
|
-
downloadedPl:
|
|
989
|
+
minioRelPath: c,
|
|
990
|
+
downloadedPl: R(t, e.arch)
|
|
974
991
|
};
|
|
975
992
|
} catch (o) {
|
|
976
993
|
const n = `SshPl.downloadBinariesAndUploadToServer: error ${o} occurred, state: ${JSON.stringify(i)}`;
|
|
@@ -983,12 +1000,12 @@ class W {
|
|
|
983
1000
|
* For this reason, we extract all to the remote server. */
|
|
984
1001
|
async downloadAndUntar(r, t, e, i, o) {
|
|
985
1002
|
const n = {};
|
|
986
|
-
n.binBasePath =
|
|
987
|
-
let
|
|
988
|
-
const
|
|
989
|
-
for (let h = 1; h <=
|
|
1003
|
+
n.binBasePath = v(t), await this.sshClient.createRemoteDirectory(n.binBasePath), n.binBasePathCreated = !0;
|
|
1004
|
+
let c = null;
|
|
1005
|
+
const a = 5;
|
|
1006
|
+
for (let h = 1; h <= a; h++)
|
|
990
1007
|
try {
|
|
991
|
-
|
|
1008
|
+
c = await ut(
|
|
992
1009
|
this.logger,
|
|
993
1010
|
r,
|
|
994
1011
|
i,
|
|
@@ -997,11 +1014,11 @@ class W {
|
|
|
997
1014
|
e.platform
|
|
998
1015
|
);
|
|
999
1016
|
break;
|
|
1000
|
-
} catch (
|
|
1001
|
-
if (await
|
|
1002
|
-
throw new Error(`downloadAndUntar: ${
|
|
1017
|
+
} catch (d) {
|
|
1018
|
+
if (await C(300), h == a)
|
|
1019
|
+
throw new Error(`downloadAndUntar: ${a} attempts, last error: ${d}`);
|
|
1003
1020
|
}
|
|
1004
|
-
n.downloadResult =
|
|
1021
|
+
n.downloadResult = f(c), n.localArchivePath = u.resolve(n.downloadResult.archivePath), n.remoteDir = u.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);
|
|
1005
1022
|
const l = await this.sshClient.exec(
|
|
1006
1023
|
`tar xvf ${n.remoteArchivePath} --directory=${n.remoteDir}`
|
|
1007
1024
|
);
|
|
@@ -1010,49 +1027,49 @@ class W {
|
|
|
1010
1027
|
return n.plUntarDone = !0, n;
|
|
1011
1028
|
}
|
|
1012
1029
|
async needDownload(r, t) {
|
|
1013
|
-
const e =
|
|
1030
|
+
const e = W(r, t.arch), i = z(r, t.arch), o = R(r, t.arch);
|
|
1014
1031
|
return !await this.sshClient.checkFileExists(o) || !await this.sshClient.checkFileExists(i) || !await this.sshClient.checkFileExists(e);
|
|
1015
1032
|
}
|
|
1016
1033
|
async checkIsAliveWithInterval(r = 1e3, t = 15, e = !0) {
|
|
1017
1034
|
const i = t * r;
|
|
1018
1035
|
let o = 0, n = await this.isAlive();
|
|
1019
1036
|
for (; e ? !n : n; ) {
|
|
1020
|
-
if (await
|
|
1037
|
+
if (await C(r), o += r, o > i)
|
|
1021
1038
|
throw new Error(`isAliveWithInterval: The process did not ${e ? "started" : "stopped"} after ${i} ms.`);
|
|
1022
1039
|
n = await this.isAlive();
|
|
1023
1040
|
}
|
|
1024
1041
|
}
|
|
1025
1042
|
async getUserCredentials(r) {
|
|
1026
|
-
const t = await this.sshClient.readFile(
|
|
1043
|
+
const t = await this.sshClient.readFile(N(r));
|
|
1027
1044
|
return JSON.parse(t);
|
|
1028
1045
|
}
|
|
1029
1046
|
async fetchPorts(r, t) {
|
|
1030
1047
|
return {
|
|
1031
1048
|
grpc: {
|
|
1032
|
-
local: await
|
|
1049
|
+
local: await y(),
|
|
1033
1050
|
remote: await this.getFreePortForPlatformaOnServer(r, t)
|
|
1034
1051
|
},
|
|
1035
1052
|
monitoring: {
|
|
1036
|
-
local: await
|
|
1053
|
+
local: await y(),
|
|
1037
1054
|
remote: await this.getFreePortForPlatformaOnServer(r, t)
|
|
1038
1055
|
},
|
|
1039
1056
|
debug: {
|
|
1040
|
-
local: await
|
|
1057
|
+
local: await y(),
|
|
1041
1058
|
remote: await this.getFreePortForPlatformaOnServer(r, t)
|
|
1042
1059
|
},
|
|
1043
1060
|
minioPort: {
|
|
1044
|
-
local: await
|
|
1061
|
+
local: await y(),
|
|
1045
1062
|
remote: await this.getFreePortForPlatformaOnServer(r, t)
|
|
1046
1063
|
},
|
|
1047
1064
|
minioConsolePort: {
|
|
1048
|
-
local: await
|
|
1065
|
+
local: await y(),
|
|
1049
1066
|
remote: await this.getFreePortForPlatformaOnServer(r, t)
|
|
1050
1067
|
}
|
|
1051
1068
|
};
|
|
1052
1069
|
}
|
|
1053
1070
|
async getLocalFreePort() {
|
|
1054
1071
|
return new Promise((r) => {
|
|
1055
|
-
const t =
|
|
1072
|
+
const t = B.createServer();
|
|
1056
1073
|
t.listen(0, () => {
|
|
1057
1074
|
const e = t.address().port;
|
|
1058
1075
|
t.close((i) => r(e));
|
|
@@ -1060,7 +1077,7 @@ class W {
|
|
|
1060
1077
|
});
|
|
1061
1078
|
}
|
|
1062
1079
|
async getFreePortForPlatformaOnServer(r, t) {
|
|
1063
|
-
const e =
|
|
1080
|
+
const e = Ut(r, t.arch), { stdout: i, stderr: o } = await this.sshClient.exec(`${e}`);
|
|
1064
1081
|
if (o)
|
|
1065
1082
|
throw new Error(`getFreePortForPlatformaOnServer: stderr is not empty: ${o}, stdout: ${i}`);
|
|
1066
1083
|
return +i;
|
|
@@ -1086,11 +1103,11 @@ class W {
|
|
|
1086
1103
|
}
|
|
1087
1104
|
}
|
|
1088
1105
|
export {
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1106
|
+
Et as LocalConfigYaml,
|
|
1107
|
+
Ft as LocalPl,
|
|
1108
|
+
x as SshClient,
|
|
1109
|
+
q as SshPl,
|
|
1110
|
+
b as getDefaultPlVersion,
|
|
1111
|
+
ir as localPlatformaInit
|
|
1095
1112
|
};
|
|
1096
1113
|
//# sourceMappingURL=index.mjs.map
|