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