@milaboratories/pl-deployments 1.1.12 → 1.1.14

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.mjs CHANGED
@@ -1,5 +1,5 @@
1
- var V = Object.defineProperty;
2
- var Y = (s, r, t) => r in s ? V(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t;
1
+ var Z = Object.defineProperty;
2
+ var Y = (s, r, t) => r in s ? Z(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t;
3
3
  var w = (s, r, t) => Y(s, typeof r != "symbol" ? r + "" : r, t);
4
4
  import { spawn as Q } from "node:child_process";
5
5
  import { sleep as b, fileExists as g, assertNever as j, notEmpty as f, RetryablePromise as X } from "@milaboratories/ts-helpers";
@@ -16,7 +16,7 @@ import at, { Client as F } from "ssh2";
16
16
  import H from "node:net";
17
17
  import ct from "node:dns";
18
18
  import { randomBytes as k } from "node:crypto";
19
- import { generateSshPlConfigs as lt, getFreePort as P } from "@milaboratories/pl-config";
19
+ import { generateSshPlConfigs as lt, getFreePort as v } from "@milaboratories/pl-config";
20
20
  import { z as p } from "zod";
21
21
  function ht(s, r) {
22
22
  return s.info(`Running:
@@ -72,7 +72,7 @@ function S(s) {
72
72
  }
73
73
  const wt = "https://cdn.platforma.bio/software", ft = "https://cdn-ga.pl-open.science/software";
74
74
  async function pt(s, r, t, e, i, o) {
75
- const n = L(t, e, r, S(i), O(o)), { archiveUrl: c, alternativeArchiveGAUrl: a, archivePath: l } = n;
75
+ const n = G(t, e, r, S(i), O(o)), { archiveUrl: c, alternativeArchiveGAUrl: a, archivePath: l } = n;
76
76
  try {
77
77
  await C(s, c, l), n.wasDownloadedFrom = c;
78
78
  } catch {
@@ -81,7 +81,7 @@ async function pt(s, r, t, e, i, o) {
81
81
  return n;
82
82
  }
83
83
  async function mt(s, r, t, e, i, o) {
84
- const n = L(t, e, r, S(i), O(o)), { archiveUrl: c, alternativeArchiveGAUrl: a, archivePath: l, archiveType: h, targetFolder: u, baseName: y } = n;
84
+ const n = G(t, e, r, S(i), O(o)), { archiveUrl: c, alternativeArchiveGAUrl: a, archivePath: l, archiveType: h, targetFolder: u, baseName: y } = n;
85
85
  try {
86
86
  await C(s, c, l), n.wasDownloadedFrom = c;
87
87
  } catch {
@@ -89,7 +89,7 @@ async function mt(s, r, t, e, i, o) {
89
89
  }
90
90
  return await yt(s, l, h, u), n;
91
91
  }
92
- function L(s, r, t, e, i) {
92
+ function G(s, r, t, e, i) {
93
93
  const o = `${r}-${e}`, n = $t[i], c = `${o}.${n}`, a = `${wt}/${s}/${i}/${c}`, l = `${ft}/${s}/${i}/${c}`, h = d.join(t, c), u = d.join(t, o);
94
94
  return {
95
95
  archiveUrl: a,
@@ -157,12 +157,12 @@ const $t = {
157
157
  windows: "zip"
158
158
  };
159
159
  function R() {
160
- return "1.18.3";
160
+ return "1.20.1";
161
161
  }
162
- function Pt() {
162
+ function vt() {
163
163
  return { type: "Download", version: R() };
164
164
  }
165
- async function vt(s, r, t) {
165
+ async function Pt(s, r, t) {
166
166
  switch (t.type) {
167
167
  case "Download":
168
168
  const e = await mt(s, r, "pl", `pl-${t.version}`, A.arch(), A.platform());
@@ -178,7 +178,7 @@ const St = {
178
178
  macos: "platforma",
179
179
  windows: "platforma.exe"
180
180
  };
181
- function G(s) {
181
+ function L(s) {
182
182
  return d.join(s, "pl_pid");
183
183
  }
184
184
  async function Ct(s) {
@@ -196,7 +196,7 @@ function At() {
196
196
  function Ft(s, r, t) {
197
197
  return s[r] = t, t;
198
198
  }
199
- async function N(s, r) {
199
+ async function B(s, r) {
200
200
  const t = At();
201
201
  try {
202
202
  return await r((i, o) => Ft(t, i, o), t);
@@ -215,7 +215,7 @@ class Dt {
215
215
  this.logger = r, this.workingDir = t, this.startOptions = e, this.initialStartHistory = i, this.onClose = o, this.onError = n, this.onCloseAndError = c, this.onCloseAndErrorNoStop = a;
216
216
  }
217
217
  async start() {
218
- await N(this.logger, async (r, t) => {
218
+ await B(this.logger, async (r, t) => {
219
219
  this.wasStopped = !1;
220
220
  const e = ht(this.logger, this.startOptions);
221
221
  e.on("error", (o) => {
@@ -225,7 +225,7 @@ class Dt {
225
225
  }), e.on("close", () => {
226
226
  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);
227
227
  }), r("started", !0);
228
- const i = r("pidFile", G(this.workingDir));
228
+ const i = r("pidFile", L(this.workingDir));
229
229
  r("pid", f(e.pid)), r("pidWritten", await Et(i, f(e.pid))), this.nRuns++, this.instance = e, this.pid = e.pid, this.lastRunHistory = t;
230
230
  });
231
231
  }
@@ -254,18 +254,18 @@ class Dt {
254
254
  }
255
255
  async function fr(s, r) {
256
256
  const t = {
257
- plBinary: Pt(),
257
+ plBinary: vt(),
258
258
  spawnOptions: {},
259
259
  closeOld: !0,
260
260
  ...r
261
261
  };
262
- return await N(s, async (e, i) => {
262
+ return await B(s, async (e, i) => {
263
263
  e("startOptions", { ...t, config: "too wordy" });
264
264
  const o = d.resolve(t.workingDir);
265
265
  t.closeOld && e("closeOld", await kt(s, o));
266
266
  const n = d.join(o, bt);
267
267
  s.info(`writing configuration '${n}'...`), await m.writeFile(n, t.config);
268
- const c = d.join(o, "binaries"), a = await vt(s, c, t.plBinary), h = {
268
+ const c = d.join(o, "binaries"), a = await Pt(s, c, t.plBinary), h = {
269
269
  cmd: e("binaryPath", d.join("binaries", a)),
270
270
  args: ["-config", n],
271
271
  opts: {
@@ -296,8 +296,8 @@ async function fr(s, r) {
296
296
  });
297
297
  }
298
298
  async function kt(s, r) {
299
- return await N(s, async (t, e) => {
300
- const i = t("pidFilePath", G(r)), o = t("pid", await Ct(i)), n = t("wasAlive", await x(o));
299
+ return await B(s, async (t, e) => {
300
+ const i = t("pidFilePath", L(r)), o = t("pid", await Ct(i)), n = t("wasAlive", await x(o));
301
301
  return o !== void 0 && n && (t("stopped", J(o)), t("waitStopped", await M(o, 1e4))), e;
302
302
  });
303
303
  }
@@ -305,7 +305,7 @@ const xt = {
305
305
  keepaliveInterval: 6e4,
306
306
  keepaliveCountMax: 10
307
307
  };
308
- class U {
308
+ class N {
309
309
  constructor(r, t) {
310
310
  w(this, "config");
311
311
  w(this, "homeDir");
@@ -321,7 +321,7 @@ class U {
321
321
  const e = {
322
322
  ...xt,
323
323
  ...t
324
- }, i = new U(r, new F());
324
+ }, i = new N(r, new F());
325
325
  return await i.connect(e), i;
326
326
  }
327
327
  getForwardedServers() {
@@ -698,7 +698,7 @@ class U {
698
698
  * @param remotePath - The path to the remote directory.
699
699
  * @returns A promise that resolves when the directory is created.
700
700
  */
701
- createRemoteDirectory(r, t = 493) {
701
+ ensureRemoteDirCreated(r, t = 493) {
702
702
  return this.withSftp(async (e) => {
703
703
  const i = r.split("/");
704
704
  let o = "";
@@ -758,7 +758,7 @@ async function Rt(s, r, t, e, i, o) {
758
758
  r.forwardOut(t, e, i, o, (a, l) => a ? (s.error(`forwardOut.error: ${a}`), c(a)) : n(l));
759
759
  });
760
760
  }
761
- const Nt = "minio-2024-12-18T13-15-44Z", Ut = "supervisord-0.7.3", Bt = "supervisord_0.7.3_Linux_64-bit";
761
+ const Bt = "minio-2024-12-18T13-15-44Z", Nt = "supervisord-0.7.3", Ut = "supervisord_0.7.3_Linux_64-bit";
762
762
  function $(s) {
763
763
  return d.join(s, ".platforma_ssh");
764
764
  }
@@ -784,31 +784,31 @@ function _t(s, r) {
784
784
  return d.join(z(s, r), "minio");
785
785
  }
786
786
  function jt(s, r) {
787
- return d.join(E(s), `supervisord-0.7.3-${S(r)}`, Bt);
787
+ return d.join(E(s), `supervisord-0.7.3-${S(r)}`, Ut);
788
788
  }
789
789
  function K(s, r) {
790
790
  return d.join(jt(s, r), "supervisord");
791
791
  }
792
- function q(s) {
792
+ function V(s) {
793
793
  return d.join($(s), "supervisor.conf");
794
794
  }
795
795
  function I(s) {
796
796
  return d.join($(s), "connection.txt");
797
797
  }
798
798
  async function Ht(s, r, t) {
799
- const e = await B(s, r, t, "--daemon");
799
+ const e = await U(s, r, t, "--daemon");
800
800
  if (e.stderr)
801
801
  throw new Error(`Can not run ssh Platforma ${e.stderr}`);
802
802
  }
803
803
  async function Jt(s, r, t) {
804
- const e = await B(s, r, t, "ctl shutdown");
804
+ const e = await U(s, r, t, "ctl shutdown");
805
805
  if (e.stderr)
806
806
  throw new Error(`Can not stop ssh Platforma ${e.stderr}`);
807
807
  }
808
808
  async function Mt(s, r, t, e) {
809
809
  let i;
810
810
  try {
811
- i = await B(r, t, e, "ctl status");
811
+ i = await U(r, t, e, "ctl status");
812
812
  } catch (a) {
813
813
  return { execError: String(a), allAlive: !1 };
814
814
  }
@@ -822,7 +822,7 @@ async function Mt(s, r, t, e) {
822
822
  };
823
823
  return c.allAlive || (c.minio || s.warn("Minio is not running on the server"), c.platforma || s.warn("Platforma is not running on the server")), c;
824
824
  }
825
- function Lt(s, r, t, e, i, o, n) {
825
+ function Gt(s, r, t, e, i, o, n) {
826
826
  const c = Object.entries(r).map(([h, u]) => `${h}="${u}"`).join(","), a = k(16).toString("hex"), l = t;
827
827
  return `
828
828
  [supervisord]
@@ -855,8 +855,8 @@ directory=${e}
855
855
  autorestart=true
856
856
  `;
857
857
  }
858
- async function B(s, r, t, e) {
859
- const i = K(r, t), o = q(r), n = `${i} --configuration ${o} ${e}`;
858
+ async function U(s, r, t, e) {
859
+ const i = K(r, t), o = V(r), n = `${i} --configuration ${o} ${e}`;
860
860
  return await s.exec(n);
861
861
  }
862
862
  function _(s, r) {
@@ -866,38 +866,41 @@ function _(s, r) {
866
866
  return o === r && n === "Running";
867
867
  });
868
868
  }
869
- const v = p.object({
869
+ const P = p.object({
870
870
  local: p.number(),
871
871
  remote: p.number()
872
- }), Gt = p.object({
873
- grpc: v,
874
- monitoring: v,
875
- debug: v,
876
- minioPort: v,
877
- minioConsolePort: v
872
+ }), Lt = p.object({
873
+ grpc: P,
874
+ monitoring: P,
875
+ debug: P,
876
+ minioPort: P,
877
+ minioConsolePort: P
878
878
  }), Wt = p.object({
879
879
  plUser: p.string(),
880
880
  plPassword: p.string(),
881
- ports: Gt,
881
+ ports: Lt,
882
882
  // It's false by default because it was added later,
883
883
  // and in some deployments there won't be useGlobalAccess flag in the file.
884
- useGlobalAccess: p.boolean().default(!1)
884
+ useGlobalAccess: p.boolean().default(!1),
885
+ // We added the field afterwards, the pl backend was this version.
886
+ plVersion: p.string().default("1.18.3")
885
887
  });
886
- function zt(s, r, t, e) {
888
+ function zt(s, r, t, e, i) {
887
889
  return {
888
890
  plUser: s,
889
891
  plPassword: r,
890
892
  ports: t,
891
- useGlobalAccess: e
893
+ useGlobalAccess: e,
894
+ plVersion: i
892
895
  };
893
896
  }
894
897
  function Kt(s) {
895
898
  return Wt.parse(JSON.parse(s));
896
899
  }
897
- function qt(s) {
900
+ function Vt(s) {
898
901
  return JSON.stringify(s, void 0, 2);
899
902
  }
900
- class Z {
903
+ class q {
901
904
  constructor(r, t, e) {
902
905
  w(this, "initState", {});
903
906
  this.logger = r, this.sshClient = t, this.username = e;
@@ -910,8 +913,8 @@ class Z {
910
913
  }
911
914
  static async init(r, t) {
912
915
  try {
913
- const e = await U.init(r, t);
914
- return new Z(r, e, f(t.username));
916
+ const e = await N.init(r, t);
917
+ return new q(r, e, f(t.username));
915
918
  } catch (e) {
916
919
  throw r.error(`Connection error in SshClient.init: ${e}`), e;
917
920
  }
@@ -964,18 +967,20 @@ class Z {
964
967
  const t = { localWorkdir: r.localWorkdir };
965
968
  try {
966
969
  const e = {
967
- ...Zt,
970
+ ...qt,
968
971
  ...r
969
972
  };
970
- if (t.arch = await this.getArch(), t.remoteHome = await this.getUserHomeDirectory(), t.alive = await this.isAlive(), t.alive.allAlive) {
973
+ if (t.plBinaryOps = e.plBinary, t.arch = await this.getArch(), t.remoteHome = await this.getUserHomeDirectory(), t.alive = await this.isAlive(), t.alive.allAlive) {
971
974
  if (t.userCredentials = await this.getUserCredentials(t.remoteHome), !t.userCredentials)
972
975
  throw new Error("SshPl.platformaInit: platforma is alive but userCredentials are not found");
973
- if (!(t.userCredentials.useGlobalAccess != e.useGlobalAccess))
976
+ const a = t.userCredentials.useGlobalAccess == e.useGlobalAccess, l = t.userCredentials.plVersion == e.plBinary.version;
977
+ if (t.needRestart = !(a && l), this.logger.info(`SshPl.platformaInit: need restart? ${t.needRestart}`), !t.needRestart)
974
978
  return t.userCredentials;
975
- await this.stopAndClean();
979
+ await this.stop();
976
980
  }
977
981
  const i = await this.downloadBinariesAndUploadToTheServer(
978
982
  e.localWorkdir,
983
+ e.plBinary,
979
984
  t.remoteHome,
980
985
  t.arch
981
986
  );
@@ -1003,8 +1008,8 @@ class Z {
1003
1008
  for (const [a, l] of Object.entries(o.filesToCreate))
1004
1009
  await this.sshClient.writeFileOnTheServer(a, l), this.logger.info(`Created file ${a}`);
1005
1010
  for (const a of o.dirsToCreate)
1006
- await this.sshClient.createRemoteDirectory(a), this.logger.info(`Created directory ${a}`);
1007
- const n = Lt(
1011
+ await this.sshClient.ensureRemoteDirCreated(a), this.logger.info(`Created directory ${a}`);
1012
+ const n = Gt(
1008
1013
  o.minioConfig.storageDir,
1009
1014
  o.minioConfig.envs,
1010
1015
  await this.getFreePortForPlatformaOnServer(t.remoteHome, t.arch),
@@ -1013,56 +1018,57 @@ class Z {
1013
1018
  t.binPaths.minioRelPath,
1014
1019
  t.binPaths.downloadedPl
1015
1020
  );
1016
- if (!await this.sshClient.writeFileOnTheServer(q(t.remoteHome), n))
1021
+ if (!await this.sshClient.writeFileOnTheServer(V(t.remoteHome), n))
1017
1022
  throw new Error(`Can not write supervisord config on the server ${$(t.remoteHome)}`);
1018
1023
  return t.connectionInfo = zt(
1019
1024
  o.plUser,
1020
1025
  o.plPassword,
1021
1026
  t.ports,
1022
- f(e.useGlobalAccess)
1027
+ f(e.useGlobalAccess),
1028
+ e.plBinary.version
1023
1029
  ), await this.sshClient.writeFileOnTheServer(
1024
1030
  I(t.remoteHome),
1025
- qt(t.connectionInfo)
1031
+ Vt(t.connectionInfo)
1026
1032
  ), await this.start(), t.started = !0, this.initState = t, t.connectionInfo;
1027
1033
  } catch (e) {
1028
1034
  const i = `SshPl.platformaInit: error occurred: ${e}, state: ${JSON.stringify(t)}`;
1029
1035
  throw this.logger.error(i), new Error(i);
1030
1036
  }
1031
1037
  }
1032
- async downloadBinariesAndUploadToTheServer(r, t, e) {
1033
- const i = [];
1038
+ async downloadBinariesAndUploadToTheServer(r, t, e, i) {
1039
+ const o = [];
1034
1040
  try {
1035
- const o = await this.downloadAndUntar(
1041
+ const n = await this.downloadAndUntar(
1036
1042
  r,
1037
- t,
1038
1043
  e,
1044
+ i,
1039
1045
  "pl",
1040
- `pl-${R()}`
1046
+ `pl-${t.version}`
1041
1047
  );
1042
- i.push(o);
1043
- const n = await this.downloadAndUntar(
1048
+ o.push(n);
1049
+ const c = await this.downloadAndUntar(
1044
1050
  r,
1045
- t,
1046
1051
  e,
1052
+ i,
1047
1053
  "supervisord",
1048
- Ut
1054
+ Nt
1049
1055
  );
1050
- i.push(n);
1051
- const c = _t(t, e.arch), a = await this.downloadAndUntar(
1056
+ o.push(c);
1057
+ const a = _t(e, i.arch), l = await this.downloadAndUntar(
1052
1058
  r,
1053
- t,
1054
1059
  e,
1060
+ i,
1055
1061
  "minio",
1056
- Nt
1062
+ Bt
1057
1063
  );
1058
- return i.push(a), await this.sshClient.chmod(c, 488), {
1059
- history: i,
1060
- minioRelPath: c,
1061
- downloadedPl: T(t, e.arch)
1064
+ return o.push(l), await this.sshClient.chmod(a, 488), {
1065
+ history: o,
1066
+ minioRelPath: a,
1067
+ downloadedPl: T(e, i.arch)
1062
1068
  };
1063
- } catch (o) {
1064
- const n = `SshPl.downloadBinariesAndUploadToServer: error ${o} occurred, state: ${JSON.stringify(i)}`;
1065
- throw this.logger.error(n), o;
1069
+ } catch (n) {
1070
+ const c = `SshPl.downloadBinariesAndUploadToServer: error ${n} occurred, state: ${JSON.stringify(o)}`;
1071
+ throw this.logger.error(c), n;
1066
1072
  }
1067
1073
  }
1068
1074
  /** We have to extract pl in the remote server,
@@ -1073,7 +1079,7 @@ class Z {
1073
1079
  * (it's not installed for Rocky Linux for example). */
1074
1080
  async downloadAndUntar(r, t, e, i, o) {
1075
1081
  const n = {};
1076
- n.binBasePath = E(t), await this.sshClient.createRemoteDirectory(n.binBasePath), n.binBasePathCreated = !0;
1082
+ n.binBasePath = E(t), await this.sshClient.ensureRemoteDirCreated(n.binBasePath), n.binBasePathCreated = !0;
1077
1083
  let c = null;
1078
1084
  const a = 5;
1079
1085
  for (let h = 1; h <= a; h++)
@@ -1091,7 +1097,7 @@ class Z {
1091
1097
  if (await b(300), h == a)
1092
1098
  throw new Error(`downloadAndUntar: ${a} attempts, last error: ${u}`);
1093
1099
  }
1094
- n.downloadResult = f(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);
1100
+ n.downloadResult = f(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.ensureRemoteDirCreated(n.remoteDir), await this.sshClient.uploadFile(n.localArchivePath, n.remoteArchivePath);
1095
1101
  const l = await this.sshClient.exec(
1096
1102
  `tar --warning=no-all -xvf ${n.remoteArchivePath} --directory=${n.remoteDir}`
1097
1103
  );
@@ -1119,23 +1125,23 @@ class Z {
1119
1125
  async fetchPorts(r, t) {
1120
1126
  return {
1121
1127
  grpc: {
1122
- local: await P(),
1128
+ local: await v(),
1123
1129
  remote: await this.getFreePortForPlatformaOnServer(r, t)
1124
1130
  },
1125
1131
  monitoring: {
1126
- local: await P(),
1132
+ local: await v(),
1127
1133
  remote: await this.getFreePortForPlatformaOnServer(r, t)
1128
1134
  },
1129
1135
  debug: {
1130
- local: await P(),
1136
+ local: await v(),
1131
1137
  remote: await this.getFreePortForPlatformaOnServer(r, t)
1132
1138
  },
1133
1139
  minioPort: {
1134
- local: await P(),
1140
+ local: await v(),
1135
1141
  remote: await this.getFreePortForPlatformaOnServer(r, t)
1136
1142
  },
1137
1143
  minioConsolePort: {
1138
- local: await P(),
1144
+ local: await v(),
1139
1145
  remote: await this.getFreePortForPlatformaOnServer(r, t)
1140
1146
  }
1141
1147
  };
@@ -1175,21 +1181,25 @@ class Z {
1175
1181
  return r.trim();
1176
1182
  }
1177
1183
  }
1178
- const Zt = {
1179
- useGlobalAccess: !1
1184
+ const qt = {
1185
+ useGlobalAccess: !1,
1186
+ plBinary: {
1187
+ type: "Download",
1188
+ version: R()
1189
+ }
1180
1190
  };
1181
1191
  export {
1182
1192
  Wt as ConnectionInfo,
1183
1193
  bt as LocalConfigYaml,
1184
1194
  Dt as LocalPl,
1185
- v as PortPair,
1186
- U as SshClient,
1187
- Z as SshPl,
1188
- Gt as SshPlPorts,
1195
+ P as PortPair,
1196
+ N as SshClient,
1197
+ q as SshPl,
1198
+ Lt as SshPlPorts,
1189
1199
  R as getDefaultPlVersion,
1190
1200
  fr as localPlatformaInit,
1191
1201
  zt as newConnectionInfo,
1192
1202
  Kt as parseConnectionInfo,
1193
- qt as stringifyConnectionInfo
1203
+ Vt as stringifyConnectionInfo
1194
1204
  };
1195
1205
  //# sourceMappingURL=index.mjs.map