@kapeta/local-cluster-service 0.34.1 → 0.35.0

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 (43) hide show
  1. package/.github/workflows/check-license.yml +0 -1
  2. package/CHANGELOG.md +14 -0
  3. package/dist/cjs/src/config/routes.js +9 -0
  4. package/dist/cjs/src/containerManager.d.ts +2 -8
  5. package/dist/cjs/src/containerManager.js +4 -4
  6. package/dist/cjs/src/instanceManager.d.ts +2 -1
  7. package/dist/cjs/src/instanceManager.js +43 -1
  8. package/dist/cjs/src/operatorManager.d.ts +2 -2
  9. package/dist/cjs/src/operatorManager.js +2 -7
  10. package/dist/cjs/src/proxy/types/rest.js +2 -1
  11. package/dist/cjs/src/proxy/types/web.js +2 -1
  12. package/dist/cjs/src/serviceManager.d.ts +1 -0
  13. package/dist/cjs/src/serviceManager.js +9 -9
  14. package/dist/cjs/src/types.d.ts +39 -0
  15. package/dist/cjs/src/utils/BlockInstanceRunner.js +16 -12
  16. package/dist/cjs/src/utils/utils.d.ts +5 -1
  17. package/dist/cjs/src/utils/utils.js +11 -1
  18. package/dist/esm/src/config/routes.js +9 -0
  19. package/dist/esm/src/containerManager.d.ts +2 -8
  20. package/dist/esm/src/containerManager.js +4 -4
  21. package/dist/esm/src/instanceManager.d.ts +2 -1
  22. package/dist/esm/src/instanceManager.js +43 -1
  23. package/dist/esm/src/operatorManager.d.ts +2 -2
  24. package/dist/esm/src/operatorManager.js +2 -7
  25. package/dist/esm/src/proxy/types/rest.js +2 -1
  26. package/dist/esm/src/proxy/types/web.js +2 -1
  27. package/dist/esm/src/serviceManager.d.ts +1 -0
  28. package/dist/esm/src/serviceManager.js +9 -9
  29. package/dist/esm/src/types.d.ts +39 -0
  30. package/dist/esm/src/utils/BlockInstanceRunner.js +16 -12
  31. package/dist/esm/src/utils/utils.d.ts +5 -1
  32. package/dist/esm/src/utils/utils.js +11 -1
  33. package/package.json +6 -5
  34. package/src/config/routes.ts +15 -0
  35. package/src/containerManager.ts +5 -12
  36. package/src/instanceManager.ts +72 -4
  37. package/src/operatorManager.ts +5 -13
  38. package/src/proxy/types/rest.ts +2 -1
  39. package/src/proxy/types/web.ts +3 -2
  40. package/src/serviceManager.ts +11 -8
  41. package/src/types.ts +35 -0
  42. package/src/utils/BlockInstanceRunner.ts +21 -14
  43. package/src/utils/utils.ts +13 -2
@@ -5,19 +5,20 @@
5
5
 
6
6
  import FSExtra from 'fs-extra';
7
7
  import ClusterConfig, { DefinitionInfo } from '@kapeta/local-cluster-config';
8
- import { getBindHost, getBlockInstanceContainerName, readYML } from './utils';
8
+ import { getBindHost, getBlockInstanceContainerName, readYML, toPortInfo } from './utils';
9
9
  import { KapetaURI, parseKapetaUri, normalizeKapetaUri } from '@kapeta/nodejs-utils';
10
10
  import { DEFAULT_PORT_TYPE, HTTP_PORT_TYPE, HTTP_PORTS, serviceManager } from '../serviceManager';
11
11
  import {
12
12
  COMPOSE_LABEL_PROJECT,
13
13
  COMPOSE_LABEL_SERVICE,
14
+ CONTAINER_LABEL_PORT_PREFIX,
14
15
  containerManager,
15
16
  DockerMounts,
16
17
  toLocalBindVolume,
17
18
  } from '../containerManager';
18
19
  import { LogData } from './LogData';
19
20
  import { clusterService } from '../clusterService';
20
- import { AnyMap, BlockProcessParams, InstanceType, ProcessInfo, StringMap } from '../types';
21
+ import { AnyMap, BlockProcessParams, InstanceType, LocalImageOptions, ProcessInfo, StringMap } from '../types';
21
22
  import { definitionsManager } from '../definitionsManager';
22
23
  import Docker from 'dockerode';
23
24
  import OS from 'node:os';
@@ -384,7 +385,9 @@ export class BlockInstanceRunner {
384
385
  throw new Error(`Provider did not have local image: ${providerRef}`);
385
386
  }
386
387
 
387
- const dockerImage = spec?.local?.image;
388
+ const local = spec.local as LocalImageOptions;
389
+
390
+ const dockerImage = local.image;
388
391
 
389
392
  //We only want 1 operator per operator type - across all local systems
