@milaboratories/pl-deployments 2.4.6 → 2.4.8

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.
Files changed (96) hide show
  1. package/dist/common/os_and_arch.cjs +39 -0
  2. package/dist/common/os_and_arch.cjs.map +1 -0
  3. package/dist/common/os_and_arch.d.ts +0 -1
  4. package/dist/common/os_and_arch.js +34 -0
  5. package/dist/common/os_and_arch.js.map +1 -0
  6. package/dist/common/pl_binary.cjs +34 -0
  7. package/dist/common/pl_binary.cjs.map +1 -0
  8. package/dist/common/pl_binary.d.ts +0 -1
  9. package/dist/common/pl_binary.js +30 -0
  10. package/dist/common/pl_binary.js.map +1 -0
  11. package/dist/common/pl_binary_download.cjs +172 -0
  12. package/dist/common/pl_binary_download.cjs.map +1 -0
  13. package/dist/common/pl_binary_download.d.ts +0 -1
  14. package/dist/common/pl_binary_download.js +148 -0
  15. package/dist/common/pl_binary_download.js.map +1 -0
  16. package/dist/common/pl_version.cjs +11 -0
  17. package/dist/common/pl_version.cjs.map +1 -0
  18. package/dist/common/pl_version.d.ts +0 -1
  19. package/dist/common/pl_version.js +9 -0
  20. package/dist/common/pl_version.js.map +1 -0
  21. package/dist/index.cjs +26 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.ts +0 -1
  24. package/dist/index.js +5 -64
  25. package/dist/index.js.map +1 -1
  26. package/dist/local/options.d.ts +0 -1
  27. package/dist/local/pid.cjs +24 -0
  28. package/dist/local/pid.cjs.map +1 -0
  29. package/dist/local/pid.d.ts +0 -1
  30. package/dist/local/pid.js +20 -0
  31. package/dist/local/pid.js.map +1 -0
  32. package/dist/local/pl.cjs +217 -0
  33. package/dist/local/pl.cjs.map +1 -0
  34. package/dist/local/pl.d.ts +0 -1
  35. package/dist/local/pl.js +192 -0
  36. package/dist/local/pl.js.map +1 -0
  37. package/dist/local/process.cjs +42 -0
  38. package/dist/local/process.cjs.map +1 -0
  39. package/dist/local/process.d.ts +0 -1
  40. package/dist/local/process.js +37 -0
  41. package/dist/local/process.js.map +1 -0
  42. package/dist/local/trace.cjs +27 -0
  43. package/dist/local/trace.cjs.map +1 -0
  44. package/dist/local/trace.d.ts +0 -1
  45. package/dist/local/trace.js +23 -0
  46. package/dist/local/trace.js.map +1 -0
  47. package/dist/package.json.cjs +7 -0
  48. package/dist/package.json.cjs.map +1 -0
  49. package/dist/package.json.js +5 -0
  50. package/dist/package.json.js.map +1 -0
  51. package/dist/ssh/__tests__/common-utils.d.ts +0 -1
  52. package/dist/ssh/connection_info.cjs +62 -0
  53. package/dist/ssh/connection_info.cjs.map +1 -0
  54. package/dist/ssh/connection_info.d.ts +0 -1
  55. package/dist/ssh/connection_info.js +55 -0
  56. package/dist/ssh/connection_info.js.map +1 -0
  57. package/dist/ssh/pl.cjs +500 -0
  58. package/dist/ssh/pl.cjs.map +1 -0
  59. package/dist/ssh/pl.d.ts +0 -1
  60. package/dist/ssh/pl.js +497 -0
  61. package/dist/ssh/pl.js.map +1 -0
  62. package/dist/ssh/pl_paths.cjs +67 -0
  63. package/dist/ssh/pl_paths.cjs.map +1 -0
  64. package/dist/ssh/pl_paths.d.ts +0 -1
  65. package/dist/ssh/pl_paths.js +50 -0
  66. package/dist/ssh/pl_paths.js.map +1 -0
  67. package/dist/ssh/ssh.cjs +621 -0
  68. package/dist/ssh/ssh.cjs.map +1 -0
  69. package/dist/ssh/ssh.d.ts +0 -1
  70. package/dist/ssh/ssh.js +619 -0
  71. package/dist/ssh/ssh.js.map +1 -0
  72. package/dist/ssh/supervisord.cjs +149 -0
  73. package/dist/ssh/supervisord.cjs.map +1 -0
  74. package/dist/ssh/supervisord.d.ts +0 -1
  75. package/dist/ssh/supervisord.js +140 -0
  76. package/dist/ssh/supervisord.js.map +1 -0
  77. package/package.json +16 -14
  78. package/src/common/pl_version.ts +3 -2
  79. package/dist/common/os_and_arch.d.ts.map +0 -1
  80. package/dist/common/pl_binary.d.ts.map +0 -1
  81. package/dist/common/pl_binary_download.d.ts.map +0 -1
  82. package/dist/common/pl_version.d.ts.map +0 -1
  83. package/dist/index.d.ts.map +0 -1
  84. package/dist/index.mjs +0 -1366
  85. package/dist/index.mjs.map +0 -1
  86. package/dist/local/options.d.ts.map +0 -1
  87. package/dist/local/pid.d.ts.map +0 -1
  88. package/dist/local/pl.d.ts.map +0 -1
  89. package/dist/local/process.d.ts.map +0 -1
  90. package/dist/local/trace.d.ts.map +0 -1
  91. package/dist/ssh/__tests__/common-utils.d.ts.map +0 -1
  92. package/dist/ssh/connection_info.d.ts.map +0 -1
  93. package/dist/ssh/pl.d.ts.map +0 -1
  94. package/dist/ssh/pl_paths.d.ts.map +0 -1
  95. package/dist/ssh/ssh.d.ts.map +0 -1
  96. package/dist/ssh/supervisord.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.js","sources":["../../src/local/trace.ts"],"sourcesContent":["import type { MiLogger } from '@milaboratories/ts-helpers';\n\n/** Records all inputs and outputs of one's choice, so if the error happened\n * one can check how it was by just printing this structure. */\nexport type Trace = Record<string, any>;\n\nexport function newTrace(): Trace {\n return {};\n}\n\nexport function trace(t: Trace, k: string, v: any) {\n t[k] = v;\n return v;\n}\n\n/** Creates a trace and runs a function with it. The function can record all its\n * logs or traces using `trace` fn. */\nexport async function withTrace<T>(\n logger: MiLogger,\n fn: (trace: (k: string, v: any) => typeof v, t: Trace) => Promise<T>,\n): Promise<T> {\n const t = newTrace();\n try {\n const result = await fn((k: string, v: any) => trace(t, k, v), t);\n return result;\n } catch (e: any) {\n logger.error(`error ${e} while doing traced operation, state: ${JSON.stringify(t)}`);\n throw e;\n }\n}\n"],"names":[],"mappings":"SAMgB,QAAQ,GAAA;AACtB,IAAA,OAAO,EAAE;AACX;SAEgB,KAAK,CAAC,CAAQ,EAAE,CAAS,EAAE,CAAM,EAAA;AAC/C,IAAA,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACR,IAAA,OAAO,CAAC;AACV;AAEA;AACsC;AAC/B,eAAe,SAAS,CAC7B,MAAgB,EAChB,EAAoE,EAAA;AAEpE,IAAA,MAAM,CAAC,GAAG,QAAQ,EAAE;AACpB,IAAA,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CAAS,EAAE,CAAM,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AACjE,QAAA,OAAO,MAAM;IACf;IAAE,OAAO,CAAM,EAAE;AACf,QAAA,MAAM,CAAC,KAAK,CAAC,CAAA,MAAA,EAAS,CAAC,CAAA,sCAAA,EAAyC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA,CAAE,CAAC;AACpF,QAAA,MAAM,CAAC;IACT;AACF;;;;"}
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var packageJson = {
4
+ "pl-version": "1.35.2"};
5
+
6
+ module.exports = packageJson;
7
+ //# sourceMappingURL=package.json.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.json.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
@@ -0,0 +1,5 @@
1
+ var packageJson = {
2
+ "pl-version": "1.35.2"};
3
+
4
+ export { packageJson as default };
5
+ //# sourceMappingURL=package.json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -9,4 +9,3 @@ export declare function getContainerHostAndPort(container: StartedTestContainer)
9
9
  };
