@platforma-sdk/bootstrap 5.2.50 → 5.2.52

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 (176) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/block.cjs +106 -146
  3. package/dist/block.cjs.map +1 -1
  4. package/dist/block.js +100 -125
  5. package/dist/block.js.map +1 -1
  6. package/dist/cmd-opts.cjs +87 -177
  7. package/dist/cmd-opts.cjs.map +1 -1
  8. package/dist/cmd-opts.js +87 -172
  9. package/dist/cmd-opts.js.map +1 -1
  10. package/dist/commands/create-block.cjs +19 -20
  11. package/dist/commands/create-block.cjs.map +1 -1
  12. package/dist/commands/create-block.d.ts +12 -7
  13. package/dist/commands/create-block.js +17 -17
  14. package/dist/commands/create-block.js.map +1 -1
  15. package/dist/commands/reset.cjs +18 -21
  16. package/dist/commands/reset.cjs.map +1 -1
  17. package/dist/commands/reset.d.ts +12 -7
  18. package/dist/commands/reset.js +16 -18
  19. package/dist/commands/reset.js.map +1 -1
  20. package/dist/commands/start/docker/s3.cjs +64 -67
  21. package/dist/commands/start/docker/s3.cjs.map +1 -1
  22. package/dist/commands/start/docker/s3.d.ts +32 -27
  23. package/dist/commands/start/docker/s3.js +61 -64
  24. package/dist/commands/start/docker/s3.js.map +1 -1
  25. package/dist/commands/start/docker.cjs +64 -67
  26. package/dist/commands/start/docker.cjs.map +1 -1
  27. package/dist/commands/start/docker.d.ts +32 -27
  28. package/dist/commands/start/docker.js +61 -64
  29. package/dist/commands/start/docker.js.map +1 -1
  30. package/dist/commands/start/local/s3.cjs +101 -135
  31. package/dist/commands/start/local/s3.cjs.map +1 -1
  32. package/dist/commands/start/local/s3.d.ts +36 -31
  33. package/dist/commands/start/local/s3.js +97 -113
  34. package/dist/commands/start/local/s3.js.map +1 -1
  35. package/dist/commands/start/local.cjs +95 -122
  36. package/dist/commands/start/local.cjs.map +1 -1
  37. package/dist/commands/start/local.d.ts +34 -29
  38. package/dist/commands/start/local.js +91 -100
  39. package/dist/commands/start/local.js.map +1 -1
  40. package/dist/commands/start.cjs +18 -21
  41. package/dist/commands/start.cjs.map +1 -1
  42. package/dist/commands/start.d.ts +12 -7
  43. package/dist/commands/start.js +16 -18
  44. package/dist/commands/start.js.map +1 -1
  45. package/dist/commands/stop.cjs +22 -27
  46. package/dist/commands/stop.cjs.map +1 -1
  47. package/dist/commands/stop.d.ts +12 -7
  48. package/dist/commands/stop.js +20 -24
  49. package/dist/commands/stop.js.map +1 -1
  50. package/dist/commands/svc/create/arg-parser.cjs +102 -172
  51. package/dist/commands/svc/create/arg-parser.cjs.map +1 -1
  52. package/dist/commands/svc/create/arg-parser.js +102 -171
  53. package/dist/commands/svc/create/arg-parser.js.map +1 -1
  54. package/dist/commands/svc/create/docker/s3.cjs +78 -96
  55. package/dist/commands/svc/create/docker/s3.cjs.map +1 -1
  56. package/dist/commands/svc/create/docker/s3.d.ts +35 -30
  57. package/dist/commands/svc/create/docker/s3.js +75 -93
  58. package/dist/commands/svc/create/docker/s3.js.map +1 -1
  59. package/dist/commands/svc/create/docker.cjs +82 -103
  60. package/dist/commands/svc/create/docker.cjs.map +1 -1
  61. package/dist/commands/svc/create/docker.d.ts +35 -30
  62. package/dist/commands/svc/create/docker.js +79 -100
  63. package/dist/commands/svc/create/docker.js.map +1 -1
  64. package/dist/commands/svc/create/local/s3.cjs +107 -139
  65. package/dist/commands/svc/create/local/s3.cjs.map +1 -1
  66. package/dist/commands/svc/create/local/s3.d.ts +39 -34
  67. package/dist/commands/svc/create/local/s3.js +103 -117
  68. package/dist/commands/svc/create/local/s3.js.map +1 -1
  69. package/dist/commands/svc/create/local.cjs +101 -138
  70. package/dist/commands/svc/create/local.cjs.map +1 -1
  71. package/dist/commands/svc/create/local.d.ts +37 -32
  72. package/dist/commands/svc/create/local.js +97 -116
  73. package/dist/commands/svc/create/local.js.map +1 -1
  74. package/dist/commands/svc/delete.cjs +36 -38
  75. package/dist/commands/svc/delete.cjs.map +1 -1
  76. package/dist/commands/svc/delete.d.ts +16 -11
  77. package/dist/commands/svc/delete.js +34 -35
  78. package/dist/commands/svc/delete.js.map +1 -1
  79. package/dist/commands/svc/down.cjs +27 -30
  80. package/dist/commands/svc/down.cjs.map +1 -1
  81. package/dist/commands/svc/down.d.ts +15 -10
  82. package/dist/commands/svc/down.js +25 -27
  83. package/dist/commands/svc/down.js.map +1 -1
  84. package/dist/commands/svc/list.cjs +25 -29
  85. package/dist/commands/svc/list.cjs.map +1 -1
  86. package/dist/commands/svc/list.d.ts +9 -5
  87. package/dist/commands/svc/list.js +23 -26
  88. package/dist/commands/svc/list.js.map +1 -1
  89. package/dist/commands/svc/up.cjs +33 -49
  90. package/dist/commands/svc/up.cjs.map +1 -1
  91. package/dist/commands/svc/up.d.ts +15 -10
  92. package/dist/commands/svc/up.js +31 -46
  93. package/dist/commands/svc/up.js.map +1 -1
  94. package/dist/core.cjs +712 -881
  95. package/dist/core.cjs.map +1 -1
  96. package/dist/core.js +709 -877
  97. package/dist/core.js.map +1 -1
  98. package/dist/index.cjs +36 -36
  99. package/dist/index.cjs.map +1 -1
  100. package/dist/index.d.ts +37 -33
  101. package/dist/index.js +35 -34
  102. package/dist/index.js.map +1 -1
  103. package/dist/package.cjs +15 -36
  104. package/dist/package.cjs.map +1 -1
  105. package/dist/package.js +14 -14
  106. package/dist/package.js.map +1 -1
  107. package/dist/platforma.cjs +119 -148
  108. package/dist/platforma.cjs.map +1 -1
  109. package/dist/platforma.js +114 -122
  110. package/dist/platforma.js.map +1 -1
  111. package/dist/run.cjs +55 -58
  112. package/dist/run.cjs.map +1 -1
  113. package/dist/run.js +56 -56
  114. package/dist/run.js.map +1 -1
  115. package/dist/state.cjs +114 -141
  116. package/dist/state.cjs.map +1 -1
  117. package/dist/state.js +110 -139
  118. package/dist/state.js.map +1 -1
  119. package/dist/templates/compose.cjs +38 -65
  120. package/dist/templates/compose.cjs.map +1 -1
  121. package/dist/templates/compose.js +35 -63
  122. package/dist/templates/compose.js.map +1 -1
  123. package/dist/templates/pl-config.cjs +163 -165
  124. package/dist/templates/pl-config.cjs.map +1 -1
  125. package/dist/templates/pl-config.js +161 -163
  126. package/dist/templates/pl-config.js.map +1 -1
  127. package/dist/templates/types.cjs +24 -23
  128. package/dist/templates/types.cjs.map +1 -1
  129. package/dist/templates/types.js +24 -22
  130. package/dist/templates/types.js.map +1 -1
  131. package/dist/util.cjs +57 -74
  132. package/dist/util.cjs.map +1 -1
  133. package/dist/util.js +51 -72
  134. package/dist/util.js.map +1 -1
  135. package/package.json +6 -6
  136. package/dist/block.d.ts +0 -25
  137. package/dist/block.d.ts.map +0 -1
  138. package/dist/cmd-opts.d.ts +0 -89
  139. package/dist/cmd-opts.d.ts.map +0 -1
  140. package/dist/commands/create-block.d.ts.map +0 -1
  141. package/dist/commands/reset.d.ts.map +0 -1
  142. package/dist/commands/start/docker/s3.d.ts.map +0 -1
  143. package/dist/commands/start/docker.d.ts.map +0 -1
  144. package/dist/commands/start/local/s3.d.ts.map +0 -1
  145. package/dist/commands/start/local.d.ts.map +0 -1
  146. package/dist/commands/start.d.ts.map +0 -1
  147. package/dist/commands/stop.d.ts.map +0 -1
  148. package/dist/commands/svc/create/arg-parser.d.ts +0 -43
  149. package/dist/commands/svc/create/arg-parser.d.ts.map +0 -1
  150. package/dist/commands/svc/create/docker/s3.d.ts.map +0 -1
  151. package/dist/commands/svc/create/docker.d.ts.map +0 -1
  152. package/dist/commands/svc/create/local/s3.d.ts.map +0 -1
  153. package/dist/commands/svc/create/local.d.ts.map +0 -1
  154. package/dist/commands/svc/delete.d.ts.map +0 -1
  155. package/dist/commands/svc/down.d.ts.map +0 -1
  156. package/dist/commands/svc/list.d.ts.map +0 -1
  157. package/dist/commands/svc/up.d.ts.map +0 -1
  158. package/dist/core.d.ts +0 -105
  159. package/dist/core.d.ts.map +0 -1
  160. package/dist/index.d.ts.map +0 -1
  161. package/dist/package.d.ts +0 -7
  162. package/dist/package.d.ts.map +0 -1
  163. package/dist/platforma.d.ts +0 -24
  164. package/dist/platforma.d.ts.map +0 -1
  165. package/dist/run.d.ts +0 -13
  166. package/dist/run.d.ts.map +0 -1
  167. package/dist/state.d.ts +0 -63
  168. package/dist/state.d.ts.map +0 -1
  169. package/dist/templates/compose.d.ts +0 -14
  170. package/dist/templates/compose.d.ts.map +0 -1
  171. package/dist/templates/pl-config.d.ts +0 -6
  172. package/dist/templates/pl-config.d.ts.map +0 -1
  173. package/dist/templates/types.d.ts +0 -138
  174. package/dist/templates/types.d.ts.map +0 -1
  175. package/dist/util.d.ts +0 -18
  176. package/dist/util.d.ts.map +0 -1