390
393
  const containerName = getBlockInstanceContainerName(this._systemId, blockInstance.id);
@@ -397,11 +400,13 @@ export class BlockInstanceRunner {
397
400
  const PortBindings: AnyMap = {};
398
401
  let HealthCheck = undefined;
399
402
  let Mounts: DockerMounts[] = [];
400
- const localPorts = spec.local.ports as { [p: string]: { port: string; type: string } };
403
+ const localPorts = local.ports ?? {};
404
+ const labels: { [key: string]: string } = {};
401
405
  const promises = Object.entries(localPorts).map(async ([portType, value]) => {
402
- const dockerPort = `${value.port}/${value.type}`;
406
+ const portInfo = toPortInfo(value);
407
+ const dockerPort = `${portInfo.port}/${portInfo.type}`;
403
408
  ExposedPorts[dockerPort] = {};
404
- addonEnv[`KAPETA_LOCAL_SERVER_PORT_${portType.toUpperCase()}`] = value.port;
409
+ addonEnv[`KAPETA_LOCAL_SERVER_PORT_${portType.toUpperCase()}`] = `${portInfo.port}`;
405
410
  const publicPort = await serviceManager.ensureServicePort(this._systemId, blockInstance.id, portType);
406
411
  PortBindings[dockerPort] = [
407
412
  {
@@ -409,23 +414,24 @@ export class BlockInstanceRunner {
409
414
  HostPort: `${publicPort}`,
410
415
  },
411
416
  ];
417
+
418
+ labels[CONTAINER_LABEL_PORT_PREFIX + publicPort] = portType;
412
419
  });
413
420
 
414
421
  await Promise.all(promises);
415
422
 
416
- if (spec.local?.env) {
417
- Object.entries(spec.local.env).forEach(([key, value]) => {
423
+ if (local.env) {
424
+ Object.entries(local.env).forEach(([key, value]) => {
418
425
  addonEnv[key] = value as string;
419
426
  });
420
427
  }
421
428
 
422
- if (spec.local?.mounts) {
423
- const mounts = await containerManager.createMounts(this._systemId, blockUri.id, spec.local.mounts);
424
- Mounts = containerManager.toDockerMounts(mounts);
429
+ if (local.mounts) {
430
+ Mounts = await containerManager.createVolumes(this._systemId, blockUri.id, local.mounts);
425
431
  }
426
432
 
427
- if (spec.local?.health) {
428
- HealthCheck = containerManager.toDockerHealth(spec.local?.health);
433
+ if (local.health) {
434
+ HealthCheck = containerManager.toDockerHealth(local.health);
429
435
  }
430
436
 
431
437
  // For windows we need to default to root
@@ -447,6 +453,7 @@ export class BlockInstanceRunner {
447
453
  Mounts,
448
454
  },
449
455
  Labels: {
456
+ ...labels,
450
457
  instance: blockInstance.id,
451
458
  [COMPOSE_LABEL_PROJECT]: systemUri.id.replace(/[^a-z0-9]/gi, '_'),
452
459
  [COMPOSE_LABEL_SERVICE]: blockUri.id.replace(/[^a-z0-9]/gi, '_'),
@@ -462,7 +469,7 @@ export class BlockInstanceRunner {
462
469
  ],
463
470
  });
464
471
 
465
- const portTypes = spec.local.ports ? Object.keys(spec.local.ports) : [];
472
+ const portTypes = local.ports ? Object.keys(local.ports) : [];
466
473
  if (portTypes.length > 0) {
467
474
  out.portType = portTypes[0];
468
475
  }
@@ -5,17 +5,28 @@
5
5
 
6
6
  import FS from 'node:fs';
7
7
  import YAML from 'yaml';
8
- import { parseKapetaUri } from '@kapeta/nodejs-utils';
9
8
  import md5 from 'md5';
10
9
  import { EntityList } from '@kapeta/schemas';
11
10
  import _ from 'lodash';
12
- import { AnyMap } from '../types';
11
+ import { AnyMap, PortInfo } from '../types';
13
12
  import ClusterConfiguration from '@kapeta/local-cluster-config';
14
13
 
15
14
  export function getBlockInstanceContainerName(systemId: string, instanceId: string) {
16
15
  return `kapeta-block-instance-${md5(systemId + instanceId)}`;
17
16
  }
18
17
 
18
+ export function toPortInfo(port: PortInfo) {
19
+ if (typeof port === 'number' || typeof port === 'string') {
20
+ return { port: parseInt(`${port}`), type: 'tcp' };
21
+ }
22
+
23
+ if (!port.type) {
24
+ port.type = 'tcp';
25
+ }
26
+
27
+ return port;
28
+ }
29
+
19
30
  export function getRemoteUrl(id: string, defautValue: string) {
20
31
  const remoteConfig = ClusterConfiguration.getClusterConfig().remote;
21
32
  return remoteConfig?.[id] ?? defautValue;