10
10
  export declare function getConnectionForSsh(container: StartedTestContainer, debug?: boolean): ConnectConfig;
11
11
  export declare function cleanUp(container: StartedTestContainer): Promise<void>;
12
- //# sourceMappingURL=common-utils.d.ts.map
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+
5
+ /** We store all info about the connection on the server,
6
+ * so that another client could read the file and connect from another machine. */
7
+ //
8
+ // Types
9
+ //
10
+ const PortPair = zod.z.object({
11
+ local: zod.z.number(),
12
+ remote: zod.z.number(),
13
+ });
14
+ const SshPlPorts = zod.z.object({
15
+ grpc: PortPair,
16
+ http: PortPair.optional(),
17
+ monitoring: PortPair,
18
+ debug: PortPair,
19
+ /** @deprecated */
20
+ minioPort: PortPair,
21
+ /** @deprecated */
22
+ minioConsolePort: PortPair,
23
+ });
24
+ const ConnectionInfo = zod.z.object({
25
+ plUser: zod.z.string(),
26
+ plPassword: zod.z.string(),
27
+ ports: SshPlPorts,
28
+ // It's false by default because it was added later,
29
+ // and in some deployments there won't be useGlobalAccess flag in the file.
30
+ useGlobalAccess: zod.z.boolean().default(false),
31
+ // We added the field afterwards, the pl backend was this version.
32
+ plVersion: zod.z.string().default('1.18.3'),
33
+ // It's true by default because it was added later and previous installation use minio.
34
+ minioIsUsed: zod.z.boolean().default(true),
35
+ });
36
+ //
37
+ // Funcs
38
+ //
39
+ function newConnectionInfo(plUser, plPassword, ports, useGlobalAccess, plVersion, minioIsUsed) {
40
+ return {
41
+ plUser,
42
+ plPassword,
43
+ ports,
44
+ useGlobalAccess,
45
+ plVersion,
46
+ minioIsUsed: minioIsUsed,
47
+ };
48
+ }
49
+ function parseConnectionInfo(content) {
50
+ return ConnectionInfo.parse(JSON.parse(content));
51
+ }
52
+ function stringifyConnectionInfo(conn) {
53
+ return JSON.stringify(conn, undefined, 2);
54
+ }
55
+
56
+ exports.ConnectionInfo = ConnectionInfo;
57
+ exports.PortPair = PortPair;
58
+ exports.SshPlPorts = SshPlPorts;
59
+ exports.newConnectionInfo = newConnectionInfo;
60
+ exports.parseConnectionInfo = parseConnectionInfo;
61
+ exports.stringifyConnectionInfo = stringifyConnectionInfo;
62
+ //# sourceMappingURL=connection_info.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection_info.cjs","sources":["../../src/ssh/connection_info.ts"],"sourcesContent":["/** We store all info about the connection on the server,\n * so that another client could read the file and connect from another machine. */\nimport { z } from 'zod';\n\n//\n// Types\n//\n\nexport const PortPair = z.object({\n local: z.number(),\n remote: z.number(),\n});\n/** The pair of ports for forwarding. */\nexport type PortPair = z.infer<typeof PortPair>;\n\nexport const SshPlPorts = z.object({\n grpc: PortPair,\n http: PortPair.optional(),\n monitoring: PortPair,\n debug: PortPair,\n /** @deprecated */\n minioPort: PortPair,\n /** @deprecated */\n minioConsolePort: PortPair,\n});\n/** All info about ports that are forwarded. */\nexport type SshPlPorts = z.infer<typeof SshPlPorts>;\n\nexport const ConnectionInfo = z.object({\n plUser: z.string(),\n plPassword: z.string(),\n ports: SshPlPorts,\n\n // It's false by default because it was added later,\n // and in some deployments there won't be useGlobalAccess flag in the file.\n useGlobalAccess: z.boolean().default(false),\n\n // We added the field afterwards, the pl backend was this version.\n plVersion: z.string().default('1.18.3'),\n\n // It's true by default because it was added later and previous installation use minio.\n minioIsUsed: z.boolean().default(true),\n});\n/** The content of the file that holds all the info about the connection on the remote server. */\nexport type ConnectionInfo = z.infer<typeof ConnectionInfo>;\n\n//\n// Funcs\n//\n\nexport function newConnectionInfo(\n plUser: string,\n plPassword: string,\n ports: SshPlPorts,\n useGlobalAccess: boolean,\n plVersion: string,\n minioIsUsed: boolean,\n): ConnectionInfo {\n return {\n plUser,\n plPassword,\n ports,\n useGlobalAccess,\n plVersion,\n minioIsUsed: minioIsUsed,\n };\n}\n\nexport function parseConnectionInfo(content: string): ConnectionInfo {\n return ConnectionInfo.parse(JSON.parse(content));\n}\n\nexport function stringifyConnectionInfo(conn: ConnectionInfo): string {\n return JSON.stringify(conn, undefined, 2);\n}\n"],"names":["z"],"mappings":";;;;AAAA;AACkF;AAGlF;AACA;AACA;AAEO,MAAM,QAAQ,GAAGA,KAAC,CAAC,MAAM,CAAC;AAC/B,IAAA,KAAK,EAAEA,KAAC,CAAC,MAAM,EAAE;AACjB,IAAA,MAAM,EAAEA,KAAC,CAAC,MAAM,EAAE;AACnB,CAAA;AAIM,MAAM,UAAU,GAAGA,KAAC,CAAC,MAAM,CAAC;AACjC,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE;AACzB,IAAA,UAAU,EAAE,QAAQ;AACpB,IAAA,KAAK,EAAE,QAAQ;;AAEf,IAAA,SAAS,EAAE,QAAQ;;AAEnB,IAAA,gBAAgB,EAAE,QAAQ;AAC3B,CAAA;AAIM,MAAM,cAAc,GAAGA,KAAC,CAAC,MAAM,CAAC;AACrC,IAAA,MAAM,EAAEA,KAAC,CAAC,MAAM,EAAE;AAClB,IAAA,UAAU,EAAEA,KAAC,CAAC,MAAM,EAAE;AACtB,IAAA,KAAK,EAAE,UAAU;;;IAIjB,eAAe,EAAEA,KAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;;IAG3C,SAAS,EAAEA,KAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC;;IAGvC,WAAW,EAAEA,KAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;AACvC,CAAA;AAID;AACA;AACA;AAEM,SAAU,iBAAiB,CAC/B,MAAc,EACd,UAAkB,EAClB,KAAiB,EACjB,eAAwB,EACxB,SAAiB,EACjB,WAAoB,EAAA;IAEpB,OAAO;QACL,MAAM;QACN,UAAU;QACV,KAAK;QACL,eAAe;QACf,SAAS;AACT,QAAA,WAAW,EAAE,WAAW;KACzB;AACH;AAEM,SAAU,mBAAmB,CAAC,OAAe,EAAA;IACjD,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAClD;AAEM,SAAU,uBAAuB,CAAC,IAAoB,EAAA;IAC1D,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;AAC3C;;;;;;;;;"}
@@ -317,4 +317,3 @@ export type ConnectionInfo = z.infer<typeof ConnectionInfo>;
317
317
  export declare function newConnectionInfo(plUser: string, plPassword: string, ports: SshPlPorts, useGlobalAccess: boolean, plVersion: string, minioIsUsed: boolean): ConnectionInfo;
