@platforma-sdk/bootstrap 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/assets/compose-backend.yaml +6 -6
  2. package/dist/cmd-opts.d.ts +6 -3
  3. package/dist/cmd-opts.d.ts.map +1 -1
  4. package/dist/commands/start/docker/s3.d.ts +6 -3
  5. package/dist/commands/start/docker/s3.d.ts.map +1 -1
  6. package/dist/commands/start/docker.d.ts +6 -3
  7. package/dist/commands/start/docker.d.ts.map +1 -1
  8. package/dist/commands/start/local/s3.d.ts +6 -3
  9. package/dist/commands/start/local/s3.d.ts.map +1 -1
  10. package/dist/commands/start/local.d.ts +6 -3
  11. package/dist/commands/start/local.d.ts.map +1 -1
  12. package/dist/core.d.ts +15 -6
  13. package/dist/core.d.ts.map +1 -1
  14. package/dist/index.d.ts +10 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +47 -40
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +928 -469
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/package.d.ts +0 -1
  21. package/dist/package.d.ts.map +1 -1
  22. package/dist/platforma.d.ts.map +1 -1
  23. package/dist/state.d.ts +3 -0
  24. package/dist/state.d.ts.map +1 -1
  25. package/dist/templates/pl-config.d.ts.map +1 -1
  26. package/dist/templates/types.d.ts +6 -0
  27. package/dist/templates/types.d.ts.map +1 -1
  28. package/dist/util.d.ts +2 -0
  29. package/dist/util.d.ts.map +1 -1
  30. package/package.json +10 -7
  31. package/src/block.ts +0 -82
  32. package/src/cmd-opts.ts +0 -175
  33. package/src/commands/create-block.ts +0 -21
  34. package/src/commands/reset.ts +0 -23
  35. package/src/commands/start/docker/s3.ts +0 -59
  36. package/src/commands/start/docker.ts +0 -65
  37. package/src/commands/start/local/s3.ts +0 -96
  38. package/src/commands/start/local.ts +0 -89
  39. package/src/commands/start.ts +0 -23
  40. package/src/commands/stop.ts +0 -23
  41. package/src/core.ts +0 -696
  42. package/src/index.ts +0 -10
  43. package/src/package.ts +0 -54
  44. package/src/platforma.ts +0 -194
  45. package/src/run.ts +0 -120
  46. package/src/state.ts +0 -105
  47. package/src/templates/pl-config.ts +0 -280
  48. package/src/templates/types.ts +0 -172
  49. package/src/util.ts +0 -55