package/dist/core.cjs CHANGED
@@ -1,761 +1,637 @@
1
- 'use strict';
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ const require_util = require('./util.cjs');
3
+ const require_package = require('./package.cjs');
4
+ const require_state = require('./state.cjs');
5
+ const require_run = require('./run.cjs');
6
+ const require_compose = require('./templates/compose.cjs');
7
+ const require_pl_config = require('./templates/pl-config.cjs');
8
+ const require_platforma = require('./platforma.cjs');
9
+ let node_os = require("node:os");
10
+ node_os = require_runtime.__toESM(node_os);
11
+ let node_fs = require("node:fs");
12
+ node_fs = require_runtime.__toESM(node_fs);
13
+ let node_path = require("node:path");
14
+ node_path = require_runtime.__toESM(node_path);
2
15
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var fs = require('node:fs');
6
- var os = require('node:os');
7
- var path = require('node:path');
8
- var _package = require('./package.cjs');
9
- var run = require('./run.cjs');
10
- var compose = require('./templates/compose.cjs');
11
- var plConfig = require('./templates/pl-config.cjs');
12
- var platforma = require('./platforma.cjs');
13
- var state = require('./state.cjs');
14
- var util = require('./util.cjs');
15
-
16
- class Core {
17
- logger;
18
- constructor(logger) {
19
- this.logger = logger;
20
- }
21
- startLast() {
22
- const instance = state.currentInstance;
23
- if (!instance) {
24
- this.logger.error("failed to bring back Platforma Backend in the last started configuration: no last configuration found");
25
- throw new Error("no previous run info found");
26
- }
27
- return this.startInstance(instance);
28
- }
29
- startInstance(instance) {
30
- if (instance.runInfo) {
31
- const runInfo = this.renderRunInfo(instance.runInfo);
32
- this.logger.info(`Starting platforma backend instance '${instance.name}':\n${runInfo}`);
33
- }
34
- const result = run.runCommands(this.logger, instance.upCommands);
35
- checkRunError(result.executed);
36
- if (result.spawned.length > 0 && instance.type === "process") {
37
- instance.pid = result.spawned[result.spawned.length - 1].pid;
38
- state.setInstanceInfo(instance.name, instance);
39
- this.logger.info(`instance '${instance.name}' started`);
40
- }
41
- state.currentInstanceName = instance.name;
42
- return result.spawned;
43
- }
44
- stopInstance(instance) {
45
- this.logger.info(`stopping platforma backend instance '${instance.name}'...`);
46
- const result = run.runCommands(this.logger, instance.downCommands);
47
- checkRunError(result.executed);
48
- const iType = instance.type;
49
- switch (iType) {
50
- case "docker": {
51
- return;
52
- }
53
- case "process": {
54
- if (instance.pid && state.isInstanceActive(instance)) {
55
- process.kill(instance.pid);
56
- }
57
- return;
58
- }
59
- default:
60
- util.assertNever();
61
- }
62
- }
63
- switchInstance(instance) {
64
- // Stop all other active instances before switching to new one;
65
- for (const iName of state.instanceList) {
66
- if (iName !== instance.name) {
67
- const iToStop = state.getInstanceInfo(iName);
68
- if (state.isInstanceActive(iToStop)) {
69
- this.stopInstance(iToStop);
70
- }
71
- }
72
- }
73
- return this.startInstance(instance);
74
- }
75
- createLocal(instanceName, options) {
76
- let plBinaryPath = platforma.binaryPath(options?.version, "binaries", "platforma");
77
- if (options?.sourcesPath) {
78
- plBinaryPath = path.join(os.tmpdir(), "platforma-custom-build");
79
- }
80
- if (options?.binaryPath) {
81
- plBinaryPath = options.binaryPath;
82
- }
83
- let configPath = options?.configPath;
84
- const workdir = options?.workdir ?? (configPath ? process.cwd() : state.instanceDir(instanceName));
85
- if (options?.primaryURL) {
86
- options.configOptions = {
87
- ...options.configOptions,
88
- storages: {
89
- ...options.configOptions?.storages,
90
- primary: plConfig.storageSettingsFromURL(options.primaryURL, workdir, options.configOptions?.storages?.primary),
91
- },
92
- };
93
- }
94
- if (options?.libraryURL) {
95
- options.configOptions = {
96
- ...options.configOptions,
97
- storages: {
98
- ...options.configOptions?.storages,
99
- library: plConfig.storageSettingsFromURL(options.libraryURL, workdir, options.configOptions?.storages?.library),
100
- },
101
- };
102
- }
103
- const configOptions = plConfig.loadDefaults(this.getLastJwt(), options?.configOptions);
104
- this.logger.debug(` checking license...`);
105
- this.checkLicense(options?.configOptions?.license?.value, options?.configOptions?.license?.file);
106
- const storageDirs = [
107
- `${configOptions.localRoot}/packages`,
108
- `${configOptions.localRoot}/packages-local`,
109
- `${configOptions.localRoot}/blocks-local`,
110
- ];
111
- if (configOptions.storages.primary.type === "FS") {
112
- storageDirs.push(configOptions.storages.primary.rootPath);
113
- }
114
- if (configOptions.storages.library.type === "FS") {
115
- storageDirs.push(configOptions.storages.library.rootPath);
116
- configOptions.hacks.libraryDownloadable = false;
117
- }
118
- if (configOptions.storages.work.type === "FS") {
119
- storageDirs.push(configOptions.storages.work.rootPath);
120
- }
121
- this.logger.debug(" creating pl state directories...");
122
- for (const dir of storageDirs) {
123
- if (!fs.existsSync(dir)) {
124
- this.logger.debug(` '${dir}'`);
125
- fs.mkdirSync(dir, { recursive: true });
126
- }
127
- }
128
- for (const drv of configOptions.core.auth.drivers) {
129
- if (drv.driver === "htpasswd") {
130
- if (!fs.existsSync(drv.path)) {
131
- this.logger.debug(` installing default 'users.htpasswd' to ${drv.path}...`);
132
- fs.copyFileSync(_package.assets("users.htpasswd"), drv.path);
133
- }
134
- }
135
- }
136
- if (!configPath) {
137
- configPath = path.join(configOptions.localRoot, "config.yaml");
138
- this.logger.debug(` rendering configuration '${configPath}'...`);
139
- fs.writeFileSync(configPath, plConfig.render(configOptions));
140
- }
141
- const upCommands = [];
142
- if (options?.sourcesPath) {
143
- upCommands.push({
144
- cmd: "go",
145
- args: ["build", "-o", plBinaryPath, "."],
146
- workdir: path.resolve(options.sourcesPath, "cmd", "platforma"),
147
- runOpts: {
148
- stdio: "inherit",
149
- },
150
- });
151
- }
152
- const runBinary = {
153
- async: true,
154
- cmd: plBinaryPath,
155
- args: ["--quiet", "--config", configPath],
156
- workdir: workdir,
157
- runOpts: {
158
- stdio: "inherit",
159
- },
160
- };
161
- if (options?.configOptions?.numCpu) {
162
- runBinary.runOpts.env = {
163
- GOMAXPROCS: String(options?.configOptions?.numCpu),
164
- };
165
- }
166
- // Process additional environment variables from CLI options
167
- if (options?.backendCommands) {
168
- if (!runBinary.runOpts.env) {
169
- runBinary.runOpts.env = {};
170
- }
171
- for (const cmd of options.backendCommands) {
172
- const equalIndex = cmd.indexOf("=");
173
- if (equalIndex > 0) {
174
- const key = cmd.substring(0, equalIndex);
175
- const value = cmd.substring(equalIndex + 1);
176
- runBinary.runOpts.env[key] = value;
177
- }
178
- else {
179
- this.logger.warn(`Invalid environment variable format: ${cmd}. Expected format: KEY=VALUE`);
180
- }
181
- }
182
- }
183
- // Process additional backend commands
184
- if (options?.backendCommands && options.backendCommands.length > 0) {
185
- this.logger.debug(`Adding backend commands: ${options.backendCommands.join(" ")}`);
186
- // Add commands as arguments to the binary
187
- runBinary.args = [...runBinary.args, ...options.backendCommands];
188
- }
189
- upCommands.push(runBinary);
190
- state.setInstanceInfo(instanceName, {
191
- type: "process",
192
- upCommands: upCommands,
193
- downCommands: [],
194
- cleanupCommands: [],
195
- runInfo: {
196
- configPath,
197
- dbPath: configOptions.core.db.path,
198
- apiAddr: configOptions.grpc.listen,
199
- logPath: configOptions.log.path,
200
- primary: configOptions.storages.primary,
201
- work: configOptions.storages.work,
202
- library: configOptions.storages.library,
203
- },
204
- });
205
- return state.getInstanceInfo(instanceName);
206
- }
207
- createLocalS3(instanceName, options) {
208
- this.logger.debug("creating platforma instance in 'local s3' mode...");
209
- const minioPort = options?.minioPort ?? 9000;
210
- const instance = this.createLocal(instanceName, {
211
- ...options,
212
- primaryURL: options?.primaryURL ??
213
- `s3e://testuser:testpassword@localhost:${minioPort}/platforma-primary-bucket/?region=no-region`,
214
- libraryURL: options?.libraryURL ??
215
- `s3e://testuser:testpassword@localhost:${minioPort}/platforma-library-bucket/?region=no-region`,
216
- });
217
- const localRoot = options?.configOptions?.localRoot;
218
- const minioRunCmd = this.createMinio(instanceName, {
219
- minioPort: minioPort,
220
- minioConsolePort: options?.minioConsolePort,
221
- storage: localRoot ? path.join(localRoot, "minio") : undefined,
222
- });
223
- instance.upCommands = [minioRunCmd.start, ...instance.upCommands];
224
- instance.downCommands = [minioRunCmd.stop, ...instance.downCommands];
225
- instance.cleanupCommands = [minioRunCmd.cleanup, ...instance.cleanupCommands];
226
- state.setInstanceInfo(instanceName, instance);
227
- return instance;
228
- }
229
- createMinio(instanceName, options) {
230
- this.logger.debug(" creating docker compose for minio service...");
231
- const composeSrc = _package.assets("compose-backend.yaml");
232
- const composeMinio = state.instanceDir(instanceName, "compose-minio.yaml");
233
- compose.render(composeSrc, composeMinio, `pl-${instanceName}-minio`, new Map([["minio", {}]]), { dropVolumes: true });
234
- const version = options?.version ? `:${options.version}` : "";
235
- this.logger.debug(` minio version: ${version}`);
236
- const image = options?.image ?? `quay.io/minio/minio${version}`;
237
- this.logger.debug(` minio image: ${image}`);
238
- const storage = options?.storage ?? state.instanceDir(instanceName, "minio");
239
- util.ensureDir(storage, { mode: "0775" });
240
- const minioPort = options?.minioPort ?? 9000;
241
- const minioConsolePort = options?.minioConsolePort ?? 9001;
242
- const envs = {
243
- MINIO_IMAGE: image,
244
- MINIO_STORAGE: path.resolve(storage),
245
- MINIO_PORT: minioPort.toString(),
246
- MINIO_CONSOLE_PORT: minioConsolePort.toString(),
247
- };
248
- return {
249
- start: {
250
- cmd: "docker",
251
- args: [
252
- "compose",
253
- `--file=${composeMinio}`,
254
- "up",
255
- "--detach",
256
- "--remove-orphans",
257
- "--pull=missing",
258
- ],
259
- envs: envs,
260
- workdir: state.instanceDir(instanceName),
261
- runOpts: { stdio: "inherit" },
262
- },
263
- stop: {
264
- cmd: "docker",
265
- args: ["compose", `--file=${composeMinio}`, "down"],
266
- envs: envs,
267
- workdir: state.instanceDir(instanceName),
268
- runOpts: { stdio: "inherit" },
269
- },
270
- cleanup: {
271
- cmd: "docker",
272
- args: ["compose", `--file=${composeMinio}`, "down", "--volumes", "--remove-orphans"],
273
- envs: envs,
274
- workdir: state.instanceDir(instanceName),
275
- runOpts: { stdio: "inherit" },
276
- },
277
- };
278
- }
279
- createDockerS3(instanceName, localRoot, options) {
280
- this.logger.debug("creating platforma instance in 'docker s3' mode...");
281
- const composeS3Path = _package.assets("compose-backend.yaml");
282
- const image = options?.image ?? _package.plImageTag(options?.version);
283
- this.checkLicense(options?.license, options?.licenseFile);
284
- const storagePath = (...s) => path.join(localRoot, ...s);
285
- const storageDir = (s) => {
286
- const p = storagePath(s);
287
- util.ensureDir(p, { mode: "0775" });
288
- return p;
289
- };
290
- const logFilePath = storagePath("logs", "platforma.log");
291
- if (!fs.existsSync(logFilePath)) {
292
- fs.mkdirSync(path.dirname(logFilePath), { recursive: true });
293
- fs.writeFileSync(logFilePath, "");
294
- }
295
- const presignHost = options?.presignHost ?? "localhost";
296
- const presignPort = options?.s3Port ?? 9000;
297
- const primary = plConfig.storageSettingsFromURL(`s3e://testuser:testpassword@minio:${presignPort}/platforma-primary-bucket`);
298
- if (primary.type !== "S3") {
299
- throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");
300
- }
301
- else {
302
- primary.presignEndpoint = `http://${presignHost}:${presignPort}`;
303
- }
304
- const library = plConfig.storageSettingsFromURL(`s3e://testuser:testpassword@minio:${presignPort}/platforma-library-bucket`);
305
- if (library.type !== "S3") {
306
- throw new Error(`${library.type} storage type is not supported for library storage`);
307
- }
308
- else {
309
- library.presignEndpoint = `http://${presignHost}:${presignPort}`;
310
- }
311
- const dbFSPath = storageDir("db");
312
- const workFSPath = storageDir("work");
313
- const usersFSPath = storagePath("users.htpasswd");
314
- if (!fs.existsSync(usersFSPath)) {
315
- fs.copyFileSync(_package.assets("users.htpasswd"), usersFSPath);
316
- }
317
- const composeDstPath = storagePath("compose.yaml");
318
- if (fs.existsSync(composeDstPath)) {
319
- this.logger.info(`replacing docker compose file ${composeDstPath}`);
320
- }
321
- const backendMounts = [];
322
- for (const mnt of options?.customMounts ?? []) {
323
- backendMounts.push({
324
- hostPath: mnt.hostPath,
325
- containerPath: mnt.containerPath ?? mnt.hostPath,
326
- });
327
- }
328
- compose.render(composeS3Path, composeDstPath, `pl-${instanceName}`, new Map([
329
- ["minio", {}],
330
- [
331
- "backend",
332
- {
333
- platform: options?.platformOverride,
334
- mounts: backendMounts,
335
- commands: options?.backendCommands,
336
- },
337
- ],
338
- ]));
339
- const envs = {
340
- MINIO_IMAGE: "quay.io/minio/minio",
341
- MINIO_STORAGE: storageDir("minio"),
342
- PL_IMAGE: image,
343
- PL_AUTH_HTPASSWD: usersFSPath,
344
- PL_LICENSE: options?.license,
345
- PL_LICENSE_FILE: options?.licenseFile,
346
- PL_LOG_LEVEL: options?.logLevel ?? "info",
347
- PL_LOG_DIR: path.dirname(logFilePath),
348
- PL_LOG_ROTATION_ENABLED: "true",
349
- PL_RUNNER_WD_CACHE_ON_FAILURE: "1h",
350
- PL_DATA_DB_ROOT: dbFSPath,
351
- PL_DATA_PRIMARY_ROOT: storageDir("primary"),
352
- PL_DATA_LIBRARY_ROOT: storageDir("library"),
353
- PL_DATA_WORKDIR_ROOT: workFSPath,
354
- // Mount packages storage as volume, because APFS is case-insensitive on Mac OS X and this breaks some pl software installation.
355
- // PL_DATA_PACKAGE_ROOT: storageDir('packages'),
356
- ...this.configureDockerStorage("primary", primary),
357
- ...this.configureDockerStorage("library", library),
358
- };
359
- if (options?.grpcAddr) {
360
- const addrParts = options.grpcAddr.split(":");
361
- if (addrParts.length === 2) {
362
- envs.PL_LISTEN_ADDRESS = addrParts[0];
363
- envs.PL_LISTEN_PORT = addrParts[1];
364
- }
365
- else {
366
- envs.PL_LISTEN_ADDRESS = options.grpcAddr;
367
- }
368
- }
369
- else if (options?.grpcPort) {
370
- envs.PL_LISTEN_PORT = options.grpcPort.toString();
371
- }
372
- if (options?.monitoringAddr) {
373
- const addrParts = options.monitoringAddr.split(":");
374
- if (addrParts.length === 2) {
375
- envs.PL_MONITORING_IP = addrParts[0];
376
- envs.PL_MONITORING_PORT = addrParts[1];
377
- }
378
- else {
379
- envs.PL_MONITORING_IP = options.monitoringAddr;
380
- }
381
- }
382
- else if (options?.monitoringPort) {
383
- envs.PL_MONITORING_PORT = options.monitoringPort.toString();
384
- }
385
- if (options?.debugAddr) {
386
- const addrParts = options.debugAddr.split(":");
387
- if (addrParts.length === 2) {
388
- envs.PL_DEBUG_IP = addrParts[0];
389
- envs.PL_DEBUG_PORT = addrParts[1];
390
- }
391
- else {
392
- envs.PL_DEBUG_IP = options.debugAddr;
393
- }
394
- }
395
- else if (options?.debugPort) {
396
- envs.PL_DEBUG_PORT = options.debugPort.toString();
397
- }
398
- if (options?.s3Port)
399
- envs.MINIO_PORT = options.s3Port.toString();
400
- if (options?.s3ConsolePort)
401
- envs.MINIO_CONSOLE_PORT = options.s3ConsolePort.toString();
402
- if (options?.auth) {
403
- if (options.auth.enabled) {
404
- envs["PL_NO_AUTH"] = "false";
405
- }
406
- else {
407
- envs["PL_NO_AUTH"] = "true";
408
- }
409
- if (options.auth.drivers) {
410
- for (const drv of options.auth.drivers) {
411
- if (drv.driver === "htpasswd") {
412
- envs["PL_AUTH_HTPASSWD"] = path.resolve(drv.path);
413
- drv.path = "/etc/platforma/users.htpasswd";
414
- }
415
- }
416
- envs["PL_AUTH_DRIVERS"] = JSON.stringify(options.auth.drivers);
417
- }
418
- }
419
- // Process additional backend commands
420
- if (options?.backendCommands && options.backendCommands.length > 0) {
421
- this.logger.debug(`Adding backend commands: ${options.backendCommands.join(" ")}`);
422
- }
423
- state.setInstanceInfo(instanceName, {
424
- type: "docker",
425
- upCommands: [
426
- {
427
- cmd: "docker",
428
- args: [
429
- "compose",
430
- `--file=${composeDstPath}`,
431
- "up",
432
- "--detach",
433
- "--remove-orphans",
434
- "--pull=missing",
435
- ],
436
- envs: envs,
437
- runOpts: { stdio: "inherit" },
438
- },
439
- ],
440
- downCommands: [
441
- {
442
- cmd: "docker",
443
- args: ["compose", `--file=${composeDstPath}`, "down"],
444
- envs: envs,
445
- runOpts: { stdio: "inherit" },
446
- },
447
- ],
448
- cleanupCommands: [
449
- {
450
- cmd: "docker",
451
- args: ["compose", `--file=${composeDstPath}`, "down", "--volumes", "--remove-orphans"],
452
- envs: envs,
453
- runOpts: { stdio: "inherit" },
454
- },
455
- ],
456
- runInfo: {
457
- apiPort: options?.grpcPort,
458
- apiAddr: options?.grpcAddr,
459
- logPath: logFilePath,
460
- primary: primary,
461
- work: { type: "FS", rootPath: workFSPath },
462
- library: library,
463
- dbPath: dbFSPath,
464
- },
465
- });
466
- return state.getInstanceInfo(instanceName);
467
- }
468
- createDocker(instanceName, localRoot, options) {
469
- this.logger.debug("creating platforma instance in 'docker' mode...");
470
- const composeFSPath = _package.assets("compose-backend.yaml");
471
- const image = options?.image ?? _package.plImageTag(options?.version);
472
- this.checkLicense(options?.license, options?.licenseFile);
473
- const storagePath = (...s) => path.join(localRoot, ...s);
474
- const storageDir = (s) => {
475
- const p = storagePath(s);
476
- util.ensureDir(p, { mode: "0775" });
477
- return p;
478
- };
479
- const logFilePath = storagePath("logs", "platforma.log");
480
- if (!fs.existsSync(logFilePath)) {
481
- fs.mkdirSync(path.dirname(logFilePath), { recursive: true });
482
- fs.writeFileSync(logFilePath, "");
483
- }
484
- const dbFSPath = storageDir("db");
485
- const primaryFSPath = storageDir("primary");
486
- const libraryFSPath = storageDir("library");
487
- const workFSPath = storageDir("work");
488
- const usersFSPath = storagePath("users.htpasswd");
489
- if (!fs.existsSync(usersFSPath)) {
490
- fs.copyFileSync(_package.assets("users.htpasswd"), usersFSPath);
491
- }
492
- const composeDstPath = storagePath("compose.yaml");
493
- if (fs.existsSync(composeDstPath)) {
494
- this.logger.info(`replacing docker compose file ${composeDstPath}`);
495
- }
496
- const backendMounts = [];
497
- for (const mnt of options?.customMounts ?? []) {
498
- backendMounts.push({
499
- hostPath: mnt.hostPath,
500
- containerPath: mnt.containerPath ?? mnt.hostPath,
501
- });
502
- }
503
- this.logger.debug(`Rendering docker compose file '${composeDstPath}' using '${composeFSPath}' as base template`);
504
- compose.render(composeFSPath, composeDstPath, `pl-${instanceName}`, new Map([
505
- [
506
- "backend",
507
- {
508
- platform: options?.platformOverride,
509
- mounts: backendMounts,
510
- commands: options?.backendCommands,
511
- },
512
- ],
513
- ]));
514
- const primary = plConfig.storageSettingsFromURL(options?.primaryStorageURL ?? `file:${primaryFSPath}`, ".");
515
- const library = plConfig.storageSettingsFromURL(options?.libraryStorageURL ?? `file:${libraryFSPath}`, ".");
516
- const envs = {
517
- PL_IMAGE: image,
518
- PL_AUTH_HTPASSWD: usersFSPath,
519
- PL_LICENSE: options?.license,
520
- PL_LICENSE_FILE: options?.licenseFile,
521
- PL_LOG_LEVEL: options?.logLevel ?? "info",
522
- PL_LOG_DIR: path.dirname(logFilePath),
523
- PL_LOG_ROTATION_ENABLED: "true",
524
- PL_RUNNER_WD_CACHE_ON_FAILURE: "1h",
525
- PL_DATA_DB_ROOT: dbFSPath,
526
- PL_DATA_PRIMARY_ROOT: primaryFSPath,
527
- PL_DATA_LIBRARY_ROOT: libraryFSPath,
528
- PL_DATA_WORKDIR_ROOT: workFSPath,
529
- PL_DATA_PACKAGE_ROOT: storageDir("packages"),
530
- ...this.configureDockerStorage("primary", primary),
531
- ...this.configureDockerStorage("library", library),
532
- };
533
- if (options?.grpcAddr) {
534
- const addrParts = options.grpcAddr.split(":");
535
- if (addrParts.length === 2) {
536
- envs.PL_LISTEN_ADDRESS = addrParts[0];
537
- envs.PL_LISTEN_PORT = addrParts[1];
538
- }
539
- else {
540
- envs.PL_LISTEN_ADDRESS = options.grpcAddr;
541
- }
542
- }
543
- else if (options?.grpcPort) {
544
- envs.PL_LISTEN_PORT = options.grpcPort.toString();
545
- }
546
- if (options?.monitoringAddr) {
547
- const addrParts = options.monitoringAddr.split(":");
548
- if (addrParts.length === 2) {
549
- envs.PL_MONITORING_IP = addrParts[0];
550
- envs.PL_MONITORING_PORT = addrParts[1];
551
- }
552
- else {
553
- envs.PL_MONITORING_IP = options.monitoringAddr;
554
- }
555
- }
556
- else if (options?.monitoringPort) {
557
- envs.PL_MONITORING_PORT = options.monitoringPort.toString();
558
- }
559
- if (options?.debugAddr) {
560
- const addrParts = options.debugAddr.split(":");
561
- if (addrParts.length === 2) {
562
- envs.PL_DEBUG_IP = addrParts[0];
563
- envs.PL_DEBUG_PORT = addrParts[1];
564
- }
565
- else {
566
- envs.PL_DEBUG_IP = options.debugAddr;
567
- }
568
- }
569
- else if (options?.debugPort) {
570
- envs.PL_DEBUG_PORT = options.debugPort.toString();
571
- }
572
- if (options?.auth) {
573
- if (options.auth.enabled) {
574
- envs["PL_NO_AUTH"] = "false";
575
- }
576
- else {
577
- envs["PL_NO_AUTH"] = "true";
578
- }
579
- if (options.auth.drivers) {
580
- for (const drv of options.auth.drivers) {
581
- if (drv.driver === "htpasswd") {
582
- envs["PL_AUTH_HTPASSWD"] = path.resolve(drv.path);
583
- drv.path = "/etc/platforma/users.htpasswd";
584
- }
585
- }
586
- envs["PL_AUTH_DRIVERS"] = JSON.stringify(options.auth.drivers);
587
- }
588
- }
589
- // Process additional backend commands
590
- if (options?.backendCommands && options.backendCommands.length > 0) {
591
- this.logger.debug(`Adding backend commands: ${options.backendCommands.join(" ")}`);
592
- }
593
- state.setInstanceInfo(instanceName, {
594
- type: "docker",
595
- upCommands: [
596
- {
597
- cmd: "docker",
598
- args: [
599
- "compose",
600
- `--file=${composeDstPath}`,
601
- "up",
602
- "--detach",
603
- "--remove-orphans",
604
- "--pull=missing",
605
- ],
606
- envs: envs,
607
- runOpts: { stdio: "inherit" },
608
- },
609
- ],
610
- downCommands: [
611
- {
612
- cmd: "docker",
613
- args: ["compose", `--file=${composeDstPath}`, "down"],
614
- envs: envs,
615
- runOpts: { stdio: "inherit" },
616
- },
617
- ],
618
- cleanupCommands: [
619
- {
620
- cmd: "docker",
621
- args: ["compose", `--file=${composeDstPath}`, "down", "--volumes", "--remove-orphans"],
622
- envs: envs,
623
- runOpts: { stdio: "inherit" },
624
- },
625
- ],
626
- runInfo: {
627
- apiPort: options?.grpcPort,
628
- apiAddr: options?.grpcAddr,
629
- logPath: logFilePath,
630
- primary: primary,
631
- work: { type: "FS", rootPath: workFSPath },
632
- library: library,
633
- dbPath: dbFSPath,
634
- },
635
- });
636
- return state.getInstanceInfo(instanceName);
637
- }
638
- cleanupInstance(instanceName) {
639
- const removeWarns = [];
640
- const instancesToDrop = new Map();
641
- let warnMessage = "";
642
- if (instanceName) {
643
- const instance = state.getInstanceInfo(instanceName);
644
- instancesToDrop.set(instanceName, instance);
645
- const iType = instance.type;
646
- switch (iType) {
647
- case "docker": {
648
- removeWarns.push(`docker service 'pl-${instanceName}', including all its volumes and data in '${state.instanceDir(instanceName)}' will be destroyed`);
649
- break;
650
- }
651
- case "process": {
652
- removeWarns.push(`directory '${state.instanceDir(instanceName)}' would be deleted`);
653
- if (instance.downCommands) {
654
- removeWarns.push(`associated docker service, including all volumes and data will be destroyed`);
655
- }
656
- break;
657
- }
658
- default:
659
- util.assertNever();
660
- }
661
- if (instanceName === state.currentInstanceName) {
662
- removeWarns.push("last command run cache ('pl-dev start' shorthand will stop working until next full start command call)");
663
- }
664
- warnMessage = `
16
+ //#region src/core.ts
17
+ var Core = class {
18
+ constructor(logger) {
19
+ this.logger = logger;
20
+ }
21
+ startLast() {
22
+ const instance = require_state.default.currentInstance;
23
+ if (!instance) {
24
+ this.logger.error("failed to bring back Platforma Backend in the last started configuration: no last configuration found");
25
+ throw new Error("no previous run info found");
26
+ }
27
+ return this.startInstance(instance);
28
+ }
29
+ startInstance(instance) {
30
+ if (instance.runInfo) {
31
+ const runInfo = this.renderRunInfo(instance.runInfo);
32
+ this.logger.info(`Starting platforma backend instance '${instance.name}':\n${runInfo}`);
33
+ }
34
+ const result = require_run.runCommands(this.logger, instance.upCommands);
35
+ checkRunError(result.executed);
36
+ if (result.spawned.length > 0 && instance.type === "process") {
37
+ instance.pid = result.spawned[result.spawned.length - 1].pid;
38
+ require_state.default.setInstanceInfo(instance.name, instance);
39
+ this.logger.info(`instance '${instance.name}' started`);
40
+ }
41
+ require_state.default.currentInstanceName = instance.name;
42
+ return result.spawned;
43
+ }
44
+ stopInstance(instance) {
45
+ this.logger.info(`stopping platforma backend instance '${instance.name}'...`);
46
+ checkRunError(require_run.runCommands(this.logger, instance.downCommands).executed);
47
+ const iType = instance.type;
48
+ switch (iType) {
49
+ case "docker": return;
50
+ case "process":
51
+ if (instance.pid && require_state.default.isInstanceActive(instance)) process.kill(instance.pid);
52
+ return;
53
+ default: require_util.assertNever(iType);
54
+ }
55
+ }
56
+ switchInstance(instance) {
57
+ for (const iName of require_state.default.instanceList) if (iName !== instance.name) {
58
+ const iToStop = require_state.default.getInstanceInfo(iName);
59
+ if (require_state.default.isInstanceActive(iToStop)) this.stopInstance(iToStop);
60
+ }
61
+ return this.startInstance(instance);
62
+ }
63
+ createLocal(instanceName, options) {
64
+ let plBinaryPath = require_platforma.binaryPath(options?.version, "binaries", "platforma");
65
+ if (options?.sourcesPath) plBinaryPath = node_path.default.join(node_os.default.tmpdir(), "platforma-custom-build");
66
+ if (options?.binaryPath) plBinaryPath = options.binaryPath;
67
+ let configPath = options?.configPath;
68
+ const workdir = options?.workdir ?? (configPath ? process.cwd() : require_state.default.instanceDir(instanceName));
69
+ if (options?.primaryURL) options.configOptions = {
70
+ ...options.configOptions,
71
+ storages: {
72
+ ...options.configOptions?.storages,
73
+ primary: require_pl_config.storageSettingsFromURL(options.primaryURL, workdir, options.configOptions?.storages?.primary)
74
+ }
75
+ };
76
+ if (options?.libraryURL) options.configOptions = {
77
+ ...options.configOptions,
78
+ storages: {
79
+ ...options.configOptions?.storages,
80
+ library: require_pl_config.storageSettingsFromURL(options.libraryURL, workdir, options.configOptions?.storages?.library)
81
+ }
82
+ };
83
+ const configOptions = require_pl_config.loadDefaults(this.getLastJwt(), options?.configOptions);
84
+ this.logger.debug(` checking license...`);
85
+ this.checkLicense(options?.configOptions?.license?.value, options?.configOptions?.license?.file);
86
+ const storageDirs = [
87
+ `${configOptions.localRoot}/packages`,
88
+ `${configOptions.localRoot}/packages-local`,
89
+ `${configOptions.localRoot}/blocks-local`
90
+ ];
91
+ if (configOptions.storages.primary.type === "FS") storageDirs.push(configOptions.storages.primary.rootPath);
92
+ if (configOptions.storages.library.type === "FS") {
93
+ storageDirs.push(configOptions.storages.library.rootPath);
94
+ configOptions.hacks.libraryDownloadable = false;
95
+ }
96
+ if (configOptions.storages.work.type === "FS") storageDirs.push(configOptions.storages.work.rootPath);
97
+ this.logger.debug(" creating pl state directories...");
98
+ for (const dir of storageDirs) if (!node_fs.default.existsSync(dir)) {
99
+ this.logger.debug(` '${dir}'`);
100
+ node_fs.default.mkdirSync(dir, { recursive: true });
101
+ }
102
+ for (const drv of configOptions.core.auth.drivers) if (drv.driver === "htpasswd") {
103
+ if (!node_fs.default.existsSync(drv.path)) {
104
+ this.logger.debug(` installing default 'users.htpasswd' to ${drv.path}...`);
105
+ node_fs.default.copyFileSync(require_package.assets("users.htpasswd"), drv.path);
106
+ }
107
+ }
108
+ if (!configPath) {
109
+ configPath = node_path.default.join(configOptions.localRoot, "config.yaml");
110
+ this.logger.debug(` rendering configuration '${configPath}'...`);
111
+ node_fs.default.writeFileSync(configPath, require_pl_config.render(configOptions));
112
+ }
113
+ const upCommands = [];
114
+ if (options?.sourcesPath) upCommands.push({
115
+ cmd: "go",
116
+ args: [
117
+ "build",
118
+ "-o",
119
+ plBinaryPath,
120
+ "."
121
+ ],
122
+ workdir: node_path.default.resolve(options.sourcesPath, "cmd", "platforma"),
123
+ runOpts: { stdio: "inherit" }
124
+ });
125
+ const runBinary = {
126
+ async: true,
127
+ cmd: plBinaryPath,
128
+ args: [
129
+ "--quiet",
130
+ "--config",
131
+ configPath
132
+ ],
133
+ workdir,
134
+ runOpts: { stdio: "inherit" }
135
+ };
136
+ if (options?.configOptions?.numCpu) runBinary.runOpts.env = { GOMAXPROCS: String(options?.configOptions?.numCpu) };
137
+ if (options?.backendCommands) {
138
+ if (!runBinary.runOpts.env) runBinary.runOpts.env = {};
139
+ for (const cmd of options.backendCommands) {
140
+ const equalIndex = cmd.indexOf("=");
141
+ if (equalIndex > 0) {
142
+ const key = cmd.substring(0, equalIndex);
143
+ const value = cmd.substring(equalIndex + 1);
144
+ runBinary.runOpts.env[key] = value;
145
+ } else this.logger.warn(`Invalid environment variable format: ${cmd}. Expected format: KEY=VALUE`);
146
+ }
147
+ }
148
+ if (options?.backendCommands && options.backendCommands.length > 0) {
149
+ this.logger.debug(`Adding backend commands: ${options.backendCommands.join(" ")}`);
150
+ runBinary.args = [...runBinary.args, ...options.backendCommands];
151
+ }
152
+ upCommands.push(runBinary);
153
+ require_state.default.setInstanceInfo(instanceName, {
154
+ type: "process",
155
+ upCommands,
156
+ downCommands: [],
157
+ cleanupCommands: [],
158
+ runInfo: {
159
+ configPath,
160
+ dbPath: configOptions.core.db.path,
161
+ apiAddr: configOptions.grpc.listen,
162
+ logPath: configOptions.log.path,
163
+ primary: configOptions.storages.primary,
164
+ work: configOptions.storages.work,
165
+ library: configOptions.storages.library
166
+ }
167
+ });
168
+ return require_state.default.getInstanceInfo(instanceName);
169
+ }
170
+ createLocalS3(instanceName, options) {
171
+ this.logger.debug("creating platforma instance in 'local s3' mode...");
172
+ const minioPort = options?.minioPort ?? 9e3;
173
+ const instance = this.createLocal(instanceName, {
174
+ ...options,
175
+ primaryURL: options?.primaryURL ?? `s3e://testuser:testpassword@localhost:${minioPort}/platforma-primary-bucket/?region=no-region`,
176
+ libraryURL: options?.libraryURL ?? `s3e://testuser:testpassword@localhost:${minioPort}/platforma-library-bucket/?region=no-region`
177
+ });
178
+ const localRoot = options?.configOptions?.localRoot;
179
+ const minioRunCmd = this.createMinio(instanceName, {
180
+ minioPort,
181
+ minioConsolePort: options?.minioConsolePort,
182
+ storage: localRoot ? node_path.default.join(localRoot, "minio") : void 0
183
+ });
184
+ instance.upCommands = [minioRunCmd.start, ...instance.upCommands];
185
+ instance.downCommands = [minioRunCmd.stop, ...instance.downCommands];
186
+ instance.cleanupCommands = [minioRunCmd.cleanup, ...instance.cleanupCommands];
187
+ require_state.default.setInstanceInfo(instanceName, instance);
188
+ return instance;
189
+ }
190
+ createMinio(instanceName, options) {
191
+ this.logger.debug(" creating docker compose for minio service...");
192
+ const composeSrc = require_package.assets("compose-backend.yaml");
193
+ const composeMinio = require_state.default.instanceDir(instanceName, "compose-minio.yaml");
194
+ require_compose.render(composeSrc, composeMinio, `pl-${instanceName}-minio`, new Map([["minio", {}]]), { dropVolumes: true });
195
+ const version = options?.version ? `:${options.version}` : "";
196
+ this.logger.debug(` minio version: ${version}`);
197
+ const image = options?.image ?? `quay.io/minio/minio${version}`;
198
+ this.logger.debug(` minio image: ${image}`);
199
+ const storage = options?.storage ?? require_state.default.instanceDir(instanceName, "minio");
200
+ require_util.ensureDir(storage, { mode: "0775" });
201
+ const minioPort = options?.minioPort ?? 9e3;
202
+ const minioConsolePort = options?.minioConsolePort ?? 9001;
203
+ const envs = {
204
+ MINIO_IMAGE: image,
205
+ MINIO_STORAGE: node_path.default.resolve(storage),
206
+ MINIO_PORT: minioPort.toString(),
207
+ MINIO_CONSOLE_PORT: minioConsolePort.toString()
208
+ };
209
+ return {
210
+ start: {
211
+ cmd: "docker",
212
+ args: [
213
+ "compose",
214
+ `--file=${composeMinio}`,
215
+ "up",
216
+ "--detach",
217
+ "--remove-orphans",
218
+ "--pull=missing"
219
+ ],
220
+ envs,
221
+ workdir: require_state.default.instanceDir(instanceName),
222
+ runOpts: { stdio: "inherit" }
223
+ },
224
+ stop: {
225
+ cmd: "docker",
226
+ args: [
227
+ "compose",
228
+ `--file=${composeMinio}`,
229
+ "down"
230
+ ],
231
+ envs,
232
+ workdir: require_state.default.instanceDir(instanceName),
233
+ runOpts: { stdio: "inherit" }
234
+ },
235
+ cleanup: {
236
+ cmd: "docker",
237
+ args: [
238
+ "compose",
239
+ `--file=${composeMinio}`,
240
+ "down",
241
+ "--volumes",
242
+ "--remove-orphans"
243
+ ],
244
+ envs,
245
+ workdir: require_state.default.instanceDir(instanceName),
246
+ runOpts: { stdio: "inherit" }
247
+ }
248
+ };
249
+ }
250
+ createDockerS3(instanceName, localRoot, options) {
251
+ this.logger.debug("creating platforma instance in 'docker s3' mode...");
252
+ const composeS3Path = require_package.assets("compose-backend.yaml");
253
+ const image = options?.image ?? require_package.plImageTag(options?.version);
254
+ this.checkLicense(options?.license, options?.licenseFile);
255
+ const storagePath = (...s) => node_path.default.join(localRoot, ...s);
256
+ const storageDir = (s) => {
257
+ const p = storagePath(s);
258
+ require_util.ensureDir(p, { mode: "0775" });
259
+ return p;
260
+ };
261
+ const logFilePath = storagePath("logs", "platforma.log");
262
+ if (!node_fs.default.existsSync(logFilePath)) {
263
+ node_fs.default.mkdirSync(node_path.default.dirname(logFilePath), { recursive: true });
264
+ node_fs.default.writeFileSync(logFilePath, "");
265
+ }
266
+ const presignHost = options?.presignHost ?? "localhost";
267
+ const presignPort = options?.s3Port ?? 9e3;
268
+ const primary = require_pl_config.storageSettingsFromURL(`s3e://testuser:testpassword@minio:${presignPort}/platforma-primary-bucket`);
269
+ if (primary.type !== "S3") throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");
270
+ else primary.presignEndpoint = `http://${presignHost}:${presignPort}`;
271
+ const library = require_pl_config.storageSettingsFromURL(`s3e://testuser:testpassword@minio:${presignPort}/platforma-library-bucket`);
272
+ if (library.type !== "S3") throw new Error(`${library.type} storage type is not supported for library storage`);
273
+ else library.presignEndpoint = `http://${presignHost}:${presignPort}`;
274
+ const dbFSPath = storageDir("db");
275
+ const workFSPath = storageDir("work");
276
+ const usersFSPath = storagePath("users.htpasswd");
277
+ if (!node_fs.default.existsSync(usersFSPath)) node_fs.default.copyFileSync(require_package.assets("users.htpasswd"), usersFSPath);
278
+ const composeDstPath = storagePath("compose.yaml");
279
+ if (node_fs.default.existsSync(composeDstPath)) this.logger.info(`replacing docker compose file ${composeDstPath}`);
280
+ const backendMounts = [];
281
+ for (const mnt of options?.customMounts ?? []) backendMounts.push({
282
+ hostPath: mnt.hostPath,
283
+ containerPath: mnt.containerPath ?? mnt.hostPath
284
+ });
285
+ require_compose.render(composeS3Path, composeDstPath, `pl-${instanceName}`, new Map([["minio", {}], ["backend", {
286
+ platform: options?.platformOverride,
287
+ mounts: backendMounts,
288
+ commands: options?.backendCommands
289
+ }]]));
290
+ const envs = {
291
+ MINIO_IMAGE: "quay.io/minio/minio",
292
+ MINIO_STORAGE: storageDir("minio"),
293
+ PL_IMAGE: image,
294
+ PL_AUTH_HTPASSWD: usersFSPath,
295
+ PL_LICENSE: options?.license,
296
+ PL_LICENSE_FILE: options?.licenseFile,
297
+ PL_LOG_LEVEL: options?.logLevel ?? "info",
298
+ PL_LOG_DIR: node_path.default.dirname(logFilePath),
299
+ PL_LOG_ROTATION_ENABLED: "true",
300
+ PL_RUNNER_WD_CACHE_ON_FAILURE: "1h",
301
+ PL_DATA_DB_ROOT: dbFSPath,
302
+ PL_DATA_PRIMARY_ROOT: storageDir("primary"),
303
+ PL_DATA_LIBRARY_ROOT: storageDir("library"),
304
+ PL_DATA_WORKDIR_ROOT: workFSPath,
305
+ ...this.configureDockerStorage("primary", primary),
306
+ ...this.configureDockerStorage("library", library)
307
+ };
308
+ if (options?.grpcAddr) {
309
+ const addrParts = options.grpcAddr.split(":");
310
+ if (addrParts.length === 2) {
311
+ envs.PL_LISTEN_ADDRESS = addrParts[0];
312
+ envs.PL_LISTEN_PORT = addrParts[1];
313
+ } else envs.PL_LISTEN_ADDRESS = options.grpcAddr;
314
+ } else if (options?.grpcPort) envs.PL_LISTEN_PORT = options.grpcPort.toString();
315
+ if (options?.monitoringAddr) {
316
+ const addrParts = options.monitoringAddr.split(":");
317
+ if (addrParts.length === 2) {
318
+ envs.PL_MONITORING_IP = addrParts[0];
319
+ envs.PL_MONITORING_PORT = addrParts[1];
320
+ } else envs.PL_MONITORING_IP = options.monitoringAddr;
321
+ } else if (options?.monitoringPort) envs.PL_MONITORING_PORT = options.monitoringPort.toString();
322
+ if (options?.debugAddr) {
323
+ const addrParts = options.debugAddr.split(":");
324
+ if (addrParts.length === 2) {
325
+ envs.PL_DEBUG_IP = addrParts[0];
326
+ envs.PL_DEBUG_PORT = addrParts[1];
327
+ } else envs.PL_DEBUG_IP = options.debugAddr;
328
+ } else if (options?.debugPort) envs.PL_DEBUG_PORT = options.debugPort.toString();
329
+ if (options?.s3Port) envs.MINIO_PORT = options.s3Port.toString();
330
+ if (options?.s3ConsolePort) envs.MINIO_CONSOLE_PORT = options.s3ConsolePort.toString();
331
+ if (options?.auth) {
332
+ if (options.auth.enabled) envs["PL_NO_AUTH"] = "false";
333
+ else envs["PL_NO_AUTH"] = "true";
334
+ if (options.auth.drivers) {
335
+ for (const drv of options.auth.drivers) if (drv.driver === "htpasswd") {
336
+ envs["PL_AUTH_HTPASSWD"] = node_path.default.resolve(drv.path);
337
+ drv.path = "/etc/platforma/users.htpasswd";
338
+ }
339
+ envs["PL_AUTH_DRIVERS"] = JSON.stringify(options.auth.drivers);
340
+ }
341
+ }
342
+ if (options?.backendCommands && options.backendCommands.length > 0) this.logger.debug(`Adding backend commands: ${options.backendCommands.join(" ")}`);
343
+ require_state.default.setInstanceInfo(instanceName, {
344
+ type: "docker",
345
+ upCommands: [{
346
+ cmd: "docker",
347
+ args: [
348
+ "compose",
349
+ `--file=${composeDstPath}`,
350
+ "up",
351
+ "--detach",
352
+ "--remove-orphans",
353
+ "--pull=missing"
354
+ ],
355
+ envs,
356
+ runOpts: { stdio: "inherit" }
357
+ }],
358
+ downCommands: [{
359
+ cmd: "docker",
360
+ args: [
361
+ "compose",
362
+ `--file=${composeDstPath}`,
363
+ "down"
364
+ ],
365
+ envs,
366
+ runOpts: { stdio: "inherit" }
367
+ }],
368
+ cleanupCommands: [{
369
+ cmd: "docker",
370
+ args: [
371
+ "compose",
372
+ `--file=${composeDstPath}`,
373
+ "down",
374
+ "--volumes",
375
+ "--remove-orphans"
376
+ ],
377
+ envs,
378
+ runOpts: { stdio: "inherit" }
379
+ }],
380
+ runInfo: {
381
+ apiPort: options?.grpcPort,
382
+ apiAddr: options?.grpcAddr,
383
+ logPath: logFilePath,
384
+ primary,
385
+ work: {
386
+ type: "FS",
387
+ rootPath: workFSPath
388
+ },
389
+ library,
390
+ dbPath: dbFSPath
391
+ }
392
+ });
393
+ return require_state.default.getInstanceInfo(instanceName);
394
+ }
395
+ createDocker(instanceName, localRoot, options) {
396
+ this.logger.debug("creating platforma instance in 'docker' mode...");
397
+ const composeFSPath = require_package.assets("compose-backend.yaml");
398
+ const image = options?.image ?? require_package.plImageTag(options?.version);
399
+ this.checkLicense(options?.license, options?.licenseFile);
400
+ const storagePath = (...s) => node_path.default.join(localRoot, ...s);
401
+ const storageDir = (s) => {
402
+ const p = storagePath(s);
403
+ require_util.ensureDir(p, { mode: "0775" });
404
+ return p;
405
+ };
406
+ const logFilePath = storagePath("logs", "platforma.log");
407
+ if (!node_fs.default.existsSync(logFilePath)) {
408
+ node_fs.default.mkdirSync(node_path.default.dirname(logFilePath), { recursive: true });
409
+ node_fs.default.writeFileSync(logFilePath, "");
410
+ }
411
+ const dbFSPath = storageDir("db");
412
+ const primaryFSPath = storageDir("primary");
413
+ const libraryFSPath = storageDir("library");
414
+ const workFSPath = storageDir("work");
415
+ const usersFSPath = storagePath("users.htpasswd");
416
+ if (!node_fs.default.existsSync(usersFSPath)) node_fs.default.copyFileSync(require_package.assets("users.htpasswd"), usersFSPath);
417
+ const composeDstPath = storagePath("compose.yaml");
418
+ if (node_fs.default.existsSync(composeDstPath)) this.logger.info(`replacing docker compose file ${composeDstPath}`);
419
+ const backendMounts = [];
420
+ for (const mnt of options?.customMounts ?? []) backendMounts.push({
421
+ hostPath: mnt.hostPath,
422
+ containerPath: mnt.containerPath ?? mnt.hostPath
423
+ });
424
+ this.logger.debug(`Rendering docker compose file '${composeDstPath}' using '${composeFSPath}' as base template`);
425
+ require_compose.render(composeFSPath, composeDstPath, `pl-${instanceName}`, new Map([["backend", {
426
+ platform: options?.platformOverride,
427
+ mounts: backendMounts,
428
+ commands: options?.backendCommands
429
+ }]]));
430
+ const primary = require_pl_config.storageSettingsFromURL(options?.primaryStorageURL ?? `file:${primaryFSPath}`, ".");
431
+ const library = require_pl_config.storageSettingsFromURL(options?.libraryStorageURL ?? `file:${libraryFSPath}`, ".");
432
+ const envs = {
433
+ PL_IMAGE: image,
434
+ PL_AUTH_HTPASSWD: usersFSPath,
435
+ PL_LICENSE: options?.license,
436
+ PL_LICENSE_FILE: options?.licenseFile,
437
+ PL_LOG_LEVEL: options?.logLevel ?? "info",
438
+ PL_LOG_DIR: node_path.default.dirname(logFilePath),
439
+ PL_LOG_ROTATION_ENABLED: "true",
440
+ PL_RUNNER_WD_CACHE_ON_FAILURE: "1h",
441
+ PL_DATA_DB_ROOT: dbFSPath,
442
+ PL_DATA_PRIMARY_ROOT: primaryFSPath,
443
+ PL_DATA_LIBRARY_ROOT: libraryFSPath,
444
+ PL_DATA_WORKDIR_ROOT: workFSPath,
445
+ PL_DATA_PACKAGE_ROOT: storageDir("packages"),
446
+ ...this.configureDockerStorage("primary", primary),
447
+ ...this.configureDockerStorage("library", library)
448
+ };
449
+ if (options?.grpcAddr) {
450
+ const addrParts = options.grpcAddr.split(":");
451
+ if (addrParts.length === 2) {
452
+ envs.PL_LISTEN_ADDRESS = addrParts[0];
453
+ envs.PL_LISTEN_PORT = addrParts[1];
454
+ } else envs.PL_LISTEN_ADDRESS = options.grpcAddr;
455
+ } else if (options?.grpcPort) envs.PL_LISTEN_PORT = options.grpcPort.toString();
456
+ if (options?.monitoringAddr) {
457
+ const addrParts = options.monitoringAddr.split(":");
458
+ if (addrParts.length === 2) {
459
+ envs.PL_MONITORING_IP = addrParts[0];
460
+ envs.PL_MONITORING_PORT = addrParts[1];
461
+ } else envs.PL_MONITORING_IP = options.monitoringAddr;
462
+ } else if (options?.monitoringPort) envs.PL_MONITORING_PORT = options.monitoringPort.toString();
463
+ if (options?.debugAddr) {
464
+ const addrParts = options.debugAddr.split(":");
465
+ if (addrParts.length === 2) {
466
+ envs.PL_DEBUG_IP = addrParts[0];
467
+ envs.PL_DEBUG_PORT = addrParts[1];
468
+ } else envs.PL_DEBUG_IP = options.debugAddr;
469
+ } else if (options?.debugPort) envs.PL_DEBUG_PORT = options.debugPort.toString();
470
+ if (options?.auth) {
471
+ if (options.auth.enabled) envs["PL_NO_AUTH"] = "false";
472
+ else envs["PL_NO_AUTH"] = "true";
473
+ if (options.auth.drivers) {
474
+ for (const drv of options.auth.drivers) if (drv.driver === "htpasswd") {
475
+ envs["PL_AUTH_HTPASSWD"] = node_path.default.resolve(drv.path);
476
+ drv.path = "/etc/platforma/users.htpasswd";
477
+ }
478
+ envs["PL_AUTH_DRIVERS"] = JSON.stringify(options.auth.drivers);
479
+ }
480
+ }
481
+ if (options?.backendCommands && options.backendCommands.length > 0) this.logger.debug(`Adding backend commands: ${options.backendCommands.join(" ")}`);
482
+ require_state.default.setInstanceInfo(instanceName, {
483
+ type: "docker",
484
+ upCommands: [{
485
+ cmd: "docker",
486
+ args: [
487
+ "compose",
488
+ `--file=${composeDstPath}`,
489
+ "up",
490
+ "--detach",
491
+ "--remove-orphans",
492
+ "--pull=missing"
493
+ ],
494
+ envs,
495
+ runOpts: { stdio: "inherit" }
496
+ }],
497
+ downCommands: [{
498
+ cmd: "docker",
499
+ args: [
500
+ "compose",
501
+ `--file=${composeDstPath}`,
502
+ "down"
503
+ ],
504
+ envs,
505
+ runOpts: { stdio: "inherit" }
506
+ }],
507
+ cleanupCommands: [{
508
+ cmd: "docker",
509
+ args: [
510
+ "compose",
511
+ `--file=${composeDstPath}`,
512
+ "down",
513
+ "--volumes",
514
+ "--remove-orphans"
515
+ ],
516
+ envs,
517
+ runOpts: { stdio: "inherit" }
518
+ }],
519
+ runInfo: {
520
+ apiPort: options?.grpcPort,
521
+ apiAddr: options?.grpcAddr,
522
+ logPath: logFilePath,
523
+ primary,
524
+ work: {
525
+ type: "FS",
526
+ rootPath: workFSPath
527
+ },
528
+ library,
529
+ dbPath: dbFSPath
530
+ }
531
+ });
532
+ return require_state.default.getInstanceInfo(instanceName);
533
+ }
534
+ cleanupInstance(instanceName) {
535
+ const removeWarns = [];
536
+ const instancesToDrop = /* @__PURE__ */ new Map();
537
+ let warnMessage = "";
538
+ if (instanceName) {
539
+ const instance = require_state.default.getInstanceInfo(instanceName);
540
+ instancesToDrop.set(instanceName, instance);
541
+ const iType = instance.type;
542
+ switch (iType) {
543
+ case "docker":
544
+ removeWarns.push(`docker service 'pl-${instanceName}', including all its volumes and data in '${require_state.default.instanceDir(instanceName)}' will be destroyed`);
545
+ break;
546
+ case "process":
547
+ removeWarns.push(`directory '${require_state.default.instanceDir(instanceName)}' would be deleted`);
548
+ if (instance.downCommands) removeWarns.push(`associated docker service, including all volumes and data will be destroyed`);
549
+ break;
550
+ default: require_util.assertNever(iType);
551
+ }
552
+ if (instanceName === require_state.default.currentInstanceName) removeWarns.push("last command run cache ('pl-dev start' shorthand will stop working until next full start command call)");
553
+ warnMessage = `
665
554
  You are going to reset the state of platforma service '${instanceName}':
666
555
  - ${removeWarns.join("\n - ")}
667
556
  `;
668
- }
669
- else {
670
- for (const iName of state.instanceList) {
671
- instancesToDrop.set(iName, state.getInstanceInfo(iName));
672
- }
673
- removeWarns.push("last command run cache ('pl-dev start' shorthand will stop working until next full start command call)", `all service configurations stored in: ${state.instanceDir()} (including all associated docker containers and volumes)`);
674
- warnMessage = `
557
+ } else {
558
+ for (const iName of require_state.default.instanceList) instancesToDrop.set(iName, require_state.default.getInstanceInfo(iName));
559
+ removeWarns.push("last command run cache ('pl-dev start' shorthand will stop working until next full start command call)", `all service configurations stored in: ${require_state.default.instanceDir()} (including all associated docker containers and volumes)`);
560
+ warnMessage = `
675
561
  You are going to reset the state of all platforma services configured with pl-bootstrap package.
676
562
  - ${removeWarns.join("\n - ")}
677
563
  `;
678
- }
679
- this.logger.warn(warnMessage);
680
- if (!util.askYN("Are you sure?")) {
681
- this.logger.info("Reset action was canceled");
682
- return;
683
- }
684
- for (const [name, instance] of instancesToDrop.entries()) {
685
- if (instance.cleanupCommands.length) {
686
- this.logger.info(`Wiping instance ${name} services`);
687
- const result = run.runCommands(this.logger, instance.cleanupCommands);
688
- checkRunError(result.executed, `failed to wipe instance ${name} services`);
689
- }
690
- this.logger.info(`Destroying instance '${name}' data directory`);
691
- fs.rmSync(state.instanceDir(name), { recursive: true, force: true });
692
- }
693
- if (!instanceName) {
694
- this.logger.info(`Destroying state dir '${state.path()}'`);
695
- fs.rmSync(state.path(), { recursive: true, force: true });
696
- }
697
- this.logger.info(`\nIf you want to remove all downloaded platforma binaries, delete '${state.binaries()}' dir manually\n`);
698
- }
699
- mergeLicenseEnvs(flags) {
700
- if (flags.license === undefined) {
701
- if ((process.env.MI_LICENSE ?? "") != "")
702
- flags.license = process.env.MI_LICENSE;
703
- else if ((process.env.PL_LICENSE ?? "") != "")
704
- flags.license = process.env.PL_LICENSE;
705
- }
706
- // set 'license-file' only if license is still undefined
707
- if (flags["license-file"] === undefined && flags.license === undefined) {
708
- if ((process.env.MI_LICENSE_FILE ?? "") != "")
709
- flags["license-file"] = process.env.MI_LICENSE_FILE;
710
- else if ((process.env.PL_LICENSE_FILE ?? "") != "")
711
- flags["license-file"] = process.env.PL_LICENSE_FILE;
712
- else if (fs.existsSync(path.resolve(os.homedir(), ".pl.license")))
713
- flags["license-file"] = path.resolve(os.homedir(), ".pl.license");
714
- }
715
- }
716
- initAuthDriversList(flags, workdir) {
717
- const authDrivers = [];
718
- if (flags["auth-htpasswd-file"]) {
719
- authDrivers.push({
720
- driver: "htpasswd",
721
- path: path.resolve(workdir, flags["auth-htpasswd-file"]),
722
- });
723
- }
724
- if (Boolean(flags["auth-ldap-server"]) !== Boolean(flags["auth-ldap-default-dn"])) {
725
- throw new Error("LDAP auth settings require both 'server' and 'default DN' options to be set");
726
- }
727
- if (flags["auth-ldap-server"]) {
728
- authDrivers.push({
729
- driver: "ldap",
730
- serverUrl: flags["auth-ldap-server"],
731
- defaultDN: flags["auth-ldap-default-dn"],
732
- });
733
- }
734
- if (authDrivers.length === 0) {
735
- return undefined;
736
- }
737
- return [{ driver: "jwt", key: this.getLastJwt() }, ...authDrivers];
738
- }
739
- /** Gets the last stored JWT secret key or generates it and stores in a file. */
740
- getLastJwt() {
741
- const jwtFile = state.path("auth.jwt");
742
- const encoding = "utf-8";
743
- let lastJwt = "";
744
- if (fs.existsSync(jwtFile)) {
745
- lastJwt = fs.readFileSync(jwtFile, { encoding });
746
- }
747
- if (lastJwt == "") {
748
- lastJwt = util.randomStr(64);
749
- fs.writeFileSync(jwtFile, lastJwt, { encoding });
750
- }
751
- return lastJwt;
752
- }
753
- checkLicense(value, file) {
754
- if (value !== undefined && value != "")
755
- return;
756
- if (file !== undefined && file != "")
757
- return;
758
- this.logger.error(`A license for Platforma Backend must be set.
564
+ }
565
+ this.logger.warn(warnMessage);
566
+ if (!require_util.askYN("Are you sure?")) {
567
+ this.logger.info("Reset action was canceled");
568
+ return;
569
+ }
570
+ for (const [name, instance] of instancesToDrop.entries()) {
571
+ if (instance.cleanupCommands.length) {
572
+ this.logger.info(`Wiping instance ${name} services`);
573
+ checkRunError(require_run.runCommands(this.logger, instance.cleanupCommands).executed, `failed to wipe instance ${name} services`);
574
+ }
575
+ this.logger.info(`Destroying instance '${name}' data directory`);
576
+ node_fs.default.rmSync(require_state.default.instanceDir(name), {
577
+ recursive: true,
578
+ force: true
579
+ });
580
+ }
581
+ if (!instanceName) {
582
+ this.logger.info(`Destroying state dir '${require_state.default.path()}'`);
583
+ node_fs.default.rmSync(require_state.default.path(), {
584
+ recursive: true,
585
+ force: true
586
+ });
587
+ }
588
+ this.logger.info(`\nIf you want to remove all downloaded platforma binaries, delete '${require_state.default.binaries()}' dir manually\n`);
589
+ }
590
+ mergeLicenseEnvs(flags) {
591
+ if (flags.license === void 0) {
592
+ if ((process.env.MI_LICENSE ?? "") != "") flags.license = process.env.MI_LICENSE;
593
+ else if ((process.env.PL_LICENSE ?? "") != "") flags.license = process.env.PL_LICENSE;
594
+ }
595
+ if (flags["license-file"] === void 0 && flags.license === void 0) {
596
+ if ((process.env.MI_LICENSE_FILE ?? "") != "") flags["license-file"] = process.env.MI_LICENSE_FILE;
597
+ else if ((process.env.PL_LICENSE_FILE ?? "") != "") flags["license-file"] = process.env.PL_LICENSE_FILE;
598
+ else if (node_fs.default.existsSync(node_path.default.resolve(node_os.default.homedir(), ".pl.license"))) flags["license-file"] = node_path.default.resolve(node_os.default.homedir(), ".pl.license");
599
+ }
600
+ }
601
+ initAuthDriversList(flags, workdir) {
602
+ const authDrivers = [];
603
+ if (flags["auth-htpasswd-file"]) authDrivers.push({
604
+ driver: "htpasswd",
605
+ path: node_path.default.resolve(workdir, flags["auth-htpasswd-file"])
606
+ });
607
+ if (Boolean(flags["auth-ldap-server"]) !== Boolean(flags["auth-ldap-default-dn"])) throw new Error("LDAP auth settings require both 'server' and 'default DN' options to be set");
608
+ if (flags["auth-ldap-server"]) authDrivers.push({
609
+ driver: "ldap",
610
+ serverUrl: flags["auth-ldap-server"],
611
+ defaultDN: flags["auth-ldap-default-dn"]
612
+ });
613
+ if (authDrivers.length === 0) return;
614
+ return [{
615
+ driver: "jwt",
616
+ key: this.getLastJwt()
617
+ }, ...authDrivers];
618
+ }
619
+ /** Gets the last stored JWT secret key or generates it and stores in a file. */
620
+ getLastJwt() {
621
+ const jwtFile = require_state.default.path("auth.jwt");
622
+ const encoding = "utf-8";
623
+ let lastJwt = "";
624
+ if (node_fs.default.existsSync(jwtFile)) lastJwt = node_fs.default.readFileSync(jwtFile, { encoding });
625
+ if (lastJwt == "") {
626
+ lastJwt = require_util.randomStr(64);
627
+ node_fs.default.writeFileSync(jwtFile, lastJwt, { encoding });
628
+ }
629
+ return lastJwt;
630
+ }
631
+ checkLicense(value, file) {
632
+ if (value !== void 0 && value != "") return;
633
+ if (file !== void 0 && file != "") return;
634
+ this.logger.error(`A license for Platforma Backend must be set.
759
635
 
760
636
  You can provide the license directly using the '--license' flag
761
637
  or use the '--license-file' flag if the license is stored in a file.
@@ -766,137 +642,92 @@ The license file can also be set with the variables 'MI_LICENSE_FILE' or 'PL_LIC
766
642
  or stored in '$HOME/.pl.license'.
767
643
 
768
644
  You can obtain the license from "https://platforma.bio/getlicense".`);
769
- throw new Error(`The license was not provided.`);
770
- }
771
- configureDockerStorage(storageID, storage) {
772
- const envs = {};
773
- const sType = storage.type;
774
- storageID = storageID.toUpperCase();
775
- switch (sType) {
776
- case "S3":
777
- switch (storageID) {
778
- case "PRIMARY": {
779
- // Construct the S3 URL for primary storage
780
- if (storage.endpoint && storage.bucketName) {
781
- envs["PL_PRIMARY_STORAGE_S3"] = `${storage.endpoint}${storage.bucketName}`;
782
- }
783
- if (storage.endpoint)
784
- envs["PL_PRIMARY_STORAGE_S3_ENDPOINT"] = storage.endpoint;
785
- if (storage.presignEndpoint)
786
- envs["PL_PRIMARY_STORAGE_S3_EXTERNAL_ENDPOINT"] = storage.presignEndpoint;
787
- if (storage.region)
788
- envs["PL_PRIMARY_STORAGE_S3_REGION"] = storage.region;
789
- if (storage.key)
790
- envs["PL_PRIMARY_STORAGE_S3_KEY"] = storage.key;
791
- if (storage.secret)
792
- envs["PL_PRIMARY_STORAGE_S3_SECRET"] = storage.secret;
793
- break;
794
- }
795
- case "LIBRARY": {
796
- // Construct the S3 URL for library storage
797
- if (storage.endpoint && storage.bucketName) {
798
- envs["PL_DATA_LIBRARY_S3_URL"] = `library=${storage.endpoint}${storage.bucketName}`;
799
- }
800
- if (storage.endpoint)
801
- envs["PL_DATA_LIBRARY_S3_ENDPOINT"] = `library=${storage.endpoint}`;
802
- if (storage.presignEndpoint)
803
- envs["PL_DATA_LIBRARY_S3_EXTERNAL_ENDPOINT"] = `library=${storage.presignEndpoint}`;
804
- if (storage.region)
805
- envs["PL_DATA_LIBRARY_S3_REGION"] = `library=${storage.region}`;
806
- if (storage.key)
807
- envs["PL_DATA_LIBRARY_S3_KEY"] = `library=${storage.key}`;
808
- if (storage.secret)
809
- envs["PL_DATA_LIBRARY_S3_SECRET"] = `library=${storage.secret}`;
810
- break;
811
- }
812
- default:
813
- throw new Error(`Unknown storage ID: ${storageID}`);
814
- }
815
- return envs;
816
- case "FS":
817
- switch (storageID) {
818
- case "PRIMARY":
819
- if (storage.rootPath)
820
- envs["PL_PRIMARY_STORAGE_FS"] = storage.rootPath;
821
- break;
822
- case "LIBRARY":
823
- if (storage.rootPath)
824
- envs["PL_DATA_LIBRARY_FS_PATH"] = storage.rootPath;
825
- break;
826
- default:
827
- throw new Error(`Unknown storage ID: ${storageID}`);
828
- }
829
- return envs;
830
- default:
831
- util.assertNever();
832
- }
833
- return {};
834
- }
835
- renderRunInfo(runInfo, indent = 10) {
836
- const report = [];
837
- const column = (t) => t.padStart(indent, " ");
838
- if (runInfo.configPath) {
839
- report.push(`${column("config")}: ${runInfo.configPath}`);
840
- }
841
- if (runInfo.apiAddr) {
842
- report.push(`${column("API")}: ${runInfo.apiAddr}`);
843
- }
844
- else if (runInfo.apiPort) {
845
- report.push(`${column("API")}: 127.0.0.1:${runInfo.apiPort.toString()}`);
846
- }
847
- else {
848
- report.push(`${column("API")}: 127.0.0.1:6345`);
849
- }
850
- if (runInfo.logPath) {
851
- report.push(`${column("log")}: ${runInfo.logPath}`);
852
- }
853
- const primaryType = runInfo.primary?.type;
854
- switch (primaryType) {
855
- case undefined:
856
- break;
857
- case "FS":
858
- report.push(`${column("primary")}: ${runInfo.primary.rootPath}`);
859
- break;
860
- case "S3":
861
- report.push(`${column("primary")}: S3 at '${runInfo.primary.endpoint ?? "AWS"}', bucket '${runInfo.primary.bucketName}', prefix: '${runInfo.primary.keyPrefix ?? ""}'`);
862
- break;
863
- default:
864
- util.assertNever();
865
- }
866
- const libraryType = runInfo.library?.type;
867
- switch (libraryType) {
868
- case undefined:
869
- break;
870
- case "FS":
871
- report.push(`${column("library")}: ${runInfo.library.rootPath}`);
872
- break;
873
- case "S3":
874
- report.push(`${column("library")}: S3 at '${runInfo.library.endpoint ?? "AWS"}', bucket '${runInfo.library.bucketName}', prefix: '${runInfo.library.keyPrefix ?? ""}'`);
875
- break;
876
- default:
877
- util.assertNever();
878
- }
879
- if (runInfo.work) {
880
- report.push(`${column("workdirs")}: ${runInfo.work.rootPath}`);
881
- }
882
- if (runInfo.dbPath) {
883
- report.push(`${column("db")}: ${runInfo.dbPath}`);
884
- }
885
- return report.join("\n");
886
- }
887
- }
645
+ throw new Error(`The license was not provided.`);
646
+ }
647
+ configureDockerStorage(storageID, storage) {
648
+ const envs = {};
649
+ const sType = storage.type;
650
+ storageID = storageID.toUpperCase();
651
+ switch (sType) {
652
+ case "S3":
653
+ switch (storageID) {
654
+ case "PRIMARY":
655
+ if (storage.endpoint && storage.bucketName) envs["PL_PRIMARY_STORAGE_S3"] = `${storage.endpoint}${storage.bucketName}`;
656
+ if (storage.endpoint) envs["PL_PRIMARY_STORAGE_S3_ENDPOINT"] = storage.endpoint;
657
+ if (storage.presignEndpoint) envs["PL_PRIMARY_STORAGE_S3_EXTERNAL_ENDPOINT"] = storage.presignEndpoint;
658
+ if (storage.region) envs["PL_PRIMARY_STORAGE_S3_REGION"] = storage.region;
659
+ if (storage.key) envs["PL_PRIMARY_STORAGE_S3_KEY"] = storage.key;
660
+ if (storage.secret) envs["PL_PRIMARY_STORAGE_S3_SECRET"] = storage.secret;
661
+ break;
662
+ case "LIBRARY":
663
+ if (storage.endpoint && storage.bucketName) envs["PL_DATA_LIBRARY_S3_URL"] = `library=${storage.endpoint}${storage.bucketName}`;
664
+ if (storage.endpoint) envs["PL_DATA_LIBRARY_S3_ENDPOINT"] = `library=${storage.endpoint}`;
665
+ if (storage.presignEndpoint) envs["PL_DATA_LIBRARY_S3_EXTERNAL_ENDPOINT"] = `library=${storage.presignEndpoint}`;
666
+ if (storage.region) envs["PL_DATA_LIBRARY_S3_REGION"] = `library=${storage.region}`;
667
+ if (storage.key) envs["PL_DATA_LIBRARY_S3_KEY"] = `library=${storage.key}`;
668
+ if (storage.secret) envs["PL_DATA_LIBRARY_S3_SECRET"] = `library=${storage.secret}`;
669
+ break;
670
+ default: throw new Error(`Unknown storage ID: ${storageID}`);
671
+ }
672
+ return envs;
673
+ case "FS":
674
+ switch (storageID) {
675
+ case "PRIMARY":
676
+ if (storage.rootPath) envs["PL_PRIMARY_STORAGE_FS"] = storage.rootPath;
677
+ break;
678
+ case "LIBRARY":
679
+ if (storage.rootPath) envs["PL_DATA_LIBRARY_FS_PATH"] = storage.rootPath;
680
+ break;
681
+ default: throw new Error(`Unknown storage ID: ${storageID}`);
682
+ }
683
+ return envs;
684
+ default: require_util.assertNever(sType);
685
+ }
686
+ return {};
687
+ }
688
+ renderRunInfo(runInfo, indent = 10) {
689
+ const report = [];
690
+ const column = (t) => t.padStart(indent, " ");
691
+ if (runInfo.configPath) report.push(`${column("config")}: ${runInfo.configPath}`);
692
+ if (runInfo.apiAddr) report.push(`${column("API")}: ${runInfo.apiAddr}`);
693
+ else if (runInfo.apiPort) report.push(`${column("API")}: 127.0.0.1:${runInfo.apiPort.toString()}`);
694
+ else report.push(`${column("API")}: 127.0.0.1:6345`);
695
+ if (runInfo.logPath) report.push(`${column("log")}: ${runInfo.logPath}`);
696
+ const primaryType = runInfo.primary?.type;
697
+ switch (primaryType) {
698
+ case void 0: break;
699
+ case "FS":
700
+ report.push(`${column("primary")}: ${runInfo.primary.rootPath}`);
701
+ break;
702
+ case "S3":
703
+ report.push(`${column("primary")}: S3 at '${runInfo.primary.endpoint ?? "AWS"}', bucket '${runInfo.primary.bucketName}', prefix: '${runInfo.primary.keyPrefix ?? ""}'`);
704
+ break;
705
+ default: require_util.assertNever(primaryType);
706
+ }
707
+ const libraryType = runInfo.library?.type;
708
+ switch (libraryType) {
709
+ case void 0: break;
710
+ case "FS":
711
+ report.push(`${column("library")}: ${runInfo.library.rootPath}`);
712
+ break;
713
+ case "S3":
714
+ report.push(`${column("library")}: S3 at '${runInfo.library.endpoint ?? "AWS"}', bucket '${runInfo.library.bucketName}', prefix: '${runInfo.library.keyPrefix ?? ""}'`);
715
+ break;
716
+ default: require_util.assertNever(libraryType);
717
+ }
718
+ if (runInfo.work) report.push(`${column("workdirs")}: ${runInfo.work.rootPath}`);
719
+ if (runInfo.dbPath) report.push(`${column("db")}: ${runInfo.dbPath}`);
720
+ return report.join("\n");
721
+ }
722
+ };
888
723
  function checkRunError(result, message) {
889
- for (const buffer of result) {
890
- if (buffer.error) {
891
- throw buffer.error;
892
- }
893
- const msg = message ?? "failed to run command";
894
- if (buffer.status !== 0) {
895
- throw new Error(`${msg}, process exited with code '${buffer.status}'`);
896
- }
897
- }
724
+ for (const buffer of result) {
725
+ if (buffer.error) throw buffer.error;
726
+ const msg = message ?? "failed to run command";
727
+ if (buffer.status !== 0) throw new Error(`${msg}, process exited with code '${buffer.status}'`);
728
+ }
898
729
  }
899
730
 
900
- exports.checkRunError = checkRunError;
731
+ //#endregion
901
732
  exports.default = Core;
902
- //# sourceMappingURL=core.cjs.map
733
+ //# sourceMappingURL=core.cjs.map