318
318
  export declare function parseConnectionInfo(content: string): ConnectionInfo;
319
319
  export declare function stringifyConnectionInfo(conn: ConnectionInfo): string;
320
- //# sourceMappingURL=connection_info.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { z } from 'zod';
2
+
3
+ /** We store all info about the connection on the server,
4
+ * so that another client could read the file and connect from another machine. */
5
+ //
6
+ // Types
7
+ //
8
+ const PortPair = z.object({
9
+ local: z.number(),
10
+ remote: z.number(),
11
+ });
12
+ const SshPlPorts = z.object({
13
+ grpc: PortPair,
14
+ http: PortPair.optional(),
15
+ monitoring: PortPair,
16
+ debug: PortPair,
17
+ /** @deprecated */
18
+ minioPort: PortPair,
19
+ /** @deprecated */
20
+ minioConsolePort: PortPair,
21
+ });
22
+ const ConnectionInfo = z.object({
23
+ plUser: z.string(),
24
+ plPassword: z.string(),
25
+ ports: SshPlPorts,
26
+ // It's false by default because it was added later,
27
+ // and in some deployments there won't be useGlobalAccess flag in the file.
28
+ useGlobalAccess: z.boolean().default(false),
29
+ // We added the field afterwards, the pl backend was this version.
30
+ plVersion: z.string().default('1.18.3'),
31
+ // It's true by default because it was added later and previous installation use minio.
32
+ minioIsUsed: z.boolean().default(true),
33
+ });
34
+ //
35
+ // Funcs
36
+ //
37
+ function newConnectionInfo(plUser, plPassword, ports, useGlobalAccess, plVersion, minioIsUsed) {
38
+ return {
39
+ plUser,
40
+ plPassword,
41
+ ports,
42
+ useGlobalAccess,
43
+ plVersion,
44
+ minioIsUsed: minioIsUsed,
45
+ };
46
+ }
47
+ function parseConnectionInfo(content) {
48
+ return ConnectionInfo.parse(JSON.parse(content));
49
+ }
50
+ function stringifyConnectionInfo(conn) {
51
+ return JSON.stringify(conn, undefined, 2);
52
+ }
53
+
54
+ export { ConnectionInfo, PortPair, SshPlPorts, newConnectionInfo, parseConnectionInfo, stringifyConnectionInfo };
55
+ //# sourceMappingURL=connection_info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection_info.js","sources":["../../src/ssh/connection_info.ts"],"sourcesContent":["/** We store all info about the connection on the server,\n * so that another client could read the file and connect from another machine. */\nimport { z } from 'zod';\n\n//\n// Types\n//\n\nexport const PortPair = z.object({\n local: z.number(),\n remote: z.number(),\n});\n/** The pair of ports for forwarding. */\nexport type PortPair = z.infer<typeof PortPair>;\n\nexport const SshPlPorts = z.object({\n grpc: PortPair,\n http: PortPair.optional(),\n monitoring: PortPair,\n debug: PortPair,\n /** @deprecated */\n minioPort: PortPair,\n /** @deprecated */\n minioConsolePort: PortPair,\n});\n/** All info about ports that are forwarded. */\nexport type SshPlPorts = z.infer<typeof SshPlPorts>;\n\nexport const ConnectionInfo = z.object({\n plUser: z.string(),\n plPassword: z.string(),\n ports: SshPlPorts,\n\n // It's false by default because it was added later,\n // and in some deployments there won't be useGlobalAccess flag in the file.\n useGlobalAccess: z.boolean().default(false),\n\n // We added the field afterwards, the pl backend was this version.\n plVersion: z.string().default('1.18.3'),\n\n // It's true by default because it was added later and previous installation use minio.\n minioIsUsed: z.boolean().default(true),\n});\n/** The content of the file that holds all the info about the connection on the remote server. */\nexport type ConnectionInfo = z.infer<typeof ConnectionInfo>;\n\n//\n// Funcs\n//\n\nexport function newConnectionInfo(\n plUser: string,\n plPassword: string,\n ports: SshPlPorts,\n useGlobalAccess: boolean,\n plVersion: string,\n minioIsUsed: boolean,\n): ConnectionInfo {\n return {\n plUser,\n plPassword,\n ports,\n useGlobalAccess,\n plVersion,\n minioIsUsed: minioIsUsed,\n };\n}\n\nexport function parseConnectionInfo(content: string): ConnectionInfo {\n return ConnectionInfo.parse(JSON.parse(content));\n}\n\nexport function stringifyConnectionInfo(conn: ConnectionInfo): string {\n return JSON.stringify(conn, undefined, 2);\n}\n"],"names":[],"mappings":";;AAAA;AACkF;AAGlF;AACA;AACA;AAEO,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;AAC/B,IAAA,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;AACjB,IAAA,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;AACnB,CAAA;AAIM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;AACjC,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE;AACzB,IAAA,UAAU,EAAE,QAAQ;AACpB,IAAA,KAAK,EAAE,QAAQ;;AAEf,IAAA,SAAS,EAAE,QAAQ;;AAEnB,IAAA,gBAAgB,EAAE,QAAQ;AAC3B,CAAA;AAIM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;AACrC,IAAA,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;AAClB,IAAA,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;AACtB,IAAA,KAAK,EAAE,UAAU;;;IAIjB,eAAe,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;;IAG3C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC;;IAGvC,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;AACvC,CAAA;AAID;AACA;AACA;AAEM,SAAU,iBAAiB,CAC/B,MAAc,EACd,UAAkB,EAClB,KAAiB,EACjB,eAAwB,EACxB,SAAiB,EACjB,WAAoB,EAAA;IAEpB,OAAO;QACL,MAAM;QACN,UAAU;QACV,KAAK;QACL,eAAe;QACf,SAAS;AACT,QAAA,WAAW,EAAE,WAAW;KACzB;AACH;AAEM,SAAU,mBAAmB,CAAC,OAAe,EAAA;IACjD,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAClD;AAEM,SAAU,uBAAuB,CAAC,IAAoB,EAAA;IAC1D,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;AAC3C;;;;"}
@@ -0,0 +1,500 @@
1
+ 'use strict';
2
+
3
+ var ssh = require('./ssh.cjs');
4
+ var tsHelpers = require('@milaboratories/ts-helpers');
5
+ var pl_binary_download = require('../common/pl_binary_download.cjs');
6
+ var upath = require('upath');
7
+ var pl_paths = require('./pl_paths.cjs');
8
+ var pl_version = require('../common/pl_version.cjs');
9
+ var net = require('node:net');
10
+ var plConfig = require('@milaboratories/pl-config');
11
+ var supervisord = require('./supervisord.cjs');
12
+ var connection_info = require('./connection_info.cjs');
13
+
14
+ const minRequiredGlibcVersion = 2.28;
15
+ class SshPl {
16
+ logger;
17
+ sshClient;
18
+ username;
19
+ initState = { step: 'init' };
20
+ constructor(logger, sshClient, username) {
21
+ this.logger = logger;
22
+ this.sshClient = sshClient;
23
+ this.username = username;
24
+ }
25
+ info() {
26
+ return {
27
+ username: this.username,
28
+ initState: this.initState,
29
+ };
30
+ }
31
+ static async init(logger, config) {
32
+ try {
33
+ const sshClient = await ssh.SshClient.init(logger, config);
34
+ return new SshPl(logger, sshClient, tsHelpers.notEmpty(config.username));
35
+ }
36
+ catch (e) {
37
+ logger.error(`Connection error in SshClient.init: ${e}`);
38
+ throw e;
39
+ }
40
+ }
41
+ cleanUp() {
42
+ this.sshClient.close();
43
+ }
44
+ /** Provides an info if the platforma and minio are running along with the debug info. */
45
+ async isAlive() {
46
+ const arch = await this.getArch();
47
+ const remoteHome = await this.getUserHomeDirectory();
48
+ return await supervisord.supervisorStatus(this.logger, this.sshClient, remoteHome, arch.arch);
49
+ }
50
+ /** Starts all the services on the server.
51
+ * Idempotent semantic: we could call it several times. */
52
+ async start(shouldUseMinio) {
53
+ const arch = await this.getArch();
54
+ const remoteHome = await this.getUserHomeDirectory();
55
+ try {
56
+ if (!supervisord.isAllAlive(await this.isAlive(), shouldUseMinio)) {
57
+ await supervisord.supervisorCtlStart(this.sshClient, remoteHome, arch.arch);
58
+ // We are waiting for Platforma to run to ensure that it has started.
59
+ return await this.checkIsAliveWithInterval(shouldUseMinio);
60
+ }
61
+ }
62
+ catch (e) {
63
+ let msg = `SshPl.start: ${e}`;
64
+ let logs = '';
65
+ try {
66
+ logs = await this.sshClient.readFile(pl_paths.platformaCliLogs(remoteHome));
67
+ msg += `, platforma cli logs: ${logs}`;
68
+ }
69
+ catch (e) {
70
+ msg += `, Can not read platforma cli logs: ${e}`;
71
+ }
72
+ this.logger.error(msg);
73
+ throw new Error(msg);
74
+ }
75
+ }
76
+ /** Stops all the services on the server.
77
+ * Idempotent semantic: we could call it several times. */
78
+ async stop() {
79
+ const arch = await this.getArch();
80
+ const remoteHome = await this.getUserHomeDirectory();
81
+ try {
82
+ const alive = await this.isAlive();
83
+ if (supervisord.isSupervisordRunning(alive)) {
84
+ await supervisord.supervisorStop(this.sshClient, remoteHome, arch.arch);
85
+ // Check if Minio is running by looking at the alive status
86
+ const shouldUseMinio = alive.minio === true;
87
+ return await this.checkIsAliveWithInterval(shouldUseMinio, 1000, 15, false);
88
+ }
89
+ }
90
+ catch (e) {
91
+ const msg = `PlSsh.stop: ${e}`;
92
+ this.logger.error(msg);
93
+ throw new Error(msg);
94
+ }
95
+ }
96
+ /** Stops the services, deletes a directory with the state and closes SSH connection. */
97
+ async reset() {
98
+ await this.stopAndClean();
99
+ this.cleanUp();
100
+ return true;
101
+ }
102
+ /** Stops platforma and deletes its state. */
103
+ async stopAndClean() {
104
+ const remoteHome = await this.getUserHomeDirectory();
105
+ this.logger.info(`pl.reset: Stop Platforma on the server`);
106
+ await this.stop();
107
+ this.logger.info(`pl.reset: Deleting Platforma workDir ${pl_paths.workDir(remoteHome)} on the server`);
108
+ await this.sshClient.deleteFolder(pl_paths.workDir(remoteHome));
109
+ }
110
+ /** Downloads binaries and untar them on the server,
111
+ * generates all the configs, creates necessary dirs,
112
+ * and finally starts all the services. */
113
+ async platformaInit(options) {
114
+ const state = { localWorkdir: options.localWorkdir, step: 'init' };
115
+ const { onProgress } = options;
116
+ // merge options with default ops.
117
+ const ops = {
118
+ ...defaultSshPlConfig,
119
+ ...options,
120
+ };
121
+ state.plBinaryOps = ops.plBinary;
122
+ try {
123
+ await this.doStepDetectArch(state, onProgress);
124
+ await this.doStepDetectHome(state, onProgress);
125
+ const needRestartPlatforma = await this.doStepReadExistedConfig(state, ops, onProgress);
126
+ if (!needRestartPlatforma) {
127
+ await onProgress?.('Platforma is already running. Skipping initialization.');
128
+ return state.existedSettings;
129
+ }
130
+ await this.doStepStopExistedPlatforma(state, onProgress);
131
+ await onProgress?.('Installation platforma...');
132
+ await this.doStepDownloadBinaries(state, onProgress, ops);
133
+ await this.doStepFetchPorts(state);
134
+ await this.doStepGenerateNewConfig(state, onProgress, ops);
135
+ await this.doStepCreateFoldersAndSaveFiles(state, onProgress);
136
+ await this.doStepConfigureSupervisord(state, onProgress);
137
+ await this.doStepSaveNewConnectionInfo(state, onProgress, ops);
138
+ await this.doStepStartPlatforma(state, onProgress);
139
+ return state.connectionInfo;
140
+ }
141
+ catch (e) {
142
+ const msg = `SshPl.platformaInit: ${e}, state: ${JSON.stringify(this.removeSensitiveData(state))}`;
143
+ this.logger.error(msg);
144
+ throw new Error(msg);
145
+ }
146
+ }
147
+ async doStepStopExistedPlatforma(state, onProgress) {
148
+ state.step = 'stopExistedPlatforma';
149
+ if (!supervisord.isAllAlive(state.alive, state.shouldUseMinio ?? false)) {
150
+ return;
151
+ }
152
+ await onProgress?.('Stopping services...');
153
+ await this.stop();
154
+ }
155
+ removeSensitiveData(state) {
156
+ const stateCopy = { ...state };
157
+ stateCopy.generatedConfig = { ...stateCopy.generatedConfig, filesToCreate: { skipped: 'sanitized' } };
158
+ return stateCopy;
159
+ }
160
+ async doStepStartPlatforma(state, onProgress) {
161
+ state.step = 'startPlatforma';
162
+ await onProgress?.('Starting Platforma on the server...');
163
+ await this.start(state.shouldUseMinio ?? false);
164
+ state.started = true;
165
+ this.initState = state;
166
+ await onProgress?.('Platforma has been started successfully.');
167
+ }
168
+ async doStepSaveNewConnectionInfo(state, onProgress, ops) {
169
+ state.step = 'saveNewConnectionInfo';
170
+ const config = state.generatedConfig;
171
+ await onProgress?.('Saving connection information...');
172
+ state.connectionInfo = connection_info.newConnectionInfo(config.plUser, config.plPassword, state.ports, tsHelpers.notEmpty(ops.useGlobalAccess), ops.plBinary.version, state.shouldUseMinio ?? false);
173
+ await this.sshClient.writeFileOnTheServer(pl_paths.connectionInfo(state.remoteHome), connection_info.stringifyConnectionInfo(state.connectionInfo));
174
+ await onProgress?.('Connection information saved.');
175
+ }
176
+ async doStepConfigureSupervisord(state, onProgress) {
177
+ await onProgress?.('Writing supervisord configuration...');
178
+ state.step = 'configureSupervisord';
179
+ const config = state.generatedConfig;
180
+ let supervisorConfig;
181
+ if (state.shouldUseMinio) {
182
+ supervisorConfig = supervisord.generateSupervisordConfigWithMinio(config.minioConfig.storageDir, config.minioConfig.envs, await this.getFreePortForPlatformaOnServer(state.remoteHome, state.arch), config.workingDir, config.plConfig.configPath, state.binPaths.minioRelPath, state.binPaths.downloadedPl);
183
+ }
184
+ else {
185
+ supervisorConfig = supervisord.generateSupervisordConfig(await this.getFreePortForPlatformaOnServer(state.remoteHome, state.arch), config.workingDir, config.plConfig.configPath, state.binPaths.downloadedPl);
186
+ }
187
+ const writeResult = await this.sshClient.writeFileOnTheServer(pl_paths.supervisorConf(state.remoteHome), supervisorConfig);
188
+ if (!writeResult) {
189
+ throw new Error(`Can not write supervisord config on the server ${pl_paths.workDir(state.remoteHome)}`);
190
+ }
191
+ await onProgress?.('Supervisord configuration written.');
192
+ }
193
+ async doStepCreateFoldersAndSaveFiles(state, onProgress) {
194
+ state.step = 'createFoldersAndSaveFiles';
195
+ const config = state.generatedConfig;
196
+ await onProgress?.('Generating folder structure...');
197
+ for (const [filePath, content] of Object.entries(config.filesToCreate)) {
198
+ await this.sshClient.writeFileOnTheServer(filePath, content);
199
+ this.logger.info(`Created file ${filePath}`);
200
+ }
201
+ for (const dir of config.dirsToCreate) {
202
+ await this.sshClient.ensureRemoteDirCreated(dir);
203
+ this.logger.info(`Created directory ${dir}`);
204
+ }
205
+ await onProgress?.('Folder structure created.');
206
+ }
207
+ async doStepGenerateNewConfig(state, onProgress, ops) {
208
+ state.step = 'generateNewConfig';
209
+ await onProgress?.('Generating new config...');
210
+ const config = await plConfig.generateSshPlConfigs({
211
+ logger: this.logger,
212
+ workingDir: pl_paths.workDir(state.remoteHome),
213
+ portsMode: {
214
+ type: 'customWithMinio',
215
+ ports: {
216
+ debug: state.ports.debug.remote,
217
+ grpc: state.ports.grpc.remote,
218
+ http: state.ports.http.remote,
219
+ minio: state.ports.minioPort.remote,
220
+ minioConsole: state.ports.minioConsolePort.remote,
221
+ monitoring: state.ports.monitoring.remote,
222
+ httpLocal: state.ports.http.local,
223
+ grpcLocal: state.ports.grpc.local,
224
+ minioLocal: state.ports.minioPort.local,
225
+ },
226
+ },
227
+ licenseMode: ops.license,
228
+ useGlobalAccess: tsHelpers.notEmpty(ops.useGlobalAccess),
229
+ plConfigPostprocessing: ops.plConfigPostprocessing,
230
+ useMinio: state.shouldUseMinio ?? false,
231
+ });
232
+ state.generatedConfig = { ...config };
233
+ await onProgress?.('New config generated');
234
+ }
235
+ async doStepFetchPorts(state) {
236
+ state.step = 'fetchPorts';
237
+ state.ports = await this.fetchPorts(state.remoteHome, state.arch);
238
+ if (!state.ports.debug.remote
239
+ || !state.ports.grpc.remote
240
+ || !state.ports.minioPort.remote
241
+ || !state.ports.minioConsolePort.remote
242
+ || !state.ports.monitoring.remote
243
+ || !state.ports.http?.remote) {
244
+ throw new Error(`SshPl.platformaInit: remote ports are not defined`);
245
+ }
246
+ }
247
+ async doStepDownloadBinaries(state, onProgress, ops) {
248
+ state.step = 'downloadBinaries';
249
+ await onProgress?.('Downloading and uploading required binaries...');
250
+ const glibcVersion = await getGlibcVersion(this.logger, this.sshClient);
251
+ if (glibcVersion < minRequiredGlibcVersion)
252
+ throw new Error(`glibc version ${glibcVersion} is too old. Version ${minRequiredGlibcVersion} or higher is required for Platforma.`);
253
+ const downloadRes = await this.downloadBinariesAndUploadToTheServer(ops.localWorkdir, ops.plBinary, state.remoteHome, state.arch, state.shouldUseMinio ?? false);
254
+ await onProgress?.('All required binaries have been downloaded and uploaded.');
255
+ state.binPaths = { ...downloadRes, history: undefined };
256
+ state.downloadedBinaries = downloadRes.history;
257
+ }
258
+ async doStepDetectArch(state, onProgress) {
259
+ state.step = 'detectArch';
260
+ await onProgress?.('Detecting server architecture...');
261
+ state.arch = await this.getArch();
262
+ await onProgress?.('Server architecture detected.');
263
+ }
264
+ async doStepDetectHome(state, onProgress) {
265
+ state.step = 'detectHome';
266
+ await onProgress?.('Fetching user home directory...');
267
+ state.remoteHome = await this.getUserHomeDirectory();
268
+ await onProgress?.('User home directory retrieved.');
269
+ }
270
+ async doStepReadExistedConfig(state, ops, onProgress) {
271
+ state.step = 'checkAlive';
272
+ await onProgress?.('Checking platform status...');
273
+ state.alive = await this.isAlive();
274
+ if (!state.alive?.platforma) {
275
+ return true;
276
+ }
277
+ await onProgress?.('All required services are running.');
278
+ state.existedSettings = await this.readExistedConfig(state.remoteHome);
279
+ if (!state.existedSettings) {
280
+ throw new Error(`SshPl.platformaInit: platforma is alive but existed settings are not found`);
281
+ }
282
+ const sameGA = state.existedSettings.useGlobalAccess == ops.useGlobalAccess;
283
+ const samePlVersion = state.existedSettings.plVersion == ops.plBinary.version;
284
+ state.needRestart = !(sameGA && samePlVersion);
285
+ this.logger.info(`SshPl.platformaInit: need restart? ${state.needRestart}`);
286
+ state.shouldUseMinio = state.existedSettings.minioIsUsed;
287
+ if (state.shouldUseMinio) {
288
+ this.logger.info(`SshPl.platformaInit: minio is used`);
289
+ }
290
+ else {
291
+ this.logger.info(`SshPl.platformaInit: minio is not used`);
292
+ }
293
+ if (!state.needRestart) {
294
+ await onProgress?.('Server setup completed.');
295
+ return false;
296
+ }
297
+ await onProgress?.('Stopping services...');
298
+ await this.stop();
299
+ return true;
300
+ }
301
+ async downloadBinariesAndUploadToTheServer(localWorkdir, plBinary, remoteHome, arch, shouldUseMinio) {
302
+ const state = [];
303
+ try {
304
+ const pl = await this.downloadAndUntar(localWorkdir, remoteHome, arch, 'pl', `pl-${plBinary.version}`);
305
+ state.push(pl);
306
+ const supervisor = await this.downloadAndUntar(localWorkdir, remoteHome, arch, 'supervisord', pl_paths.supervisordDirName);
307
+ state.push(supervisor);
308
+ const minioPath = pl_paths.minioBin(remoteHome, arch.arch);
309
+ if (shouldUseMinio) {
310
+ const minio = await this.downloadAndUntar(localWorkdir, remoteHome, arch, 'minio', pl_paths.minioDirName);
311
+ state.push(minio);
312
+ await this.sshClient.chmod(minioPath, 0o750);
313
+ }
314
+ return {
315
+ history: state,
316
+ minioRelPath: shouldUseMinio ? minioPath : undefined,
317
+ downloadedPl: pl_paths.platformaBin(remoteHome, arch.arch),
318
+ };
319
+ }
320
+ catch (e) {
321
+ const msg = `SshPl.downloadBinariesAndUploadToServer: ${e}, state: ${JSON.stringify(state)}`;
322
+ this.logger.error(msg);
323
+ throw e;
324
+ }
325
+ }
326
+ /** We have to extract pl in the remote server,
327
+ * because Windows doesn't support symlinks
328
+ * that are found in Linux pl binaries tgz archive.
329
+ * For this reason, we extract all to the remote server.
330
+ * It requires `tar` to be installed on the server
331
+ * (it's not installed for Rocky Linux for example). */
332
+ async downloadAndUntar(localWorkdir, remoteHome, arch, softwareName, tgzName) {
333
+ const state = {};
334
+ state.binBasePath = pl_paths.binariesDir(remoteHome);
335
+ await this.sshClient.ensureRemoteDirCreated(state.binBasePath);
336
+ state.binBasePathCreated = true;
337
+ let downloadBinaryResult = null;
338
+ const attempts = 5;
339
+ for (let i = 1; i <= attempts; i++) {
340
+ try {
341
+ downloadBinaryResult = await pl_binary_download.downloadBinaryNoExtract(this.logger, localWorkdir, softwareName, tgzName, arch.arch, arch.platform);
342
+ break;
343
+ }
344
+ catch (e) {
345
+ await tsHelpers.sleep(300);
346
+ if (i == attempts) {
347
+ throw new Error(`downloadAndUntar: ${attempts} attempts, last error: ${e}`);
348
+ }
349
+ }
350
+ }
351
+ state.downloadResult = tsHelpers.notEmpty(downloadBinaryResult);
352
+ state.localArchivePath = upath.resolve(state.downloadResult.archivePath);
353
+ state.remoteDir = upath.join(state.binBasePath, state.downloadResult.baseName);
354
+ state.remoteArchivePath = state.remoteDir + '.tgz';
355
+ await this.sshClient.ensureRemoteDirCreated(state.remoteDir);
356
+ await this.sshClient.uploadFile(state.localArchivePath, state.remoteArchivePath);
357
+ state.uploadDone = true;
358
+ try {
359
+ await this.sshClient.exec('hash tar');
360
+ }
361
+ catch (_) {
362
+ throw new Error(`tar is not installed on the server. Please install it before running Platforma.`);
363
+ }
364
+ // TODO: Create a proper archive to avoid xattr warnings
365
+ const untarResult = await this.sshClient.exec(`tar --warning=no-all -xvf ${state.remoteArchivePath} --directory=${state.remoteDir}`);
366
+ if (untarResult.stderr)
367
+ throw new Error(`downloadAndUntar: untar: stderr occurred: ${untarResult.stderr}, stdout: ${untarResult.stdout}`);
368
+ state.untarDone = true;
369
+ return state;
370
+ }
371
+ async needDownload(remoteHome, arch) {
372
+ const checkPathSupervisor = pl_paths.supervisorBin(remoteHome, arch.arch);
373
+ const checkPathMinio = pl_paths.minioDir(remoteHome, arch.arch);
374
+ const checkPathPlatforma = pl_paths.platformaBin(remoteHome, arch.arch);
375
+ if (!await this.sshClient.checkFileExists(checkPathPlatforma)
376
+ || !await this.sshClient.checkFileExists(checkPathMinio)
377
+ || !await this.sshClient.checkFileExists(checkPathSupervisor)) {
378
+ return true;
379
+ }
380
+ return false;
381
+ }
382
+ async checkIsAliveWithInterval(shouldUseMinio, interval = 1000, count = 15, shouldStart = true) {
383
+ const maxMs = count * interval;
384
+ let total = 0;
385
+ let alive = await this.isAlive();
386
+ while (shouldStart ? !supervisord.isAllAlive(alive, shouldUseMinio) : supervisord.isAllAlive(alive, shouldUseMinio)) {
387
+ await tsHelpers.sleep(interval);
388
+ total += interval;
389
+ if (total > maxMs) {
390
+ throw new Error(`isAliveWithInterval: The process did not ${shouldStart ? 'started' : 'stopped'} after ${maxMs} ms. Live status: ${JSON.stringify(alive)}`);
391
+ }
392
+ alive = await this.isAlive();
393
+ }
394
+ }
395
+ async readExistedConfig(remoteHome) {
396
+ const connectionInfo = await this.sshClient.readFile(pl_paths.connectionInfo(remoteHome));
397
+ return connection_info.parseConnectionInfo(connectionInfo);
398
+ }
399
+ async fetchPorts(remoteHome, arch) {
400
+ const ports = {
401
+ grpc: {
402
+ local: await plConfig.getFreePort(),
403
+ remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),
404
+ },
405
+ monitoring: {
406
+ local: await plConfig.getFreePort(),
407
+ remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),
408
+ },
409
+ debug: {
410
+ local: await plConfig.getFreePort(),
411
+ remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),
412
+ },
413
+ http: {
414
+ local: await plConfig.getFreePort(),
415
+ remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),
416
+ },
417
+ minioPort: {
418
+ local: await plConfig.getFreePort(),
419
+ remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),
420
+ },
421
+ minioConsolePort: {
422
+ local: await plConfig.getFreePort(),
423
+ remote: await this.getFreePortForPlatformaOnServer(remoteHome, arch),
424
+ },
425
+ };
426
+ return ports;
427
+ }
428
+ async getLocalFreePort() {
429
+ return new Promise((res) => {
430
+ const srv = net.createServer();
431
+ srv.listen(0, () => {
432
+ const port = srv.address().port;
433
+ srv.close((_) => res(port));
434
+ });
435
+ });
436
+ }
437
+ async getFreePortForPlatformaOnServer(remoteHome, arch) {
438
+ const freePortBin = pl_paths.platformaFreePortBin(remoteHome, arch.arch);
439
+ const { stdout, stderr } = await this.sshClient.exec(`${freePortBin}`);
440
+ if (stderr) {
441
+ throw new Error(`getFreePortForPlatformaOnServer: stderr is not empty: ${stderr}, stdout: ${stdout}`);
442
+ }
443
+ return +stdout;
444
+ }
445
+ async getArch() {
446
+ const { stdout, stderr } = await this.sshClient.exec('uname -s && uname -m');
447
+ if (stderr)
448
+ throw new Error(`getArch: stderr is not empty: ${stderr}, stdout: ${stdout}`);
449
+ const arr = stdout.split('\n');
450
+ return {
451
+ platform: arr[0],
452
+ arch: arr[1],
453
+ };
454
+ }
455
+ async getUserHomeDirectory() {
456
+ const { stdout, stderr } = await this.sshClient.exec('echo $HOME');
457
+ if (stderr) {
458
+ const home = `/home/${this.username}`;
459
+ console.warn(`getUserHomeDirectory: stderr is not empty: ${stderr}, stdout: ${stdout}, will get a default home: ${home}`);
460
+ return home;
461
+ }
462
+ return stdout.trim();
463
+ }
464
+ }
465
+ const defaultSshPlConfig = {
466
+ useGlobalAccess: false,
467
+ plBinary: {
468
+ type: 'Download',
469
+ version: pl_version.getDefaultPlVersion(),
470
+ },
471
+ };
472
+ /**
473
+ * Gets the glibc version on the remote system
474
+ * @returns The glibc version as a number
475
+ * @throws Error if version cannot be determined
476
+ */
477
+ async function getGlibcVersion(logger, sshClient) {
478
+ try {
479
+ const { stdout, stderr } = await sshClient.exec('ldd --version | head -n 1');
480
+ if (stderr) {
481
+ throw new Error(`Failed to check glibc version: ${stderr}`);
482
+ }
483
+ return parseGlibcVersion(stdout);
484
+ }
485
+ catch (e) {
486
+ logger.error(`glibc version check failed: ${e}`);
487
+ throw e;
488
+ }
489
+ }
490
+ function parseGlibcVersion(output) {
491
+ const versionMatch = output.match(/\d+\.\d+/);
492
+ if (!versionMatch) {
493
+ throw new Error(`Could not parse glibc version from: ${output}`);
494
+ }
495
+ return parseFloat(versionMatch[0]);
496
+ }
497
+
498
+ exports.SshPl = SshPl;
499
+ exports.parseGlibcVersion = parseGlibcVersion;
500
+ //# sourceMappingURL=pl.cjs.map