package/src/core.ts DELETED
@@ -1,696 +0,0 @@
1
- import { ChildProcess, SpawnSyncReturns, spawn, spawnSync } from 'child_process';
2
- import yaml from 'yaml';
3
- import fs from 'fs';
4
- import os from 'os';
5
- import path from 'path';
6
- import * as pkg from './package';
7
- import * as run from './run';
8
- import * as plCfg from './templates/pl-config';
9
- import * as types from './templates/types';
10
- import * as platforma from './platforma';
11
- import state from './state';
12
- import * as util from './util';
13
- import winston from 'winston';
14
-
15
- export default class Core {
16
- constructor(private readonly logger: winston.Logger) {}
17
-
18
- public startLast() {
19
- const result = run.rerunLast(this.logger, { stdio: 'inherit' });
20
- checkRunError(result, 'failed to bring back Platforma Backend in the last started configuration');
21
- }
22
-
23
- public startLocal(options?: startLocalOptions): ChildProcess {
24
- const cmd = options?.binaryPath ?? platforma.binaryPath(options?.version, 'binaries', 'platforma');
25
- var configPath = options?.configPath;
26
- const workdir: string = options?.workdir ?? (configPath ? process.cwd() : state.path());
27
-
28
- if (options?.primaryURL) {
29
- options.configOptions = {
30
- ...options.configOptions,
31
- storages: {
32
- ...options.configOptions?.storages,
33
- primary: plCfg.storageSettingsFromURL(options.primaryURL, workdir, options.configOptions?.storages?.primary)
34
- }
35
- };
36
- }
37
- if (options?.libraryURL) {
38
- options.configOptions = {
39
- ...options.configOptions,
40
- storages: {
41
- ...options.configOptions?.storages,
42
- library: plCfg.storageSettingsFromURL(options.libraryURL, workdir, options.configOptions?.storages?.library)
43
- }
44
- };
45
- }
46
-
47
- const configOptions = plCfg.loadDefaults(this.getLastJwt(), options?.configOptions);
48
-
49
- this.logger.debug(` checking license...`);
50
- this.checkLicense(options?.configOptions?.license?.value, options?.configOptions?.license?.file);
51
-
52
- const storageDirs: string[] = [
53
- `${configOptions.localRoot}/packages`,
54
- `${configOptions.localRoot}/packages-local`,
55
- `${configOptions.localRoot}/blocks-local`
56
- ];
57
- if (configOptions.storages.primary.type === 'FS') {
58
- storageDirs.push(configOptions.storages.primary.rootPath);
59
- }
60
- if (configOptions.storages.library.type === 'FS') {
61
- storageDirs.push(configOptions.storages.library.rootPath);
62
- configOptions.hacks.libraryDownloadable = false;
63
- }
64
- if (configOptions.storages.work.type === 'FS') {
65
- storageDirs.push(configOptions.storages.work.rootPath);
66
- }
67
-
68
- this.logger.debug(' creating pl state directories...');
69
- for (const dir of storageDirs) {
70
- if (!fs.existsSync(dir)) {
71
- this.logger.debug(` '${dir}'`);
72
- fs.mkdirSync(dir, { recursive: true });
73
- }
74
- }
75
-
76
- for (const drv of configOptions.core.auth.drivers) {
77
- if (drv.driver === 'htpasswd') {
78
- if (!fs.existsSync(drv.path)) {
79
- this.logger.debug(` installing default 'users.htpasswd' to ${drv.path}...`);
80
- fs.copyFileSync(pkg.assets('users.htpasswd'), drv.path);
81
- }
82
- }
83
- }
84
-
85
- if (!configPath) {
86
- configPath = state.path('config-local.yaml');
87
- this.logger.debug(` rendering configuration '${configPath}'...`);
88
- fs.writeFileSync(configPath, plCfg.render(configOptions));
89
- }
90
-
91
- var configReport: string[] = [];
92
- const column = (t: string) => t.padStart(10, ' ');
93
- configReport.push(`${column('config')}: ${configPath}`);
94
- configReport.push(`${column('API')}: ${configOptions.grpc.listen}`);
95
- configReport.push(`${column('log')}: ${configOptions.log.path}`);
96
-
97
- const primaryType = configOptions.storages.primary.type;
98
- switch (primaryType) {
99
- case 'FS':
100
- configReport.push(`${column('primary')}: ${configOptions.storages.primary.rootPath}`);
101
- break;
102
-
103
- case 'S3':
104
- configReport.push(
105
- `${column('primary')}: S3 at '${configOptions.storages.primary.endpoint ?? 'AWS'}', bucket '${configOptions.storages.primary.bucketName}', prefix: '${configOptions.storages.primary.keyPrefix}'`
106
- );
107
- break;
108
-
109
- default:
110
- util.assertNever(primaryType);
111
- }
112
-
113
- const libraryType = configOptions.storages.library.type;
114
- switch (libraryType) {
115
- case 'FS':
116
- configReport.push(`${column('library')}: ${configOptions.storages.library.rootPath}`);
117
- break;
118
-
119
- case 'S3':
120
- configReport.push(
121
- `${column('library')}: S3 at '${configOptions.storages.library.endpoint ?? 'AWS'}', bucket '${configOptions.storages.library.bucketName}', prefix: '${configOptions.storages.library.keyPrefix}'`
122
- );
123
- break;
124
-
125
- default:
126
- util.assertNever(libraryType);
127
- }
128
-
129
- configReport.push(`${column('workdirs')}: ${configOptions.storages.work.rootPath}`);
130
-
131
- this.logger.info(`Starting platforma:\n${configReport.join('\n')}`);
132
-
133
- return run.runProcess(
134
- this.logger,
135
- cmd,
136
- ['-config', configPath],
137
- {
138
- cwd: workdir,
139
- stdio: 'inherit'
140
- },
141
- {
142
- storagePath: configOptions.localRoot
143
- }
144
- );
145
- }
146
-
147
- public startLocalS3(options?: startLocalS3Options): ChildProcess {
148
- this.logger.debug("starting platforma in 'local s3' mode...");
149
-
150
- const minioPort = options?.minioPort ?? 9000;
151
- const localRoot = options?.configOptions?.localRoot;
152
- this.startMinio({
153
- minioPort: minioPort,
154
- minioConsolePort: options?.minioConsolePort,
155
- storage: localRoot ? path.join(localRoot, 'minio') : undefined
156
- });
157
-
158
- return this.startLocal({
159
- ...options,
160
- primaryURL:
161
- options?.primaryURL ?? `s3e://testuser:testpassword@localhost:${minioPort}/main-bucket/?region=no-region`,
162
- libraryURL:
163
- options?.libraryURL ?? `s3e://testuser:testpassword@localhost:${minioPort}/library-bucket/?region=no-region`
164
- });
165
- }
166
-
167
- public startMinio(options?: {
168
- image?: string;
169
- version?: string;
170
- minioPort?: number;
171
- minioConsolePort?: number;
172
- storage?: string;
173
- }) {
174
- this.logger.debug(' starting minio...');
175
- var composeMinio = pkg.assets('compose-backend.yaml');
176
-
177
- const version = options?.version ? `:${options.version!}` : '';
178
- this.logger.debug(` minio version: ${version}`);
179
- const image = options?.image ?? `quay.io/minio/minio${version}`;
180
- this.logger.debug(` minio image: ${image}`);
181
-
182
- const storage = options?.storage ?? state.path('data', 'minio');
183
- const stubStorage = state.path('data', 'stub');
184
-
185
- const minioPort = options?.minioPort ?? 9000;
186
- const minioConsolePort = options?.minioConsolePort ?? 9001;
187
-
188
- const envs = {
189
- MINIO_IMAGE: image,
190
- MINIO_STORAGE: path.resolve(storage),
191
- MINIO_PORT: minioPort.toString(),
192
- MINIO_CONSOLE_PORT: minioConsolePort.toString(),
193
-
194
- PL_DATA_DB_ROOT: stubStorage,
195
- PL_DATA_PRIMARY_ROOT: stubStorage,
196
- PL_DATA_LIBRARY_ROOT: stubStorage,
197
- PL_DATA_WORKDIR_ROOT: stubStorage,
198
- PL_DATA_PACKAGE_ROOT: stubStorage,
199
- PL_IMAGE: 'scratch'
200
- };
201
- const compose = this.readComposeFile(composeMinio);
202
-
203
- this.logger.debug(` spawning child 'docker' process...`);
204
- const result = spawnSync(
205
- 'docker',
206
- ['compose', `--file=${composeMinio}`, 'up', '--detach', '--remove-orphans', '--pull=missing', 'minio'],
207
- {
208
- env: {
209
- ...process.env,
210
- ...envs
211
- },
212
- stdio: 'inherit'
213
- }
214
- );
215
-
216
- checkRunError(result, 'failed to start MinIO service in docker');
217
- }
218
-
219
- public buildPlatforma(options: { repoRoot: string; binPath?: string }): string {
220
- const cmdPath: string = path.resolve(options.repoRoot, 'cmd', 'platforma');
221
- const binPath: string = options.binPath ?? path.join(os.tmpdir(), 'platforma-local-build');
222
-
223
- this.logger.info('Building Platforma Backend binary from sources');
224
- this.logger.info(` sources path: ${options.repoRoot}`);
225
- this.logger.info(` binary path: ${binPath}`);
226
-
227
- const result = spawnSync('go', ['build', '-o', binPath, '.'], {
228
- cwd: cmdPath,
229
- stdio: 'inherit'
230
- });
231
-
232
- checkRunError(result, "failed to build platforma binary from sources using 'go build' command");
233
- return binPath;
234
- }
235
-
236
- public startDockerS3(
237
- localRoot: string,
238
- options?: {
239
- image?: string;
240
- version?: string;
241
- auth?: types.authOptions;
242
- license?: string;
243
- licenseFile?: string;
244
- 'grpc-port'?: number;
245
- 'monitoring-port'?: number;
246
- 'debug-port'?: number;
247
- }
248
- ) {
249
- const composeS3Path = pkg.assets('compose-backend.yaml');
250
- const image = options?.image ?? pkg.plImageTag(options?.version);
251
-
252
- this.checkLicense(options?.license, options?.licenseFile);
253
-
254
- const storagePath = (s: string) => path.join(localRoot, s);
255
- const logFilePath = storagePath('platforma.log');
256
- if (!fs.existsSync(logFilePath)) {
257
- fs.mkdirSync(path.dirname(logFilePath), { recursive: true });
258
- fs.writeFileSync(logFilePath, '');
259
- }
260
-
261
- const primary = plCfg.storageSettingsFromURL('s3e://testuser:testpassword@minio:9000/main-bucket');
262
- if (primary.type !== 'S3') {
263
- throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");
264
- } else {
265
- primary.presignEndpoint = 'http://localhost:9000';
266
- }
267
-
268
- const library = plCfg.storageSettingsFromURL('s3e://testuser:testpassword@minio:9000/library-bucket');
269
- if (library.type !== 'S3') {
270
- throw new Error(`${library.type} storage type is not supported for library storage`);
271
- } else {
272
- library.presignEndpoint = 'http://localhost:9000';
273
- }
274
-
275
- const envs: NodeJS.ProcessEnv = {
276
- MINIO_IMAGE: 'quay.io/minio/minio',
277
- MINIO_STORAGE: storagePath('minio'),
278
-
279
- PL_IMAGE: image,
280
-
281
- PL_AUTH_HTPASSWD_PATH: pkg.assets('users.htpasswd'),
282
- PL_LICENSE: options?.license,
283
- PL_LICENSE_FILE: options?.licenseFile,
284
-
285
- PL_LOG_LEVEL: 'info',
286
- PL_LOG_FILE: logFilePath,
287
-
288
- PL_DATA_DB_ROOT: storagePath('db'),
289
- PL_DATA_PRIMARY_ROOT: storagePath('primary'),
290
- PL_DATA_LIBRARY_ROOT: storagePath('library'),
291
- PL_DATA_WORKDIR_ROOT: storagePath('work'),
292
- PL_DATA_PACKAGE_ROOT: storagePath('packages'),
293
-
294
- ...this.configureDockerStorage('primary', primary),
295
- ...this.configureDockerStorage('library', library)
296
- };
297
-
298
- if (options?.['grpc-port'] != undefined) envs.PL_GRPC_PORT = options['grpc-port'].toString();
299
- if (options?.['monitoring-port'] != undefined) envs.PL_MONITORING_PORT = options['monitoring-port'].toString();
300
- if (options?.['debug-port'] != undefined) envs.PL_DEBUG_PORT = options['debug-port'].toString();
301
-
302
- if (options?.auth) {
303
- if (options.auth.enabled) {
304
- envs['PL_AUTH_ENABLED'] = 'true';
305
- }
306
- if (options.auth.drivers) {
307
- for (const drv of options.auth.drivers) {
308
- if (drv.driver === 'htpasswd') {
309
- envs['PL_AUTH_HTPASSWD_PATH'] = path.resolve(drv.path);
310
- drv.path = '/etc/platforma/users.htpasswd';
311
- }
312
- }
313
- envs['PL_AUTH_DRIVERS'] = JSON.stringify(options.auth.drivers);
314
- }
315
- }
316
-
317
- const result = run.runDocker(
318
- this.logger,
319
- [
320
- 'compose',
321
- `--file=${composeS3Path}`,
322
- 'up',
323
- '--detach',
324
- '--remove-orphans',
325
- '--pull=missing',
326
- 'minio',
327
- 'backend'
328
- ],
329
- {
330
- env: envs,
331
- stdio: 'inherit'
332
- },
333
- {
334
- plImage: image,
335
- composePath: composeS3Path
336
- }
337
- );
338
-
339
- checkRunError(result, 'failed to start Platforma Backend in Docker');
340
- state.isActive = true;
341
- }
342
-
343
- public startDocker(
344
- localRoot: string,
345
- options?: {
346
- primaryStorageURL?: string;
347
- workStoragePath?: string;
348
- libraryStorageURL?: string;
349
-
350
- image?: string;
351
- version?: string;
352
- auth?: types.authOptions;
353
-
354
- license?: string;
355
- licenseFile?: string;
356
- 'grpc-port'?: number;
357
- 'monitoring-port'?: number;
358
- 'debug-port'?: number;
359
- }
360
- ) {
361
- var composeFSPath = pkg.assets('compose-backend.yaml');
362
- const image = options?.image ?? pkg.plImageTag(options?.version);
363
-
364
- this.checkLicense(options?.license, options?.licenseFile);
365
-
366
- const storagePath = (s: string) => path.join(localRoot, s);
367
-
368
- const primaryFSPath = storagePath('primary');
369
- const workFSPath = storagePath('work');
370
- const libraryFSPath = storagePath('library');
371
-
372
- const primary = plCfg.storageSettingsFromURL(options?.primaryStorageURL ?? `file:.`, '.');
373
- const library = plCfg.storageSettingsFromURL(options?.libraryStorageURL ?? `file:.`, '.');
374
-
375
- const envs: NodeJS.ProcessEnv = {
376
- MINIO_IMAGE: 'quay.io/minio/minio',
377
- MINIO_STORAGE: storagePath('minio'),
378
-
379
- PL_IMAGE: image,
380
- PL_AUTH_HTPASSWD_PATH: pkg.assets('users.htpasswd'),
381
- PL_LICENSE: options?.license,
382
- PL_LICENSE_FILE: options?.licenseFile,
383
-
384
- PL_DATA_DB_ROOT: storagePath('db'),
385
- PL_DATA_PRIMARY_ROOT: primaryFSPath,
386
- PL_DATA_LIBRARY_ROOT: libraryFSPath,
387
- PL_DATA_WORKDIR_ROOT: storagePath('work'),
388
- PL_DATA_PACKAGE_ROOT: storagePath('packages'),
389
-
390
- ...this.configureDockerStorage('primary', primary),
391
- ...this.configureDockerStorage('library', library)
392
- };
393
-
394
- if (options?.['grpc-port'] != undefined) envs.PL_GRPC_PORT = options['grpc-port'].toString();
395
- if (options?.['monitoring-port'] != undefined) envs.PL_MONITORING_PORT = options['monitoring-port'].toString();
396
- if (options?.['debug-port'] != undefined) envs.PL_DEBUG_PORT = options['debug-port'].toString();
397
-
398
- const compose = this.readComposeFile(composeFSPath);
399
-
400
- if (options?.auth) {
401
- if (options.auth.enabled) {
402
- envs['PL_AUTH_ENABLED'] = 'true';
403
- }
404
- if (options.auth.drivers) {
405
- for (const drv of options.auth.drivers) {
406
- if (drv.driver === 'htpasswd') {
407
- envs['PL_AUTH_HTPASSWD_PATH'] = path.resolve(drv.path);
408
- drv.path = '/etc/platforma/users.htpasswd';
409
- }
410
- }
411
- envs['PL_AUTH_DRIVERS'] = JSON.stringify(options.auth.drivers);
412
- }
413
- }
414
-
415
- const result = run.runDocker(
416
- this.logger,
417
- ['compose', `--file=${composeFSPath}`, 'up', '--detach', '--remove-orphans', '--pull=missing', 'backend'],
418
- {
419
- env: envs,
420
- stdio: 'inherit'
421
- },
422
- {
423
- plImage: image,
424
- composePath: composeFSPath,
425
- primaryPath: primaryFSPath,
426
- workPath: workFSPath,
427
- libraryPath: libraryFSPath
428
- }
429
- );
430
-
431
- checkRunError(result, 'failed to start Platforma Backend in Docker');
432
- state.isActive = true;
433
- }
434
-
435
- public stop() {
436
- if (!state.isActive) {
437
- console.log('no running service detected');
438
- return;
439
- }
440
-
441
- const lastRun = state.lastRun!;
442
-
443
- switch (lastRun.mode) {
444
- case 'docker':
445
- const result = spawnSync('docker', ['compose', '--file', lastRun.docker!.composePath!, 'down'], {
446
- env: {
447
- ...process.env,
448
- ...lastRun.envs
449
- },
450
- stdio: 'inherit'
451
- });
452
- state.isActive = false;
453
- if (result.status !== 0) process.exit(result.status);
454
- return;
455
-
456
- case 'process':
457
- state.isActive = false;
458
- process.kill(lastRun.process!.pid!);
459
- return;
460
-
461
- default:
462
- util.assertNever(lastRun.mode);
463
- }
464
- }
465
-
466
- public cleanup() {
467
- const removeWarns = [
468
- "last command run cache ('pl-service start' shorthand will stop working until next full start command call)",
469
- `'platforma' docker compose service containers and volumes`
470
- ];
471
- const dirsToRemove: string[] = [state.path('data')];
472
- if (state.lastRun?.docker?.primaryPath) {
473
- dirsToRemove.push(state.lastRun!.docker!.primaryPath!);
474
- }
475
- if (state.lastRun?.process?.storagePath) {
476
- dirsToRemove.push(state.lastRun!.process!.storagePath!);
477
- }
478
- const storageWarns =
479
- dirsToRemove.length > 0
480
- ? ` - storages (you'll loose all projects and calculation results stored in the service instance):\n - ${dirsToRemove.join('\n - ')}`
481
- : '';
482
-
483
- var warnMessage = `
484
- You are going to reset the state of platforma service
485
- Things to be removed:
486
- - ${removeWarns.join('\n - ')}
487
- ${storageWarns}
488
- `;
489
- this.logger.warn(warnMessage);
490
- if (!util.askYN('Are you sure?')) {
491
- this.logger.info('Reset action was canceled');
492
- return;
493
- }
494
-
495
- const composeToDestroy = new Set<string>(pkg.composeFiles());
496
- if (state.lastRun?.docker?.composePath) {
497
- composeToDestroy.add(state.lastRun.docker.composePath);
498
- }
499
-
500
- for (const composeFile of composeToDestroy) {
501
- this.logger.info(`Destroying docker compose '${composeFile}'`);
502
- this.destroyDocker(composeFile, pkg.plImageTag());
503
- }
504
-
505
- for (const dir of dirsToRemove) {
506
- this.logger.info(`Destroying '${dir}'`);
507
- fs.rmSync(dir, { recursive: true, force: true });
508
- }
509
-
510
- this.logger.info(`Destroying state dir '${state.path()}'`);
511
- fs.rmSync(state.path(), { recursive: true, force: true });
512
-
513
- this.logger.info(
514
- `\nIf you want to remove all downloaded platforma binaries, delete '${pkg.binaries()}' dir manually\n`
515
- );
516
- }
517
-
518
- public mergeLicenseEnvs(flags: { license?: string; 'license-file'?: string }) {
519
- if (flags.license === undefined) {
520
- if ((process.env.MI_LICENSE ?? '') != '') flags.license = process.env.MI_LICENSE;
521
- else if ((process.env.PL_LICENSE ?? '') != '') flags.license = process.env.PL_LICENSE;
522
- }
523
-
524
- // set 'license-file' only if license is still undefined
525
- if (flags['license-file'] === undefined && flags.license === undefined) {
526
- if ((process.env.MI_LICENSE_FILE ?? '') != '') flags['license-file'] = process.env.MI_LICENSE_FILE;
527
- else if ((process.env.PL_LICENSE_FILE ?? '') != '') flags['license-file'] = process.env.PL_LICENSE_FILE;
528
- else if (fs.existsSync(path.resolve(os.homedir(), '.pl.license')))
529
- flags['license-file'] = path.resolve(os.homedir(), '.pl.license');
530
- }
531
- }
532
-
533
- public initAuthDriversList(
534
- flags: {
535
- 'auth-htpasswd-file'?: string;
536
-
537
- 'auth-ldap-server'?: string;
538
- 'auth-ldap-default-dn'?: string;
539
- },
540
- workdir: string
541
- ): types.authDriver[] | undefined {
542
- var authDrivers: types.authDriver[] = [];
543
- if (flags['auth-htpasswd-file']) {
544
- authDrivers.push({
545
- driver: 'htpasswd',
546
- path: path.resolve(workdir, flags['auth-htpasswd-file'])
547
- });
548
- }
549
-
550
- if (Boolean(flags['auth-ldap-server']) !== Boolean(flags['auth-ldap-default-dn'])) {
551
- throw new Error("LDAP auth settings require both 'server' and 'default DN' options to be set");
552
- }
553
-
554
- if (flags['auth-ldap-server']) {
555
- authDrivers.push({
556
- driver: 'ldap',
557
- serverUrl: flags['auth-ldap-server'],
558
- defaultDN: flags['auth-ldap-default-dn']!
559
- });
560
- }
561
-
562
- if (authDrivers.length === 0) {
563
- return undefined;
564
- }
565
-
566
- return [{ driver: 'jwt', key: this.getLastJwt() }, ...authDrivers] as types.authDriver[];
567
- }
568
-
569
- /** Gets the last stored JWT secret key or generates it and stores in a file. */
570
- public getLastJwt() {
571
- const jwtFile = state.path('auth.jwt');
572
- const encoding = 'utf-8';
573
-
574
- let lastJwt = '';
575
- try {
576
- lastJwt = fs.readFileSync(jwtFile, { encoding });
577
- } catch (e: any) {}
578
-
579
- if (lastJwt == '') {
580
- lastJwt = util.randomStr(64);
581
- fs.writeFileSync(jwtFile, lastJwt, { encoding });
582
- }
583
-
584
- return lastJwt;
585
- }
586
-
587
- private destroyDocker(composePath: string, image: string) {
588
- const stubStoragePath = state.path('data', 'stub');
589
- const result = spawnSync('docker', ['compose', '--file', composePath, 'down', '--volumes', '--remove-orphans'], {
590
- env: {
591
- ...process.env,
592
- PL_IMAGE: 'scratch',
593
-
594
- PL_DATA_DB_ROOT: stubStoragePath,
595
- PL_DATA_PRIMARY_ROOT: stubStoragePath,
596
- PL_DATA_LIBRARY_ROOT: stubStoragePath,
597
- PL_DATA_WORKDIR_ROOT: stubStoragePath,
598
- PL_DATA_PACKAGE_ROOT: stubStoragePath,
599
-
600
- MINIO_IMAGE: 'scratch',
601
- MINIO_STORAGE: stubStoragePath
602
- },
603
- stdio: 'inherit'
604
- });
605
-
606
- if (result.status !== 0) process.exit(result.status);
607
- }
608
-
609
- private checkLicense(value?: string, file?: string) {
610
- if (value !== undefined && value != '') return;
611
-
612
- if (file !== undefined && file != '') return;
613
-
614
- this.logger.error(`A license for Platforma Backend must be set.
615
-
616
- You can provide the license directly using the '--license' flag
617
- or use the '--license-file' flag if the license is stored in a file.
618
-
619
- Alternatively, you can set it via the environment variables 'MI_LICENSE' or 'PL_LICENSE'.
620
-
621
- The license file can also be set with the variables 'MI_LICENSE_FILE' or 'PL_LICENSE_FILE',
622
- or stored in '$HOME/.pl.license'.
623
-
624
- You can obtain the license from "https://licensing.milaboratories.com".`);
625
-
626
- throw new Error(`The license was not provided.`);
627
- }
628
-
629
- private configureDockerStorage(storageID: string, storage: types.storageOptions): NodeJS.ProcessEnv {
630
- const envs: NodeJS.ProcessEnv = {};
631
- const sType = storage.type;
632
- storageID = storageID.toUpperCase();
633
-
634
- switch (sType) {
635
- case 'S3':
636
- envs[`PL_DATA_${storageID}_TYPE`] = 'S3';
637
- envs[`PL_DATA_${storageID}_S3_BUCKET`] = storage.bucketName!;
638
-
639
- if (storage.endpoint) envs[`PL_DATA_${storageID}_S3_ENDPOINT`] = storage.endpoint;
640
- if (storage.presignEndpoint) envs[`PL_DATA_${storageID}_S3_PRESIGN_ENDPOINT`] = storage.presignEndpoint;
641
- if (storage.region) envs[`PL_DATA_${storageID}_S3_REGION`] = storage.region;
642
- if (storage.key) envs[`PL_DATA_${storageID}_S3_KEY`] = storage.key;
643
- if (storage.secret) envs[`PL_DATA_${storageID}_S3_SECRET`] = storage.secret;
644
-
645
- return envs;
646
-
647
- case 'FS':
648
- envs[`PL_DATA_${storageID}_TYPE`] = 'FS';
649
-
650
- return envs;
651
-
652
- default:
653
- util.assertNever(sType);
654
- }
655
-
656
- return {};
657
- }
658
-
659
- private readComposeFile(fPath: string): any {
660
- const yamlData = fs.readFileSync(fPath);
661
- return yaml.parse(yamlData.toString());
662
- }
663
- private writeComposeFile(fPath: string, data: any) {
664
- fs.writeFileSync(fPath, yaml.stringify(data));
665
- }
666
- }
667
-
668
- export function checkRunError(result: SpawnSyncReturns<Buffer>, message?: string) {
669
- if (result.error) {
670
- throw result.error;
671
- }
672
-
673
- const msg = message ?? 'failed to run command';
674
-
675
- if (result.status !== 0) {
676
- throw new Error(`${msg}, process exited with code '${result.status}'`);
677
- }
678
- }
679
-
680
- export type startLocalOptions = {
681
- version?: string;
682
- binaryPath?: string;
683
- configPath?: string;
684
- configOptions?: plCfg.plOptions;
685
- workdir?: string;
686
-
687
- primaryURL?: string;
688
- libraryURL?: string;
689
- };
690
-
691
- export type startLocalFSOptions = startLocalOptions;
692
-
693
- export type startLocalS3Options = startLocalOptions & {
694
- minioPort?: number;
695
- minioConsolePort?: number;
696
- };
package/src/index.ts DELETED
@@ -1,10 +0,0 @@
1
- import Stop from './commands/stop';
2
- import Reset from './commands/reset';
3
- import Start from './commands/start';
4
-
5
- // prettier-ignore
6
- export const COMMANDS = {
7
- 'stop': Stop,
8
- 'start': Start,
9
- 'reset': Reset
10
- };