@kapeta/local-cluster-service 0.9.0 → 0.9.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.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/src/containerManager.d.ts +3 -0
- package/dist/cjs/src/containerManager.js +9 -1
- package/dist/cjs/src/utils/BlockInstanceRunner.js +8 -7
- package/dist/esm/src/containerManager.d.ts +3 -0
- package/dist/esm/src/containerManager.js +9 -1
- package/dist/esm/src/utils/BlockInstanceRunner.js +8 -7
- package/package.json +1 -1
- package/src/containerManager.ts +10 -1
- package/src/utils/BlockInstanceRunner.ts +8 -7
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.9.1](https://github.com/kapetacom/local-cluster-service/compare/v0.9.0...v0.9.1) (2023-07-26)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* Rename containers before deleting to avoid name conflicts ([#49](https://github.com/kapetacom/local-cluster-service/issues/49)) ([ac977f0](https://github.com/kapetacom/local-cluster-service/commit/ac977f0a9f18f57a517342d51e4c1e1fee68e4ff))
|
7
|
+
|
1
8
|
# [0.9.0](https://github.com/kapetacom/local-cluster-service/compare/v0.8.3...v0.9.0) (2023-07-24)
|
2
9
|
|
3
10
|
|
@@ -76,6 +76,9 @@ declare class ContainerManager {
|
|
76
76
|
waitForHealthy(container: Container, attempt?: number): Promise<void>;
|
77
77
|
_isReady(container: Container): Promise<any>;
|
78
78
|
_isHealthy(container: Container): Promise<boolean>;
|
79
|
+
remove(container: Container, opts?: {
|
80
|
+
force?: boolean;
|
81
|
+
}): Promise<void>;
|
79
82
|
/**
|
80
83
|
*
|
81
84
|
* @param name
|
@@ -13,6 +13,7 @@ const node_docker_api_1 = require("node-docker-api");
|
|
13
13
|
const nodejs_utils_1 = require("@kapeta/nodejs-utils");
|
14
14
|
const local_cluster_config_1 = __importDefault(require("@kapeta/local-cluster-config"));
|
15
15
|
const utils_1 = require("./utils/utils");
|
16
|
+
const node_uuid_1 = __importDefault(require("node-uuid"));
|
16
17
|
const LABEL_PORT_PREFIX = 'kapeta_port-';
|
17
18
|
const NANO_SECOND = 1000000;
|
18
19
|
const HEALTH_CHECK_INTERVAL = 3000;
|
@@ -324,6 +325,13 @@ class ContainerManager {
|
|
324
325
|
return false;
|
325
326
|
}
|
326
327
|
}
|
328
|
+
async remove(container, opts) {
|
329
|
+
const newName = 'deleting-' + node_uuid_1.default.v4();
|
330
|
+
const containerData = container.data;
|
331
|
+
// Rename the container first to avoid name conflicts if people start the same container
|
332
|
+
await container.rename({ name: newName });
|
333
|
+
await container.delete({ force: !!opts?.force });
|
334
|
+
}
|
327
335
|
/**
|
328
336
|
*
|
329
337
|
* @param name
|
@@ -379,7 +387,7 @@ class ContainerInfo {
|
|
379
387
|
await this._container.stop();
|
380
388
|
}
|
381
389
|
async remove(opts) {
|
382
|
-
await this._container
|
390
|
+
await exports.containerManager.remove(this._container, opts);
|
383
391
|
}
|
384
392
|
async getPort(type) {
|
385
393
|
const ports = await this.getPorts();
|
@@ -136,13 +136,13 @@ class BlockInstanceRunner {
|
|
136
136
|
const containerName = (0, utils_1.getBlockInstanceContainerName)(blockInstance.id);
|
137
137
|
const logs = new LogData_1.LogData();
|
138
138
|
logs.addLog(`Starting block ${blockInstance.ref}`);
|
139
|
-
|
139
|
+
let containerInfo = await containerManager_1.containerManager.getContainerByName(containerName);
|
140
140
|
let container = containerInfo?.native;
|
141
141
|
console.log('Starting dev container', containerName);
|
142
|
-
if (
|
142
|
+
if (containerInfo) {
|
143
143
|
console.log(`Dev container already exists. Deleting...`);
|
144
144
|
try {
|
145
|
-
await
|
145
|
+
await containerInfo.remove({
|
146
146
|
force: true,
|
147
147
|
});
|
148
148
|
}
|
@@ -150,6 +150,7 @@ class BlockInstanceRunner {
|
|
150
150
|
throw new Error('Failed to delete existing container: ' + e.message);
|
151
151
|
}
|
152
152
|
container = undefined;
|
153
|
+
containerInfo = undefined;
|
153
154
|
}
|
154
155
|
logs.addLog(`Creating new container for block: ${containerName}`);
|
155
156
|
console.log('Creating new dev container', containerName, dockerImage);
|
@@ -245,7 +246,7 @@ class BlockInstanceRunner {
|
|
245
246
|
const data = status.data;
|
246
247
|
if (deleteOnExit) {
|
247
248
|
try {
|
248
|
-
await
|
249
|
+
await containerManager_1.containerManager.remove(container);
|
249
250
|
}
|
250
251
|
catch (e) { }
|
251
252
|
}
|
@@ -262,7 +263,7 @@ class BlockInstanceRunner {
|
|
262
263
|
try {
|
263
264
|
await localContainer.stop();
|
264
265
|
if (deleteOnExit) {
|
265
|
-
await
|
266
|
+
await containerManager_1.containerManager.remove(localContainer);
|
266
267
|
}
|
267
268
|
}
|
268
269
|
catch (e) { }
|
@@ -369,7 +370,7 @@ class BlockInstanceRunner {
|
|
369
370
|
if (containerData.State?.ExitCode > 0) {
|
370
371
|
logs.addLog(`Container exited with code: ${containerData.State.ExitCode}. Deleting...`);
|
371
372
|
try {
|
372
|
-
await
|
373
|
+
await containerManager_1.containerManager.remove(container);
|
373
374
|
}
|
374
375
|
catch (e) { }
|
375
376
|
container = undefined;
|
@@ -382,7 +383,7 @@ class BlockInstanceRunner {
|
|
382
383
|
catch (e) {
|
383
384
|
console.warn('Failed to start container. Deleting...', e);
|
384
385
|
try {
|
385
|
-
await
|
386
|
+
await containerManager_1.containerManager.remove(container);
|
386
387
|
}
|
387
388
|
catch (e) { }
|
388
389
|
container = undefined;
|
@@ -76,6 +76,9 @@ declare class ContainerManager {
|
|
76
76
|
waitForHealthy(container: Container, attempt?: number): Promise<void>;
|
77
77
|
_isReady(container: Container): Promise<any>;
|
78
78
|
_isHealthy(container: Container): Promise<boolean>;
|
79
|
+
remove(container: Container, opts?: {
|
80
|
+
force?: boolean;
|
81
|
+
}): Promise<void>;
|
79
82
|
/**
|
80
83
|
*
|
81
84
|
* @param name
|
@@ -7,6 +7,7 @@ import { Docker } from 'node-docker-api';
|
|
7
7
|
import { parseKapetaUri } from '@kapeta/nodejs-utils';
|
8
8
|
import ClusterConfiguration from '@kapeta/local-cluster-config';
|
9
9
|
import { getBindHost } from './utils/utils';
|
10
|
+
import uuid from "node-uuid";
|
10
11
|
const LABEL_PORT_PREFIX = 'kapeta_port-';
|
11
12
|
const NANO_SECOND = 1000000;
|
12
13
|
const HEALTH_CHECK_INTERVAL = 3000;
|
@@ -318,6 +319,13 @@ class ContainerManager {
|
|
318
319
|
return false;
|
319
320
|
}
|
320
321
|
}
|
322
|
+
async remove(container, opts) {
|
323
|
+
const newName = 'deleting-' + uuid.v4();
|
324
|
+
const containerData = container.data;
|
325
|
+
// Rename the container first to avoid name conflicts if people start the same container
|
326
|
+
await container.rename({ name: newName });
|
327
|
+
await container.delete({ force: !!opts?.force });
|
328
|
+
}
|
321
329
|
/**
|
322
330
|
*
|
323
331
|
* @param name
|
@@ -373,7 +381,7 @@ export class ContainerInfo {
|
|
373
381
|
await this._container.stop();
|
374
382
|
}
|
375
383
|
async remove(opts) {
|
376
|
-
await this._container
|
384
|
+
await containerManager.remove(this._container, opts);
|
377
385
|
}
|
378
386
|
async getPort(type) {
|
379
387
|
const ports = await this.getPorts();
|
@@ -130,13 +130,13 @@ export class BlockInstanceRunner {
|
|
130
130
|
const containerName = getBlockInstanceContainerName(blockInstance.id);
|
131
131
|
const logs = new LogData();
|
132
132
|
logs.addLog(`Starting block ${blockInstance.ref}`);
|
133
|
-
|
133
|
+
let containerInfo = await containerManager.getContainerByName(containerName);
|
134
134
|
let container = containerInfo?.native;
|
135
135
|
console.log('Starting dev container', containerName);
|
136
|
-
if (
|
136
|
+
if (containerInfo) {
|
137
137
|
console.log(`Dev container already exists. Deleting...`);
|
138
138
|
try {
|
139
|
-
await
|
139
|
+
await containerInfo.remove({
|
140
140
|
force: true,
|
141
141
|
});
|
142
142
|
}
|
@@ -144,6 +144,7 @@ export class BlockInstanceRunner {
|
|
144
144
|
throw new Error('Failed to delete existing container: ' + e.message);
|
145
145
|
}
|
146
146
|
container = undefined;
|
147
|
+
containerInfo = undefined;
|
147
148
|
}
|
148
149
|
logs.addLog(`Creating new container for block: ${containerName}`);
|
149
150
|
console.log('Creating new dev container', containerName, dockerImage);
|
@@ -239,7 +240,7 @@ export class BlockInstanceRunner {
|
|
239
240
|
const data = status.data;
|
240
241
|
if (deleteOnExit) {
|
241
242
|
try {
|
242
|
-
await
|
243
|
+
await containerManager.remove(container);
|
243
244
|
}
|
244
245
|
catch (e) { }
|
245
246
|
}
|
@@ -256,7 +257,7 @@ export class BlockInstanceRunner {
|
|
256
257
|
try {
|
257
258
|
await localContainer.stop();
|
258
259
|
if (deleteOnExit) {
|
259
|
-
await
|
260
|
+
await containerManager.remove(localContainer);
|
260
261
|
}
|
261
262
|
}
|
262
263
|
catch (e) { }
|
@@ -363,7 +364,7 @@ export class BlockInstanceRunner {
|
|
363
364
|
if (containerData.State?.ExitCode > 0) {
|
364
365
|
logs.addLog(`Container exited with code: ${containerData.State.ExitCode}. Deleting...`);
|
365
366
|
try {
|
366
|
-
await
|
367
|
+
await containerManager.remove(container);
|
367
368
|
}
|
368
369
|
catch (e) { }
|
369
370
|
container = undefined;
|
@@ -376,7 +377,7 @@ export class BlockInstanceRunner {
|
|
376
377
|
catch (e) {
|
377
378
|
console.warn('Failed to start container. Deleting...', e);
|
378
379
|
try {
|
379
|
-
await
|
380
|
+
await containerManager.remove(container);
|
380
381
|
}
|
381
382
|
catch (e) { }
|
382
383
|
container = undefined;
|
package/package.json
CHANGED
package/src/containerManager.ts
CHANGED
@@ -8,6 +8,7 @@ import { parseKapetaUri } from '@kapeta/nodejs-utils';
|
|
8
8
|
import ClusterConfiguration from '@kapeta/local-cluster-config';
|
9
9
|
import { Container } from 'node-docker-api/lib/container';
|
10
10
|
import { getBindHost } from './utils/utils';
|
11
|
+
import uuid from "node-uuid";
|
11
12
|
|
12
13
|
type StringMap = { [key: string]: string };
|
13
14
|
|
@@ -422,6 +423,14 @@ class ContainerManager {
|
|
422
423
|
}
|
423
424
|
}
|
424
425
|
|
426
|
+
async remove(container:Container, opts?: { force?: boolean }) {
|
427
|
+
const newName = 'deleting-' + uuid.v4()
|
428
|
+
const containerData = container.data as any;
|
429
|
+
// Rename the container first to avoid name conflicts if people start the same container
|
430
|
+
await container.rename({ name: newName });
|
431
|
+
await container.delete({ force: !!opts?.force });
|
432
|
+
}
|
433
|
+
|
425
434
|
/**
|
426
435
|
*
|
427
436
|
* @param name
|
@@ -488,7 +497,7 @@ export class ContainerInfo {
|
|
488
497
|
}
|
489
498
|
|
490
499
|
async remove(opts?: { force?: boolean }) {
|
491
|
-
await this._container
|
500
|
+
await containerManager.remove(this._container, opts);
|
492
501
|
}
|
493
502
|
|
494
503
|
async getPort(type: string) {
|
@@ -171,21 +171,22 @@ export class BlockInstanceRunner {
|
|
171
171
|
const containerName = getBlockInstanceContainerName(blockInstance.id);
|
172
172
|
const logs = new LogData();
|
173
173
|
logs.addLog(`Starting block ${blockInstance.ref}`);
|
174
|
-
|
174
|
+
let containerInfo = await containerManager.getContainerByName(containerName);
|
175
175
|
let container = containerInfo?.native;
|
176
176
|
|
177
177
|
console.log('Starting dev container', containerName);
|
178
178
|
|
179
|
-
if (
|
179
|
+
if (containerInfo) {
|
180
180
|
console.log(`Dev container already exists. Deleting...`);
|
181
181
|
try {
|
182
|
-
await
|
182
|
+
await containerInfo.remove({
|
183
183
|
force: true,
|
184
184
|
});
|
185
185
|
} catch (e: any) {
|
186
186
|
throw new Error('Failed to delete existing container: ' + e.message);
|
187
187
|
}
|
188
188
|
container = undefined;
|
189
|
+
containerInfo = undefined;
|
189
190
|
}
|
190
191
|
|
191
192
|
logs.addLog(`Creating new container for block: ${containerName}`);
|
@@ -298,7 +299,7 @@ export class BlockInstanceRunner {
|
|
298
299
|
const data = status.data as any;
|
299
300
|
if (deleteOnExit) {
|
300
301
|
try {
|
301
|
-
await
|
302
|
+
await containerManager.remove(container);
|
302
303
|
} catch (e: any) {}
|
303
304
|
}
|
304
305
|
outputEvents.emit('exit', data?.State?.ExitCode ?? 0);
|
@@ -316,7 +317,7 @@ export class BlockInstanceRunner {
|
|
316
317
|
try {
|
317
318
|
await localContainer.stop();
|
318
319
|
if (deleteOnExit) {
|
319
|
-
await
|
320
|
+
await containerManager.remove(localContainer);
|
320
321
|
}
|
321
322
|
} catch (e) {}
|
322
323
|
localContainer = null;
|
@@ -448,7 +449,7 @@ export class BlockInstanceRunner {
|
|
448
449
|
if (containerData.State?.ExitCode > 0) {
|
449
450
|
logs.addLog(`Container exited with code: ${containerData.State.ExitCode}. Deleting...`);
|
450
451
|
try {
|
451
|
-
await
|
452
|
+
await containerManager.remove(container);
|
452
453
|
} catch (e) {}
|
453
454
|
container = undefined;
|
454
455
|
} else {
|
@@ -458,7 +459,7 @@ export class BlockInstanceRunner {
|
|
458
459
|
} catch (e) {
|
459
460
|
console.warn('Failed to start container. Deleting...', e);
|
460
461
|
try {
|
461
|
-
await
|
462
|
+
await containerManager.remove(container);
|
462
463
|
} catch (e) {}
|
463
464
|
container = undefined;
|
464
465
|
}
|