@platforma-sdk/bootstrap 2.1.0 → 2.1.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 +16 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -120
- package/dist/index.mjs.map +1 -1
- package/dist/util.d.ts +4 -1
- package/dist/util.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,8 @@ var er = Object.defineProperty;
|
|
|
2
2
|
var rr = (a, e, r) => e in a ? er(a, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : a[e] = r;
|
|
3
3
|
var m = (a, e, r) => rr(a, typeof e != "symbol" ? e + "" : e, r);
|
|
4
4
|
import { Flags as y, Command as O } from "@oclif/core";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import _ from "node:os";
|
|
6
|
+
import l, { createWriteStream as tr } from "node:fs";
|
|
7
7
|
import f, { resolve as ar } from "node:path";
|
|
8
8
|
import { execSync as Me, spawn as ir, spawnSync as H } from "node:child_process";
|
|
9
9
|
import j from "winston";
|
|
@@ -14,7 +14,7 @@ import { z as K } from "zod";
|
|
|
14
14
|
import nr from "decompress";
|
|
15
15
|
import Ce from "yaml";
|
|
16
16
|
import lr from "node:https";
|
|
17
|
-
import * as
|
|
17
|
+
import * as dr from "tar";
|
|
18
18
|
const T = {
|
|
19
19
|
"log-level": y.string({
|
|
20
20
|
description: "logging level",
|
|
@@ -63,7 +63,7 @@ const T = {
|
|
|
63
63
|
description: "full listen addr for Platforma Backend debug API. Default is 127.0.0.1:9091",
|
|
64
64
|
env: "PLATFORMA_DEBUG_LISTEN"
|
|
65
65
|
})
|
|
66
|
-
},
|
|
66
|
+
}, or = {
|
|
67
67
|
"s3-address-port": y.integer({
|
|
68
68
|
description: "port that S3 will listen, default is 9000",
|
|
69
69
|
default: 9e3,
|
|
@@ -177,14 +177,14 @@ function yr(a) {
|
|
|
177
177
|
return sr(Math.ceil(a / 2)).toString("hex").slice(0, a);
|
|
178
178
|
}
|
|
179
179
|
function Pr(a) {
|
|
180
|
-
return a.startsWith("~") ? f.join(
|
|
180
|
+
return a.startsWith("~") ? f.join(_.homedir(), a.slice(1)) : a;
|
|
181
181
|
}
|
|
182
|
-
function q(a) {
|
|
183
|
-
|
|
182
|
+
function q(a, e) {
|
|
183
|
+
l.existsSync(a) || (l.mkdirSync(a, { recursive: !0 }), e != null && e.mode && l.chmodSync(a, e.mode));
|
|
184
184
|
}
|
|
185
185
|
function br(a) {
|
|
186
186
|
try {
|
|
187
|
-
if (
|
|
187
|
+
if (_.platform() !== "win32")
|
|
188
188
|
return Me(`ps -p ${a} -o comm=`, { encoding: "utf8" }).trim();
|
|
189
189
|
const e = `wmic process where processid=${a} get Caption`, r = Me(e, { encoding: "utf8" }).split(`
|
|
190
190
|
`);
|
|
@@ -217,23 +217,23 @@ function kr() {
|
|
|
217
217
|
return vr.parse({ npmOrgName: a, orgName: e, blockName: r });
|
|
218
218
|
}
|
|
219
219
|
async function Sr(a, e, r) {
|
|
220
|
-
const i = await (await fetch(a)).blob(), s =
|
|
220
|
+
const i = await (await fetch(a)).blob(), s = l.mkdtempSync(f.join(_.tmpdir(), "create-repo")), c = f.join(s, "packed-repo.zip"), n = cr.toWeb(tr(c));
|
|
221
221
|
await i.stream().pipeTo(n);
|
|
222
222
|
const h = f.join(s, "unpacked-repo");
|
|
223
|
-
|
|
223
|
+
l.mkdirSync(h), await nr(c, h), l.cpSync(f.join(h, e), r, { recursive: !0 });
|
|
224
224
|
}
|
|
225
225
|
function Ar(a, e, r) {
|
|
226
226
|
Lr(a).forEach((t) => Rr(t, e, r));
|
|
227
227
|
}
|
|
228
228
|
function Lr(a) {
|
|
229
|
-
return
|
|
229
|
+
return l.readdirSync(a, {
|
|
230
230
|
withFileTypes: !0,
|
|
231
231
|
recursive: !0
|
|
232
232
|
}).filter((r) => r.isFile()).map((r) => f.join(r.parentPath, r.name));
|
|
233
233
|
}
|
|
234
234
|
function Rr(a, e, r) {
|
|
235
|
-
const i =
|
|
236
|
-
|
|
235
|
+
const i = l.readFileSync(a).toString().replaceAll(e, r);
|
|
236
|
+
l.writeFileSync(a, i);
|
|
237
237
|
}
|
|
238
238
|
const I = class I extends O {
|
|
239
239
|
async run() {
|
|
@@ -251,11 +251,11 @@ function ze(...a) {
|
|
|
251
251
|
function $(...a) {
|
|
252
252
|
return ze("assets", ...a);
|
|
253
253
|
}
|
|
254
|
-
function
|
|
255
|
-
return
|
|
254
|
+
function _r() {
|
|
255
|
+
return l.readdirSync($()).filter((e) => e.startsWith("compose-") && e.endsWith(".yaml")).map((e) => $(e));
|
|
256
256
|
}
|
|
257
257
|
function Ke(...a) {
|
|
258
|
-
return
|
|
258
|
+
return l.readFileSync(ze(...a));
|
|
259
259
|
}
|
|
260
260
|
var ae;
|
|
261
261
|
function te() {
|
|
@@ -272,9 +272,9 @@ const F = class F {
|
|
|
272
272
|
});
|
|
273
273
|
m(this, "filePath");
|
|
274
274
|
m(this, "dirPath");
|
|
275
|
-
e = e ?? f.resolve(
|
|
275
|
+
e = e ?? f.resolve(_.homedir(), ".config", "pl-bootstrap");
|
|
276
276
|
const r = f.join(e, "state.json");
|
|
277
|
-
this.dirPath = e, this.filePath = r,
|
|
277
|
+
this.dirPath = e, this.filePath = r, l.existsSync(e) || l.mkdirSync(e, { recursive: !0 }), l.existsSync(r) && (this.state = JSON.parse(Ke(r).toString()));
|
|
278
278
|
}
|
|
279
279
|
static getInstance() {
|
|
280
280
|
return F.instance || (F.instance = new F()), F.instance;
|
|
@@ -289,7 +289,7 @@ const F = class F {
|
|
|
289
289
|
return this.path("binaries", ...e);
|
|
290
290
|
}
|
|
291
291
|
writeState() {
|
|
292
|
-
|
|
292
|
+
l.writeFileSync(this.filePath, JSON.stringify(this.state));
|
|
293
293
|
}
|
|
294
294
|
get isActive() {
|
|
295
295
|
var e, r;
|
|
@@ -314,53 +314,53 @@ const F = class F {
|
|
|
314
314
|
};
|
|
315
315
|
m(F, "instance");
|
|
316
316
|
let ce = F;
|
|
317
|
-
const
|
|
317
|
+
const d = ce.getInstance();
|
|
318
318
|
function Be(a, e, r, t) {
|
|
319
319
|
var i;
|
|
320
|
-
return
|
|
321
|
-
...
|
|
320
|
+
return d.lastRun = {
|
|
321
|
+
...d.lastRun,
|
|
322
322
|
mode: "docker",
|
|
323
323
|
cmd: "docker",
|
|
324
324
|
args: e,
|
|
325
325
|
workdir: r.cwd,
|
|
326
326
|
envs: r.env,
|
|
327
327
|
docker: {
|
|
328
|
-
...(i =
|
|
328
|
+
...(i = d.lastRun) == null ? void 0 : i.docker,
|
|
329
329
|
...t
|
|
330
330
|
}
|
|
331
331
|
}, qe(a, "docker", e, r);
|
|
332
332
|
}
|
|
333
|
-
function
|
|
333
|
+
function pr(a, e, r, t, i) {
|
|
334
334
|
var c;
|
|
335
|
-
|
|
336
|
-
...
|
|
335
|
+
d.lastRun = {
|
|
336
|
+
...d.lastRun,
|
|
337
337
|
mode: "process",
|
|
338
338
|
cmd: e,
|
|
339
339
|
args: r,
|
|
340
340
|
workdir: t.cwd,
|
|
341
341
|
envs: t.env,
|
|
342
342
|
process: {
|
|
343
|
-
...(c =
|
|
343
|
+
...(c = d.lastRun) == null ? void 0 : c.process,
|
|
344
344
|
...i
|
|
345
345
|
}
|
|
346
346
|
};
|
|
347
347
|
const s = Or(a, e, r, t);
|
|
348
|
-
return
|
|
349
|
-
...
|
|
348
|
+
return d.lastRun.process = {
|
|
349
|
+
...d.lastRun.process,
|
|
350
350
|
pid: s.pid
|
|
351
351
|
}, s;
|
|
352
352
|
}
|
|
353
353
|
function $r(a, e) {
|
|
354
|
-
if (!
|
|
354
|
+
if (!d.lastRun)
|
|
355
355
|
throw new Error("no previous run info found: this is the first run after package installation");
|
|
356
356
|
return e = {
|
|
357
|
-
cwd:
|
|
357
|
+
cwd: d.lastRun.workdir,
|
|
358
358
|
env: {
|
|
359
|
-
...
|
|
359
|
+
...d.lastRun.envs,
|
|
360
360
|
...e.env
|
|
361
361
|
},
|
|
362
362
|
...e
|
|
363
|
-
}, qe(a,
|
|
363
|
+
}, qe(a, d.lastRun.cmd, d.lastRun.args, e);
|
|
364
364
|
}
|
|
365
365
|
function Or(a, e, r, t) {
|
|
366
366
|
a.debug(
|
|
@@ -458,15 +458,15 @@ function N(a, e, r) {
|
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
460
|
function Er(a, e) {
|
|
461
|
-
var
|
|
462
|
-
const r = (e == null ? void 0 : e.localRoot) ??
|
|
463
|
-
level: ((
|
|
461
|
+
var o, b, w, S, L, k, p, W, A, ye, Pe, be, ve, we, ke, Se, Ae, Le, Re, _e, pe, $e, Oe, Te, Ee, Fe, De, Ne, Ie, xe;
|
|
462
|
+
const r = (e == null ? void 0 : e.localRoot) ?? d.data("local-custom"), t = {
|
|
463
|
+
level: ((o = e == null ? void 0 : e.log) == null ? void 0 : o.level) ?? "info",
|
|
464
464
|
path: ((b = e == null ? void 0 : e.log) == null ? void 0 : b.path) ?? `${r}/platforma.log`
|
|
465
465
|
}, i = {
|
|
466
466
|
listen: ((w = e == null ? void 0 : e.grpc) == null ? void 0 : w.listen) ?? "localhost:6345",
|
|
467
467
|
tls: {
|
|
468
468
|
enable: z((L = (S = e == null ? void 0 : e.grpc) == null ? void 0 : S.tls) == null ? void 0 : L.enable, !1),
|
|
469
|
-
clientAuthMode: ((
|
|
469
|
+
clientAuthMode: ((p = (k = e == null ? void 0 : e.grpc) == null ? void 0 : k.tls) == null ? void 0 : p.clientAuthMode) ?? "NoAuth",
|
|
470
470
|
certFile: ((A = (W = e == null ? void 0 : e.grpc) == null ? void 0 : W.tls) == null ? void 0 : A.certFile) ?? `${r}/certs/tls.cert`,
|
|
471
471
|
keyFile: ((Pe = (ye = e == null ? void 0 : e.grpc) == null ? void 0 : ye.tls) == null ? void 0 : Pe.keyFile) ?? `${r}/certs/tls.key`,
|
|
472
472
|
...(be = e == null ? void 0 : e.grpc) == null ? void 0 : be.tls
|
|
@@ -492,7 +492,7 @@ function Er(a, e) {
|
|
|
492
492
|
switch ((Re = (Le = e == null ? void 0 : e.storages) == null ? void 0 : Le.work) == null ? void 0 : Re.type) {
|
|
493
493
|
case void 0:
|
|
494
494
|
case "FS":
|
|
495
|
-
n = Ve("work"), n.rootPath = ((
|
|
495
|
+
n = Ve("work"), n.rootPath = ((pe = (_e = e == null ? void 0 : e.storages) == null ? void 0 : _e.work) == null ? void 0 : pe.rootPath) ?? `${r}/storages/work`, n.indexCachePeriod = ((Oe = ($e = e == null ? void 0 : e.storages) == null ? void 0 : $e.work) == null ? void 0 : Oe.indexCachePeriod) ?? "1m";
|
|
496
496
|
break;
|
|
497
497
|
default:
|
|
498
498
|
throw new Error("work storage MUST have 'FS' type as it is used for working directories management");
|
|
@@ -542,7 +542,7 @@ function Ge(a, e, r, t) {
|
|
|
542
542
|
function Fr(a) {
|
|
543
543
|
const e = a.monitoring.enabled ? "" : " disabled", r = a.debug.enabled ? "" : " disabled", t = a.hacks.libraryDownloadable ? "true" : "false";
|
|
544
544
|
var i = a.license.value;
|
|
545
|
-
return a.license.file != "" && (i =
|
|
545
|
+
return a.license.file != "" && (i = l.readFileSync(a.license.file).toString().trimEnd()), `
|
|
546
546
|
license:
|
|
547
547
|
value: '${a.license.value}'
|
|
548
548
|
file: '${a.license.file}'
|
|
@@ -618,7 +618,7 @@ function z(a, e) {
|
|
|
618
618
|
}
|
|
619
619
|
const Dr = ["linux", "macos", "windows"];
|
|
620
620
|
function Nr(a) {
|
|
621
|
-
const e =
|
|
621
|
+
const e = _.platform();
|
|
622
622
|
switch (e) {
|
|
623
623
|
case "darwin":
|
|
624
624
|
return "macos";
|
|
@@ -634,7 +634,7 @@ function Nr(a) {
|
|
|
634
634
|
}
|
|
635
635
|
const Ir = ["amd64", "arm64"];
|
|
636
636
|
function Qe(a) {
|
|
637
|
-
const e =
|
|
637
|
+
const e = _.arch();
|
|
638
638
|
switch (e) {
|
|
639
639
|
case "arm64":
|
|
640
640
|
return "arm64";
|
|
@@ -647,10 +647,10 @@ function Qe(a) {
|
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
649
|
function xr(a, e) {
|
|
650
|
-
const r = (e == null ? void 0 : e.version) ?? te()["pl-version"], t = (e == null ? void 0 : e.showProgress) ?? process.stdout.isTTY, i = `pl-${r}-${Qe()}.tgz`, s = (e == null ? void 0 : e.downloadURL) ?? `https://cdn.platforma.bio/software/pl/${Nr()}/${i}`, c = (e == null ? void 0 : e.saveTo) ??
|
|
651
|
-
if (
|
|
650
|
+
const r = (e == null ? void 0 : e.version) ?? te()["pl-version"], t = (e == null ? void 0 : e.showProgress) ?? process.stdout.isTTY, i = `pl-${r}-${Qe()}.tgz`, s = (e == null ? void 0 : e.downloadURL) ?? `https://cdn.platforma.bio/software/pl/${Nr()}/${i}`, c = (e == null ? void 0 : e.saveTo) ?? d.binaries(i);
|
|
651
|
+
if (l.existsSync(c))
|
|
652
652
|
return a.info(`Platforma Backend archive download skipped: '${c}' already exists`), Promise.resolve(c);
|
|
653
|
-
|
|
653
|
+
l.mkdirSync(f.dirname(c), { recursive: !0 }), a.info(`Downloading Platforma Backend archive:
|
|
654
654
|
URL: ${s}
|
|
655
655
|
Save to: ${c}`);
|
|
656
656
|
const n = lr.get(s);
|
|
@@ -668,15 +668,15 @@ function xr(a, e) {
|
|
|
668
668
|
}
|
|
669
669
|
const v = parseInt(g.headers["content-length"] || "0", 10);
|
|
670
670
|
let P = 0;
|
|
671
|
-
const
|
|
672
|
-
g.pipe(
|
|
671
|
+
const o = l.createWriteStream(c);
|
|
672
|
+
g.pipe(o), g.on("data", (b) => {
|
|
673
673
|
P += b.length;
|
|
674
674
|
const w = P / v * 100;
|
|
675
675
|
t && process.stdout.write(` downloading: ${w.toFixed(2)}%\r`);
|
|
676
676
|
}), g.on("error", (b) => {
|
|
677
|
-
|
|
678
|
-
}),
|
|
679
|
-
|
|
677
|
+
l.unlinkSync(c), a.error(`Failed to download Platforma Binary: ${b.message}`), n.destroy(), u(b);
|
|
678
|
+
}), o.on("finish", () => {
|
|
679
|
+
o.close(), a.info(" ... download done."), n.destroy(), h(c);
|
|
680
680
|
});
|
|
681
681
|
});
|
|
682
682
|
});
|
|
@@ -685,18 +685,18 @@ function Mr(a, e) {
|
|
|
685
685
|
a.debug("extracting archive...");
|
|
686
686
|
const r = (e == null ? void 0 : e.version) ?? te()["pl-version"];
|
|
687
687
|
a.debug(` version: '${r}'`);
|
|
688
|
-
const t = `${Ze({ version: r })}.tgz`, i = (e == null ? void 0 : e.archivePath) ??
|
|
688
|
+
const t = `${Ze({ version: r })}.tgz`, i = (e == null ? void 0 : e.archivePath) ?? d.binaries(t);
|
|
689
689
|
a.debug(` archive path: '${i}'`);
|
|
690
690
|
const s = (e == null ? void 0 : e.extractTo) ?? Br(i);
|
|
691
|
-
if (a.debug(` target dir: '${s}'`),
|
|
691
|
+
if (a.debug(` target dir: '${s}'`), l.existsSync(s))
|
|
692
692
|
return a.info(`Platforma Backend binaries unpack skipped: '${s}' exists`), s;
|
|
693
|
-
if (!
|
|
693
|
+
if (!l.existsSync(i)) {
|
|
694
694
|
const c = `Platforma Backend binary archive not found at '${i}'`;
|
|
695
695
|
throw a.error(c), new Error(c);
|
|
696
696
|
}
|
|
697
|
-
return
|
|
697
|
+
return l.existsSync(s) || (a.debug(` creating target dir '${s}'`), l.mkdirSync(s, { recursive: !0 })), a.info(`Unpacking Platforma Backend archive:
|
|
698
698
|
Archive: ${i}
|
|
699
|
-
Target dir: ${s}`),
|
|
699
|
+
Target dir: ${s}`), dr.x({
|
|
700
700
|
file: i,
|
|
701
701
|
cwd: s,
|
|
702
702
|
gzip: !0,
|
|
@@ -710,7 +710,7 @@ function Ze(a) {
|
|
|
710
710
|
return `pl-${(a == null ? void 0 : a.version) ?? te()["pl-version"]}-${Qe()}`;
|
|
711
711
|
}
|
|
712
712
|
function Cr(a, ...e) {
|
|
713
|
-
return
|
|
713
|
+
return d.binaries(Ze({ version: a }), ...e);
|
|
714
714
|
}
|
|
715
715
|
function Br(a) {
|
|
716
716
|
const e = a.lastIndexOf(".");
|
|
@@ -725,10 +725,10 @@ class D {
|
|
|
725
725
|
J(e, "failed to bring back Platforma Backend in the last started configuration");
|
|
726
726
|
}
|
|
727
727
|
startLocal(e) {
|
|
728
|
-
var h, u, g, v, P,
|
|
728
|
+
var h, u, g, v, P, o, b, w, S, L;
|
|
729
729
|
const r = (e == null ? void 0 : e.binaryPath) ?? Cr(e == null ? void 0 : e.version, "binaries", "platforma");
|
|
730
730
|
var t = e == null ? void 0 : e.configPath;
|
|
731
|
-
const i = (e == null ? void 0 : e.workdir) ?? (t ? process.cwd() :
|
|
731
|
+
const i = (e == null ? void 0 : e.workdir) ?? (t ? process.cwd() : d.path());
|
|
732
732
|
e != null && e.primaryURL && (e.configOptions = {
|
|
733
733
|
...e.configOptions,
|
|
734
734
|
storages: {
|
|
@@ -739,7 +739,7 @@ class D {
|
|
|
739
739
|
...e.configOptions,
|
|
740
740
|
storages: {
|
|
741
741
|
...(v = e.configOptions) == null ? void 0 : v.storages,
|
|
742
|
-
library: N(e.libraryURL, i, (
|
|
742
|
+
library: N(e.libraryURL, i, (o = (P = e.configOptions) == null ? void 0 : P.storages) == null ? void 0 : o.library)
|
|
743
743
|
}
|
|
744
744
|
});
|
|
745
745
|
const s = Er(this.getLastJwt(), e == null ? void 0 : e.configOptions);
|
|
@@ -751,10 +751,10 @@ class D {
|
|
|
751
751
|
];
|
|
752
752
|
s.storages.primary.type === "FS" && c.push(s.storages.primary.rootPath), s.storages.library.type === "FS" && (c.push(s.storages.library.rootPath), s.hacks.libraryDownloadable = !1), s.storages.work.type === "FS" && c.push(s.storages.work.rootPath), this.logger.debug(" creating pl state directories...");
|
|
753
753
|
for (const k of c)
|
|
754
|
-
|
|
754
|
+
l.existsSync(k) || (this.logger.debug(` '${k}'`), l.mkdirSync(k, { recursive: !0 }));
|
|
755
755
|
for (const k of s.core.auth.drivers)
|
|
756
|
-
k.driver === "htpasswd" && (
|
|
757
|
-
t || (t = f.join(s.localRoot, "config.yaml"), this.logger.debug(` rendering configuration '${t}'...`),
|
|
756
|
+
k.driver === "htpasswd" && (l.existsSync(k.path) || (this.logger.debug(` installing default 'users.htpasswd' to ${k.path}...`), l.copyFileSync($("users.htpasswd"), k.path)));
|
|
757
|
+
t || (t = f.join(s.localRoot, "config.yaml"), this.logger.debug(` rendering configuration '${t}'...`), l.writeFileSync(t, Fr(s)));
|
|
758
758
|
const n = this.renderRunInfo({
|
|
759
759
|
configPath: t,
|
|
760
760
|
dbPath: s.core.db.path,
|
|
@@ -765,7 +765,7 @@ class D {
|
|
|
765
765
|
library: s.storages.library
|
|
766
766
|
});
|
|
767
767
|
return this.logger.info(`Starting platforma:
|
|
768
|
-
${n}`),
|
|
768
|
+
${n}`), pr(
|
|
769
769
|
this.logger,
|
|
770
770
|
r,
|
|
771
771
|
["-config", t],
|
|
@@ -799,9 +799,9 @@ ${n}`), _r(
|
|
|
799
799
|
this.logger.debug(` minio version: ${t}`);
|
|
800
800
|
const i = (e == null ? void 0 : e.image) ?? `quay.io/minio/minio${t}`;
|
|
801
801
|
this.logger.debug(` minio image: ${i}`);
|
|
802
|
-
const s = (e == null ? void 0 : e.storage) ??
|
|
803
|
-
q(s);
|
|
804
|
-
const c =
|
|
802
|
+
const s = (e == null ? void 0 : e.storage) ?? d.data("minio");
|
|
803
|
+
q(s, { mode: "0775" });
|
|
804
|
+
const c = d.data("stub");
|
|
805
805
|
q(c);
|
|
806
806
|
const n = (e == null ? void 0 : e.minioPort) ?? 9e3, h = (e == null ? void 0 : e.minioConsolePort) ?? 9001, u = {
|
|
807
807
|
MINIO_IMAGE: i,
|
|
@@ -830,7 +830,7 @@ ${n}`), _r(
|
|
|
830
830
|
J(g, "failed to start MinIO service in docker");
|
|
831
831
|
}
|
|
832
832
|
buildPlatforma(e) {
|
|
833
|
-
const r = f.resolve(e.repoRoot, "cmd", "platforma"), t = e.binPath ?? f.join(
|
|
833
|
+
const r = f.resolve(e.repoRoot, "cmd", "platforma"), t = e.binPath ?? f.join(_.tmpdir(), "platforma-local-build");
|
|
834
834
|
this.logger.info("Building Platforma Backend binary from sources"), this.logger.info(` sources path: ${e.repoRoot}`), this.logger.info(` binary path: ${t}`);
|
|
835
835
|
const i = H("go", ["build", "-o", t, "."], {
|
|
836
836
|
cwd: r,
|
|
@@ -843,9 +843,9 @@ ${n}`), _r(
|
|
|
843
843
|
this.checkLicense(r == null ? void 0 : r.license, r == null ? void 0 : r.licenseFile);
|
|
844
844
|
const s = (S) => f.join(e, S), c = (S) => {
|
|
845
845
|
const L = s(S);
|
|
846
|
-
return q(L), L;
|
|
846
|
+
return q(L, { mode: "0775" }), L;
|
|
847
847
|
}, n = s("platforma.log");
|
|
848
|
-
|
|
848
|
+
l.existsSync(n) || (l.mkdirSync(f.dirname(n), { recursive: !0 }), l.writeFileSync(n, ""));
|
|
849
849
|
const h = N("s3e://testuser:testpassword@minio:9000/main-bucket");
|
|
850
850
|
if (h.type !== "S3")
|
|
851
851
|
throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");
|
|
@@ -855,8 +855,8 @@ ${n}`), _r(
|
|
|
855
855
|
throw new Error(`${u.type} storage type is not supported for library storage`);
|
|
856
856
|
u.presignEndpoint = "http://localhost:9000";
|
|
857
857
|
const g = c("db"), v = c("work"), P = s("users.htpasswd");
|
|
858
|
-
|
|
859
|
-
const
|
|
858
|
+
l.existsSync(P) || l.copyFileSync($("users.htpasswd"), P);
|
|
859
|
+
const o = {
|
|
860
860
|
MINIO_IMAGE: "quay.io/minio/minio",
|
|
861
861
|
MINIO_STORAGE: c("minio"),
|
|
862
862
|
PL_IMAGE: i,
|
|
@@ -873,10 +873,10 @@ ${n}`), _r(
|
|
|
873
873
|
...this.configureDockerStorage("primary", h),
|
|
874
874
|
...this.configureDockerStorage("library", u)
|
|
875
875
|
};
|
|
876
|
-
if (r != null && r.grpcAddr && (
|
|
876
|
+
if (r != null && r.grpcAddr && (o.PL_GRPC_ADDR = r.grpcAddr), r != null && r.grpcPort && (o.PL_GRPC_PORT = r.grpcPort.toString()), r != null && r.monitoringAddr && (o.PL_MONITORING_ADDR = r.monitoringAddr), r != null && r.monitoringPort && (o.PL_MONITORING_PORT = r.monitoringPort.toString()), r != null && r.debugAddr && (o.PL_DEBUG_ADDR = r.debugAddr), r != null && r.debugPort && (o.PL_DEBUG_PORT = r.debugPort.toString()), r != null && r.auth && (r.auth.enabled && (o.PL_AUTH_ENABLED = "true"), r.auth.drivers)) {
|
|
877
877
|
for (const S of r.auth.drivers)
|
|
878
|
-
S.driver === "htpasswd" && (
|
|
879
|
-
|
|
878
|
+
S.driver === "htpasswd" && (o.PL_AUTH_HTPASSWD_PATH = f.resolve(S.path), S.path = "/etc/platforma/users.htpasswd");
|
|
879
|
+
o.PL_AUTH_DRIVERS = JSON.stringify(r.auth.drivers);
|
|
880
880
|
}
|
|
881
881
|
const b = Be(
|
|
882
882
|
this.logger,
|
|
@@ -891,7 +891,7 @@ ${n}`), _r(
|
|
|
891
891
|
"backend"
|
|
892
892
|
],
|
|
893
893
|
{
|
|
894
|
-
env:
|
|
894
|
+
env: o,
|
|
895
895
|
stdio: "inherit"
|
|
896
896
|
},
|
|
897
897
|
{
|
|
@@ -899,7 +899,7 @@ ${n}`), _r(
|
|
|
899
899
|
composePath: t
|
|
900
900
|
}
|
|
901
901
|
);
|
|
902
|
-
J(b, "failed to start Platforma Backend in Docker"),
|
|
902
|
+
J(b, "failed to start Platforma Backend in Docker"), d.isActive = !0;
|
|
903
903
|
const w = this.renderRunInfo({
|
|
904
904
|
apiPort: r == null ? void 0 : r.grpcPort,
|
|
905
905
|
apiAddr: r == null ? void 0 : r.grpcAddr,
|
|
@@ -917,13 +917,13 @@ ${w}`);
|
|
|
917
917
|
const i = (r == null ? void 0 : r.image) ?? ie(r == null ? void 0 : r.version);
|
|
918
918
|
this.checkLicense(r == null ? void 0 : r.license, r == null ? void 0 : r.licenseFile);
|
|
919
919
|
const s = (k) => f.join(e, k), c = (k) => {
|
|
920
|
-
const
|
|
921
|
-
return q(
|
|
920
|
+
const p = s(k);
|
|
921
|
+
return q(p, { mode: "0775" }), p;
|
|
922
922
|
}, n = s("platforma.log");
|
|
923
|
-
|
|
923
|
+
l.existsSync(n) || (l.mkdirSync(f.dirname(n), { recursive: !0 }), l.writeFileSync(n, ""));
|
|
924
924
|
const h = c("db"), u = c("primary"), g = c("library"), v = c("work"), P = s("users.htpasswd");
|
|
925
|
-
|
|
926
|
-
const
|
|
925
|
+
l.existsSync(P) || l.copyFileSync($("users.htpasswd"), P);
|
|
926
|
+
const o = N((r == null ? void 0 : r.primaryStorageURL) ?? `file:${u}`, "."), b = N((r == null ? void 0 : r.libraryStorageURL) ?? `file:${g}`, "."), w = {
|
|
927
927
|
MINIO_IMAGE: "quay.io/minio/minio",
|
|
928
928
|
MINIO_STORAGE: c("minio"),
|
|
929
929
|
PL_IMAGE: i,
|
|
@@ -937,7 +937,7 @@ ${w}`);
|
|
|
937
937
|
PL_DATA_LIBRARY_ROOT: g,
|
|
938
938
|
PL_DATA_WORKDIR_ROOT: v,
|
|
939
939
|
PL_DATA_PACKAGE_ROOT: c("packages"),
|
|
940
|
-
...this.configureDockerStorage("primary",
|
|
940
|
+
...this.configureDockerStorage("primary", o),
|
|
941
941
|
...this.configureDockerStorage("library", b)
|
|
942
942
|
};
|
|
943
943
|
if (r != null && r.grpcAddr && (w.PL_GRPC_ADDR = r.grpcAddr), r != null && r.grpcPort && (w.PL_GRPC_PORT = r.grpcPort.toString()), r != null && r.monitoringAddr && (w.PL_MONITORING_ADDR = r.monitoringAddr), r != null && r.monitoringPort && (w.PL_MONITORING_PORT = r.monitoringPort.toString()), r != null && r.debugAddr && (w.PL_DEBUG_ADDR = r.debugAddr), r != null && r.debugPort && (w.PL_DEBUG_PORT = r.debugPort.toString()), r != null && r.auth && (r.auth.enabled && (w.PL_AUTH_ENABLED = "true"), r.auth.drivers)) {
|
|
@@ -960,12 +960,12 @@ ${w}`);
|
|
|
960
960
|
libraryPath: g
|
|
961
961
|
}
|
|
962
962
|
);
|
|
963
|
-
J(S, "failed to start Platforma Backend in Docker"),
|
|
963
|
+
J(S, "failed to start Platforma Backend in Docker"), d.isActive = !0;
|
|
964
964
|
const L = this.renderRunInfo({
|
|
965
965
|
apiPort: r == null ? void 0 : r.grpcPort,
|
|
966
966
|
apiAddr: r == null ? void 0 : r.grpcAddr,
|
|
967
967
|
logPath: n,
|
|
968
|
-
primary:
|
|
968
|
+
primary: o,
|
|
969
969
|
work: { type: "FS", rootPath: v },
|
|
970
970
|
library: b,
|
|
971
971
|
dbPath: h
|
|
@@ -974,11 +974,11 @@ ${w}`);
|
|
|
974
974
|
${L}`);
|
|
975
975
|
}
|
|
976
976
|
stop() {
|
|
977
|
-
if (!
|
|
977
|
+
if (!d.isActive) {
|
|
978
978
|
console.log("no running service detected");
|
|
979
979
|
return;
|
|
980
980
|
}
|
|
981
|
-
const e =
|
|
981
|
+
const e = d.lastRun;
|
|
982
982
|
switch (e.mode) {
|
|
983
983
|
case "docker":
|
|
984
984
|
const r = H("docker", ["compose", "--file", e.docker.composePath, "down"], {
|
|
@@ -988,31 +988,31 @@ ${L}`);
|
|
|
988
988
|
},
|
|
989
989
|
stdio: "inherit"
|
|
990
990
|
});
|
|
991
|
-
|
|
991
|
+
d.isActive = !1, r.status !== 0 && process.exit(r.status);
|
|
992
992
|
return;
|
|
993
993
|
case "process":
|
|
994
|
-
|
|
994
|
+
d.isValidPID && process.kill(e.process.pid), d.isActive = !1;
|
|
995
995
|
return;
|
|
996
996
|
default:
|
|
997
997
|
Y(e.mode);
|
|
998
998
|
}
|
|
999
999
|
}
|
|
1000
1000
|
cleanup() {
|
|
1001
|
-
var n, h, u, g, v, P,
|
|
1001
|
+
var n, h, u, g, v, P, o, b, w, S, L, k, p, W;
|
|
1002
1002
|
const e = [
|
|
1003
1003
|
"last command run cache ('pl-service start' shorthand will stop working until next full start command call)",
|
|
1004
1004
|
"'platforma' docker compose service containers and volumes"
|
|
1005
|
-
], r =
|
|
1006
|
-
if ((h = (n =
|
|
1007
|
-
const A = (g = (u =
|
|
1005
|
+
], r = d.data(), t = [r];
|
|
1006
|
+
if ((h = (n = d.lastRun) == null ? void 0 : n.docker) != null && h.primaryPath) {
|
|
1007
|
+
const A = (g = (u = d.lastRun) == null ? void 0 : u.docker) == null ? void 0 : g.primaryPath;
|
|
1008
1008
|
A.startsWith(r) || t.push(A);
|
|
1009
1009
|
}
|
|
1010
|
-
if ((P = (v =
|
|
1011
|
-
const A = (b = (
|
|
1010
|
+
if ((P = (v = d.lastRun) == null ? void 0 : v.docker) != null && P.workPath) {
|
|
1011
|
+
const A = (b = (o = d.lastRun) == null ? void 0 : o.docker) == null ? void 0 : b.workPath;
|
|
1012
1012
|
A.startsWith(r) || t.push(A);
|
|
1013
1013
|
}
|
|
1014
|
-
if ((S = (w =
|
|
1015
|
-
const A = (k = (L =
|
|
1014
|
+
if ((S = (w = d.lastRun) == null ? void 0 : w.process) != null && S.storagePath) {
|
|
1015
|
+
const A = (k = (L = d.lastRun) == null ? void 0 : L.process) == null ? void 0 : k.storagePath;
|
|
1016
1016
|
A.startsWith(r) || t.push(A);
|
|
1017
1017
|
}
|
|
1018
1018
|
const i = t.length > 0 ? ` - storages (you'll loose all projects and calculation results stored in service instances):
|
|
@@ -1029,20 +1029,20 @@ ${i}
|
|
|
1029
1029
|
this.logger.info("Reset action was canceled");
|
|
1030
1030
|
return;
|
|
1031
1031
|
}
|
|
1032
|
-
const c = new Set(
|
|
1033
|
-
(W = (
|
|
1032
|
+
const c = new Set(_r());
|
|
1033
|
+
(W = (p = d.lastRun) == null ? void 0 : p.docker) != null && W.composePath && c.add(d.lastRun.docker.composePath);
|
|
1034
1034
|
for (const A of c)
|
|
1035
1035
|
this.logger.info(`Destroying docker compose '${A}'`), this.destroyDocker(A, ie());
|
|
1036
1036
|
for (const A of t)
|
|
1037
|
-
this.logger.info(`Destroying '${A}'`),
|
|
1038
|
-
this.logger.info(`Destroying state dir '${
|
|
1037
|
+
this.logger.info(`Destroying '${A}'`), l.rmSync(A, { recursive: !0, force: !0 });
|
|
1038
|
+
this.logger.info(`Destroying state dir '${d.path()}'`), l.rmSync(d.path(), { recursive: !0, force: !0 }), this.logger.info(
|
|
1039
1039
|
`
|
|
1040
|
-
If you want to remove all downloaded platforma binaries, delete '${
|
|
1040
|
+
If you want to remove all downloaded platforma binaries, delete '${d.binaries()}' dir manually
|
|
1041
1041
|
`
|
|
1042
1042
|
);
|
|
1043
1043
|
}
|
|
1044
1044
|
mergeLicenseEnvs(e) {
|
|
1045
|
-
e.license === void 0 && ((process.env.MI_LICENSE ?? "") != "" ? e.license = process.env.MI_LICENSE : (process.env.PL_LICENSE ?? "") != "" && (e.license = process.env.PL_LICENSE)), e["license-file"] === void 0 && e.license === void 0 && ((process.env.MI_LICENSE_FILE ?? "") != "" ? e["license-file"] = process.env.MI_LICENSE_FILE : (process.env.PL_LICENSE_FILE ?? "") != "" ? e["license-file"] = process.env.PL_LICENSE_FILE :
|
|
1045
|
+
e.license === void 0 && ((process.env.MI_LICENSE ?? "") != "" ? e.license = process.env.MI_LICENSE : (process.env.PL_LICENSE ?? "") != "" && (e.license = process.env.PL_LICENSE)), e["license-file"] === void 0 && e.license === void 0 && ((process.env.MI_LICENSE_FILE ?? "") != "" ? e["license-file"] = process.env.MI_LICENSE_FILE : (process.env.PL_LICENSE_FILE ?? "") != "" ? e["license-file"] = process.env.PL_LICENSE_FILE : l.existsSync(f.resolve(_.homedir(), ".pl.license")) && (e["license-file"] = f.resolve(_.homedir(), ".pl.license")));
|
|
1046
1046
|
}
|
|
1047
1047
|
initAuthDriversList(e, r) {
|
|
1048
1048
|
var t = [];
|
|
@@ -1060,16 +1060,16 @@ If you want to remove all downloaded platforma binaries, delete '${l.binaries()}
|
|
|
1060
1060
|
}
|
|
1061
1061
|
/** Gets the last stored JWT secret key or generates it and stores in a file. */
|
|
1062
1062
|
getLastJwt() {
|
|
1063
|
-
const e =
|
|
1063
|
+
const e = d.path("auth.jwt"), r = "utf-8";
|
|
1064
1064
|
let t = "";
|
|
1065
1065
|
try {
|
|
1066
|
-
t =
|
|
1066
|
+
t = l.readFileSync(e, { encoding: r });
|
|
1067
1067
|
} catch {
|
|
1068
1068
|
}
|
|
1069
|
-
return t == "" && (t = yr(64),
|
|
1069
|
+
return t == "" && (t = yr(64), l.writeFileSync(e, t, { encoding: r })), t;
|
|
1070
1070
|
}
|
|
1071
1071
|
destroyDocker(e, r) {
|
|
1072
|
-
const t =
|
|
1072
|
+
const t = d.data("stub"), i = H("docker", ["compose", "--file", e, "down", "--volumes", "--remove-orphans"], {
|
|
1073
1073
|
env: {
|
|
1074
1074
|
...process.env,
|
|
1075
1075
|
PL_IMAGE: "scratch",
|
|
@@ -1146,11 +1146,11 @@ You can obtain the license from "https://licensing.milaboratories.com".`), new E
|
|
|
1146
1146
|
`);
|
|
1147
1147
|
}
|
|
1148
1148
|
readComposeFile(e) {
|
|
1149
|
-
const r =
|
|
1149
|
+
const r = l.readFileSync(e);
|
|
1150
1150
|
return Ce.parse(r.toString());
|
|
1151
1151
|
}
|
|
1152
1152
|
writeComposeFile(e, r) {
|
|
1153
|
-
|
|
1153
|
+
l.writeFileSync(e, Ce.stringify(r));
|
|
1154
1154
|
}
|
|
1155
1155
|
}
|
|
1156
1156
|
function J(a, e) {
|
|
@@ -1189,7 +1189,7 @@ const C = class C extends O {
|
|
|
1189
1189
|
m(C, "description", "Stop platforma service"), m(C, "examples", ["<%= config.bin %> <%= command.id %>"]), m(C, "flags", {
|
|
1190
1190
|
...T
|
|
1191
1191
|
});
|
|
1192
|
-
let
|
|
1192
|
+
let de = C;
|
|
1193
1193
|
const B = class B extends O {
|
|
1194
1194
|
async run() {
|
|
1195
1195
|
const { flags: e } = await this.parse(B), r = E(e["log-level"]), t = new D(r);
|
|
@@ -1197,7 +1197,7 @@ const B = class B extends O {
|
|
|
1197
1197
|
const i = e["auth-enabled"], s = i ? {
|
|
1198
1198
|
enabled: i,
|
|
1199
1199
|
drivers: t.initAuthDriversList(e, ".")
|
|
1200
|
-
} : void 0, c = e.storage ? f.join(".", e.storage) :
|
|
1200
|
+
} : void 0, c = e.storage ? f.join(".", e.storage) : d.data("docker");
|
|
1201
1201
|
t.startDocker(c, {
|
|
1202
1202
|
primaryStorageURL: e["storage-primary"],
|
|
1203
1203
|
workStoragePath: e["storage-work"],
|
|
@@ -1228,12 +1228,12 @@ m(B, "description", "Run platforma backend service with 'FS' primary storage typ
|
|
|
1228
1228
|
...fe,
|
|
1229
1229
|
...me
|
|
1230
1230
|
});
|
|
1231
|
-
let
|
|
1231
|
+
let oe = B;
|
|
1232
1232
|
const G = class G extends O {
|
|
1233
1233
|
async run() {
|
|
1234
1234
|
const { flags: e } = await this.parse(G), r = E(e["log-level"]), t = new D(r);
|
|
1235
1235
|
t.mergeLicenseEnvs(e);
|
|
1236
|
-
const i = e["pl-workdir"] ?? ".", s = e.storage ? f.join(i, e.storage) :
|
|
1236
|
+
const i = e["pl-workdir"] ?? ".", s = e.storage ? f.join(i, e.storage) : d.data("local"), c = e["pl-log-file"] ? f.join(i, e["pl-log-file"]) : void 0, n = t.initAuthDriversList(e, i), h = e["auth-enabled"] ?? n !== void 0;
|
|
1237
1237
|
var u = e["pl-binary"];
|
|
1238
1238
|
e["pl-sources"] && (u = t.buildPlatforma({ repoRoot: e["pl-sources"] }));
|
|
1239
1239
|
var g = "127.0.0.1:6345";
|
|
@@ -1242,7 +1242,7 @@ const G = class G extends O {
|
|
|
1242
1242
|
e["monitoring-listen"] ? v = e["monitoring-listen"] : e["monitoring-port"] && (v = `127.0.0.1:${e["monitoring-port"]}`);
|
|
1243
1243
|
var P = "127.0.0.1:9091";
|
|
1244
1244
|
e["debug-listen"] ? P = e["debug-listen"] : e["debug-port"] && (P = `127.0.0.1:${e["debug-port"]}`);
|
|
1245
|
-
const
|
|
1245
|
+
const o = {
|
|
1246
1246
|
binaryPath: u,
|
|
1247
1247
|
version: e.version,
|
|
1248
1248
|
configPath: e.config,
|
|
@@ -1262,7 +1262,7 @@ const G = class G extends O {
|
|
|
1262
1262
|
}
|
|
1263
1263
|
}
|
|
1264
1264
|
};
|
|
1265
|
-
|
|
1265
|
+
o.binaryPath ? t.startLocal(o) : Xe(r, { version: e.version }).then(() => t.startLocal(o)).catch(function(b) {
|
|
1266
1266
|
r.error(b.message);
|
|
1267
1267
|
});
|
|
1268
1268
|
}
|
|
@@ -1292,7 +1292,7 @@ let Gr = (R = class extends O {
|
|
|
1292
1292
|
const i = e["auth-enabled"], s = i ? {
|
|
1293
1293
|
enabled: i,
|
|
1294
1294
|
drivers: t.initAuthDriversList(e, ".")
|
|
1295
|
-
} : void 0, c = e.storage ? f.join(".", e.storage) :
|
|
1295
|
+
} : void 0, c = e.storage ? f.join(".", e.storage) : d.data("docker-s3");
|
|
1296
1296
|
t.startDockerS3(c, {
|
|
1297
1297
|
image: e.image,
|
|
1298
1298
|
version: e.version,
|
|
@@ -1320,7 +1320,7 @@ const U = class U extends O {
|
|
|
1320
1320
|
async run() {
|
|
1321
1321
|
const { flags: e } = await this.parse(U), r = E(e["log-level"]), t = new D(r);
|
|
1322
1322
|
t.mergeLicenseEnvs(e);
|
|
1323
|
-
const i = e["pl-workdir"] ?? ".", s = e.storage ? f.join(i, e.storage) :
|
|
1323
|
+
const i = e["pl-workdir"] ?? ".", s = e.storage ? f.join(i, e.storage) : d.data("local-s3"), c = e["pl-log-file"] ? f.join(i, e["pl-log-file"]) : void 0, n = t.initAuthDriversList(e, i), h = e["auth-enabled"] ?? n !== void 0;
|
|
1324
1324
|
var u = e["pl-binary"];
|
|
1325
1325
|
e["pl-sources"] && (u = t.buildPlatforma({ repoRoot: e["pl-sources"] }));
|
|
1326
1326
|
var g = "127.0.0.1:6345";
|
|
@@ -1329,7 +1329,7 @@ const U = class U extends O {
|
|
|
1329
1329
|
e["monitoring-listen"] ? v = e["monitoring-listen"] : e["monitoring-port"] && (v = `127.0.0.1:${e["monitoring-port"]}`);
|
|
1330
1330
|
var P = "127.0.0.1:9091";
|
|
1331
1331
|
e["debug-listen"] ? P = e["debug-listen"] : e["debug-port"] && (P = `127.0.0.1:${e["debug-port"]}`);
|
|
1332
|
-
const
|
|
1332
|
+
const o = {
|
|
1333
1333
|
binaryPath: u,
|
|
1334
1334
|
version: e.version,
|
|
1335
1335
|
configPath: e.config,
|
|
@@ -1353,7 +1353,7 @@ const U = class U extends O {
|
|
|
1353
1353
|
}
|
|
1354
1354
|
}
|
|
1355
1355
|
};
|
|
1356
|
-
|
|
1356
|
+
o.binaryPath ? t.startLocalS3(o) : Xe(r, { version: e.version }).then(() => t.startLocalS3(o)).catch(function(b) {
|
|
1357
1357
|
r.error(b.message);
|
|
1358
1358
|
});
|
|
1359
1359
|
}
|
|
@@ -1362,7 +1362,7 @@ m(U, "description", "Run Platforma Backend service as local process on current h
|
|
|
1362
1362
|
...T,
|
|
1363
1363
|
...Q,
|
|
1364
1364
|
...Z,
|
|
1365
|
-
...
|
|
1365
|
+
...or,
|
|
1366
1366
|
...Je,
|
|
1367
1367
|
...He,
|
|
1368
1368
|
...Ye,
|
|
@@ -1380,8 +1380,8 @@ const rt = {
|
|
|
1380
1380
|
"create-block": se,
|
|
1381
1381
|
reset: ne,
|
|
1382
1382
|
start: le,
|
|
1383
|
-
stop:
|
|
1384
|
-
"start:docker":
|
|
1383
|
+
stop: de,
|
|
1384
|
+
"start:docker": oe,
|
|
1385
1385
|
"start:local": ge,
|
|
1386
1386
|
"start:docker:s3": Gr,
|
|
1387
1387
|
"start:local:s3": ue
|