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