@kapeta/local-cluster-service 0.19.6 → 0.19.7
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/CHANGELOG.md +7 -0
- package/dist/cjs/src/containerManager.d.ts +39 -32
- package/dist/cjs/src/containerManager.js +138 -108
- package/dist/cjs/src/instanceManager.js +28 -18
- package/dist/cjs/src/operatorManager.js +3 -0
- package/dist/cjs/src/taskManager.js +4 -1
- package/dist/cjs/src/utils/BlockInstanceRunner.js +9 -0
- package/dist/esm/src/containerManager.d.ts +39 -32
- package/dist/esm/src/containerManager.js +138 -108
- package/dist/esm/src/instanceManager.js +28 -18
- package/dist/esm/src/operatorManager.js +3 -0
- package/dist/esm/src/taskManager.js +4 -1
- package/dist/esm/src/utils/BlockInstanceRunner.js +9 -0
- package/package.json +5 -2
- package/src/containerManager.ts +188 -140
- package/src/instanceManager.ts +44 -20
- package/src/operatorManager.ts +11 -1
- package/src/taskManager.ts +4 -1
- package/src/utils/BlockInstanceRunner.ts +19 -3
@@ -262,6 +262,9 @@ class InstanceManager {
|
|
262
262
|
if (instance.status === types_1.InstanceStatus.STOPPED) {
|
263
263
|
return;
|
264
264
|
}
|
265
|
+
if (instance.status === types_1.InstanceStatus.STOPPING) {
|
266
|
+
return;
|
267
|
+
}
|
265
268
|
if (changeDesired && instance.desiredStatus !== types_1.DesiredInstanceStatus.EXTERNAL) {
|
266
269
|
instance.desiredStatus = types_1.DesiredInstanceStatus.STOP;
|
267
270
|
}
|
@@ -392,18 +395,18 @@ class InstanceManager {
|
|
392
395
|
const startTime = Date.now();
|
393
396
|
try {
|
394
397
|
const processInfo = await runner.start(blockRef, instanceId, instanceConfig);
|
395
|
-
instance.status = types_1.InstanceStatus.
|
398
|
+
instance.status = types_1.InstanceStatus.STARTING;
|
396
399
|
return this.saveInternalInstance({
|
397
400
|
...instance,
|
398
401
|
type: processInfo.type,
|
399
402
|
pid: processInfo.pid ?? -1,
|
400
403
|
health: null,
|
401
404
|
portType: processInfo.portType,
|
402
|
-
status: types_1.InstanceStatus.
|
405
|
+
status: types_1.InstanceStatus.STARTING,
|
403
406
|
});
|
404
407
|
}
|
405
408
|
catch (e) {
|
406
|
-
console.warn('Failed to start instance: ', systemId, instanceId, blockRef, e
|
409
|
+
console.warn('Failed to start instance: ', systemId, instanceId, blockRef, e);
|
407
410
|
const logs = [
|
408
411
|
{
|
409
412
|
source: 'stdout',
|
@@ -550,7 +553,7 @@ class InstanceManager {
|
|
550
553
|
await this.start(instance.systemId, instance.instanceId);
|
551
554
|
}
|
552
555
|
catch (e) {
|
553
|
-
console.warn('Failed to start instance', instance.systemId, instance.instanceId, e);
|
556
|
+
console.warn('Failed to start previously stopped instance', instance.systemId, instance.instanceId, e);
|
554
557
|
}
|
555
558
|
return;
|
556
559
|
}
|
@@ -594,31 +597,38 @@ class InstanceManager {
|
|
594
597
|
return types_1.InstanceStatus.STOPPED;
|
595
598
|
}
|
596
599
|
const state = await container.status();
|
597
|
-
if (state
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
600
|
+
if (!state) {
|
601
|
+
return types_1.InstanceStatus.STOPPED;
|
602
|
+
}
|
603
|
+
const statusType = state.Status;
|
604
|
+
if (statusType === 'running') {
|
605
|
+
if (state.Health?.Status) {
|
606
|
+
const healthStatusType = state.Health.Status;
|
607
|
+
if (healthStatusType === 'healthy' || healthStatusType === 'none') {
|
608
|
+
return types_1.InstanceStatus.READY;
|
609
|
+
}
|
610
|
+
if (healthStatusType === 'starting') {
|
611
|
+
return types_1.InstanceStatus.STARTING;
|
612
|
+
}
|
613
|
+
if (healthStatusType === 'unhealthy') {
|
614
|
+
return types_1.InstanceStatus.UNHEALTHY;
|
615
|
+
}
|
606
616
|
}
|
607
617
|
return types_1.InstanceStatus.READY;
|
608
618
|
}
|
609
|
-
if (
|
619
|
+
if (statusType === 'created') {
|
610
620
|
return types_1.InstanceStatus.STARTING;
|
611
621
|
}
|
612
|
-
if (
|
622
|
+
if (statusType === 'exited' || statusType === 'dead') {
|
613
623
|
return types_1.InstanceStatus.STOPPED;
|
614
624
|
}
|
615
|
-
if (
|
625
|
+
if (statusType === 'removing') {
|
616
626
|
return types_1.InstanceStatus.BUSY;
|
617
627
|
}
|
618
|
-
if (
|
628
|
+
if (statusType === 'restarting') {
|
619
629
|
return types_1.InstanceStatus.BUSY;
|
620
630
|
}
|
621
|
-
if (
|
631
|
+
if (statusType === 'paused') {
|
622
632
|
return types_1.InstanceStatus.BUSY;
|
623
633
|
}
|
624
634
|
return types_1.InstanceStatus.STOPPED;
|
@@ -146,8 +146,11 @@ class OperatorManager {
|
|
146
146
|
const containerName = `kapeta-resource-${(0, md5_1.default)(nameParts.join('_'))}`;
|
147
147
|
const PortBindings = {};
|
148
148
|
const Env = [];
|
149
|
+
const systemUri = (0, nodejs_utils_1.parseKapetaUri)(systemId);
|
149
150
|
const Labels = {
|
150
151
|
kapeta: 'true',
|
152
|
+
[containerManager_1.COMPOSE_LABEL_PROJECT]: systemUri.id.replace(/[^a-z0-9]/gi, '_'),
|
153
|
+
[containerManager_1.COMPOSE_LABEL_SERVICE]: [resourceType, version].join('_').replace(/[^a-z0-9]/gi, '_'),
|
151
154
|
};
|
152
155
|
const operatorMetadata = operator.getDefinitionInfo().definition.metadata;
|
153
156
|
const bindHost = (0, utils_1.getBindHost)();
|
@@ -90,7 +90,9 @@ class TaskManager {
|
|
90
90
|
});
|
91
91
|
this._tasks.push(task);
|
92
92
|
socketManager_1.socketManager.emitGlobal(EVENT_TASK_ADDED, task.toData());
|
93
|
-
this.invokeTask(task).catch(() => {
|
93
|
+
this.invokeTask(task).catch((err) => {
|
94
|
+
console.warn(`Task ${task.id} failed`, err);
|
95
|
+
});
|
94
96
|
return task;
|
95
97
|
}
|
96
98
|
async waitFor(filter) {
|
@@ -145,6 +147,7 @@ class TaskManager {
|
|
145
147
|
task.emitUpdate();
|
146
148
|
}
|
147
149
|
catch (e) {
|
150
|
+
console.warn(`Task ${task.id} failed while waiting for it to resolve`, e);
|
148
151
|
task.errorMessage = e.message;
|
149
152
|
task.status = TaskStatus.FAILED;
|
150
153
|
task.future.reject(e);
|
@@ -146,6 +146,7 @@ class BlockInstanceRunner {
|
|
146
146
|
if (localContainer.healthcheck) {
|
147
147
|
HealthCheck = containerManager_1.containerManager.toDockerHealth({ cmd: localContainer.healthcheck });
|
148
148
|
}
|
149
|
+
const systemUri = (0, nodejs_utils_1.parseKapetaUri)(this._systemId);
|
149
150
|
return this.ensureContainer({
|
150
151
|
...dockerOpts,
|
151
152
|
Image: dockerImage,
|
@@ -154,6 +155,8 @@ class BlockInstanceRunner {
|
|
154
155
|
Labels: {
|
155
156
|
...customLabels,
|
156
157
|
instance: blockInstance.id,
|
158
|
+
[containerManager_1.COMPOSE_LABEL_PROJECT]: systemUri.id.replace(/[^a-z0-9]/gi, '_'),
|
159
|
+
[containerManager_1.COMPOSE_LABEL_SERVICE]: blockInfo.id.replace(/[^a-z0-9]/gi, '_'),
|
157
160
|
},
|
158
161
|
HealthCheck,
|
159
162
|
ExposedPorts,
|
@@ -195,12 +198,15 @@ class BlockInstanceRunner {
|
|
195
198
|
const containerName = (0, utils_1.getBlockInstanceContainerName)(this._systemId, blockInstance.id);
|
196
199
|
// For windows we need to default to root
|
197
200
|
const innerHome = process.platform === 'win32' ? '/root/.kapeta' : local_cluster_config_1.default.getKapetaBasedir();
|
201
|
+
const systemUri = (0, nodejs_utils_1.parseKapetaUri)(this._systemId);
|
198
202
|
return this.ensureContainer({
|
199
203
|
Image: dockerImage,
|
200
204
|
name: containerName,
|
201
205
|
ExposedPorts,
|
202
206
|
Labels: {
|
203
207
|
instance: blockInstance.id,
|
208
|
+
[containerManager_1.COMPOSE_LABEL_PROJECT]: systemUri.id.replace(/[^a-z0-9]/gi, '_'),
|
209
|
+
[containerManager_1.COMPOSE_LABEL_SERVICE]: blockInfo.id.replace(/[^a-z0-9]/gi, '_'),
|
204
210
|
},
|
205
211
|
Env: [
|
206
212
|
...DOCKER_ENV_VARS,
|
@@ -273,6 +279,7 @@ class BlockInstanceRunner {
|
|
273
279
|
}
|
274
280
|
// For windows we need to default to root
|
275
281
|
const innerHome = process.platform === 'win32' ? '/root/.kapeta' : local_cluster_config_1.default.getKapetaBasedir();
|
282
|
+
const systemUri = (0, nodejs_utils_1.parseKapetaUri)(this._systemId);
|
276
283
|
logs.addLog(`Creating new container for block: ${containerName}`);
|
277
284
|
const out = await this.ensureContainer({
|
278
285
|
Image: dockerImage,
|
@@ -289,6 +296,8 @@ class BlockInstanceRunner {
|
|
289
296
|
},
|
290
297
|
Labels: {
|
291
298
|
instance: blockInstance.id,
|
299
|
+
[containerManager_1.COMPOSE_LABEL_PROJECT]: systemUri.id.replace(/[^a-z0-9]/gi, '_'),
|
300
|
+
[containerManager_1.COMPOSE_LABEL_SERVICE]: blockUri.id.replace(/[^a-z0-9]/gi, '_'),
|
292
301
|
},
|
293
302
|
Env: [
|
294
303
|
`KAPETA_INSTANCE_NAME=${blockInstance.ref}`,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kapeta/local-cluster-service",
|
3
|
-
"version": "0.19.
|
3
|
+
"version": "0.19.7",
|
4
4
|
"description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
|
5
5
|
"type": "commonjs",
|
6
6
|
"exports": {
|
@@ -52,8 +52,11 @@
|
|
52
52
|
"@kapeta/schemas": "^0.0.58",
|
53
53
|
"@kapeta/sdk-config": "<2",
|
54
54
|
"@kapeta/web-microfrontend": "^0.2.1",
|
55
|
+
"@types/dockerode": "^3.3.19",
|
56
|
+
"@types/stream-json": "^1.7.3",
|
55
57
|
"async-lock": "^1.4.0",
|
56
58
|
"chokidar": "^3.5.3",
|
59
|
+
"dockerode": "^3.3.5",
|
57
60
|
"express": "4.17.1",
|
58
61
|
"express-promise-router": "^4.1.1",
|
59
62
|
"fs-extra": "^11.1.0",
|
@@ -62,11 +65,11 @@
|
|
62
65
|
"lodash": "^4.17.15",
|
63
66
|
"md5": "2.2.1",
|
64
67
|
"node-cache": "^5.1.2",
|
65
|
-
"node-docker-api": "1.1.22",
|
66
68
|
"node-uuid": "^1.4.8",
|
67
69
|
"request": "2.88.2",
|
68
70
|
"request-promise": "4.2.6",
|
69
71
|
"socket.io": "^4.5.2",
|
72
|
+
"stream-json": "^1.8.0",
|
70
73
|
"tar-stream": "^3.1.6",
|
71
74
|
"typescript": "^5.1.6",
|
72
75
|
"yaml": "^1.6.0"
|