@kapeta/local-cluster-service 0.21.5 → 0.22.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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [0.22.1](https://github.com/kapetacom/local-cluster-service/compare/v0.22.0...v0.22.1) (2023-10-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Bump kapeta api to fix auth ([#86](https://github.com/kapetacom/local-cluster-service/issues/86)) ([1178afc](https://github.com/kapetacom/local-cluster-service/commit/1178afce54a25cddb52944201097bc28c59b038a))
7
+
8
+ # [0.22.0](https://github.com/kapetacom/local-cluster-service/compare/v0.21.5...v0.22.0) (2023-10-17)
9
+
10
+
11
+ ### Features
12
+
13
+ * Allow local containers to add Binds ([#85](https://github.com/kapetacom/local-cluster-service/issues/85)) ([c7b46e9](https://github.com/kapetacom/local-cluster-service/commit/c7b46e94412da1eec82503f7d30957fc665e71e6))
14
+
1
15
  ## [0.21.5](https://github.com/kapetacom/local-cluster-service/compare/v0.21.4...v0.21.5) (2023-09-26)
2
16
 
3
17
 
package/dist/cjs/index.js CHANGED
@@ -141,7 +141,7 @@ exports.default = {
141
141
  throw new Error(`Cluster service already running on: ${clusterHost}:${clusterPort}.`);
142
142
  }
143
143
  await clusterService_1.clusterService.init();
144
- await authManager_1.authManager.listenForChanges();
144
+ authManager_1.authManager.listenForChanges();
145
145
  currentServer = createServer();
146
146
  const port = clusterService_1.clusterService.getClusterServicePort();
147
147
  const host = clusterService_1.clusterService.getClusterServiceHost();
@@ -16,10 +16,6 @@ declare class OperatorManager {
16
16
  _getMountPoint(operatorType: string, mountName: string): string;
17
17
  /**
18
18
  * Get operator definition for resource type
19
- *
20
- * @param {string} resourceType
21
- * @param {string} version
22
- * @return {Operator}
23
19
  */
24
20
  getOperator(resourceType: string, version: string): Promise<Operator>;
25
21
  /**
@@ -45,10 +45,6 @@ class OperatorManager {
45
45
  }
46
46
  /**
47
47
  * Get operator definition for resource type
48
- *
49
- * @param {string} resourceType
50
- * @param {string} version
51
- * @return {Operator}
52
48
  */
53
49
  async getOperator(resourceType, version) {
54
50
  const operators = await definitionsManager_1.definitionsManager.getDefinitions(exports.KIND_OPERATOR);
@@ -84,7 +80,12 @@ class OperatorManager {
84
80
  if (!blockDefinition) {
85
81
  throw new Error(`Unknown block: ${currentInstance.block.ref} in plan ${systemId}`);
86
82
  }
87
- const blockResource = blockDefinition.definition.spec?.consumers?.find((resource) => resource.metadata.name === name);
83
+ const blockResource = blockDefinition.definition.spec?.consumers?.find((resource) => {
84
+ if (resource.metadata.name !== name) {
85
+ return false;
86
+ }
87
+ return (0, nodejs_utils_1.parseKapetaUri)(resource.kind).fullName === resourceType;
88
+ });
88
89
  if (!blockResource) {
89
90
  throw new Error(`Unknown resource: ${name} in block ${currentInstance.block.ref} in plan ${systemId}`);
90
91
  }
@@ -14,6 +14,7 @@ const LogData_1 = require("./LogData");
14
14
  const clusterService_1 = require("../clusterService");
15
15
  const types_1 = require("../types");
16
16
  const definitionsManager_1 = require("../definitionsManager");
17
+ const node_os_1 = __importDefault(require("node:os"));
17
18
  const KIND_BLOCK_TYPE_OPERATOR = 'core/block-type-operator';
18
19
  const KAPETA_SYSTEM_ID = 'KAPETA_SYSTEM_ID';
19
20
  const KAPETA_BLOCK_REF = 'KAPETA_BLOCK_REF';
@@ -46,7 +47,8 @@ function getProviderPorts(assetVersion, providerVersion) {
46
47
  }
47
48
  return [serviceManager_1.DEFAULT_PORT_TYPE];
48
49
  }
49
- return out;
50
+ // Duplicated port types are not allowed
51
+ return Array.from(new Set(out));
50
52
  }
51
53
  class BlockInstanceRunner {
52
54
  _systemId;
@@ -148,6 +150,8 @@ class BlockInstanceRunner {
148
150
  const homeDir = localContainer.userHome ? localContainer.userHome : '/root';
149
151
  const workingDir = localContainer.workingDir ? localContainer.workingDir : '/workspace';
150
152
  const customHostConfigs = localContainer.HostConfig ?? {};
153
+ const Binds = customHostConfigs.Binds ?? [];
154
+ delete customHostConfigs.Binds;
151
155
  const customLabels = localContainer.Labels ?? {};
152
156
  const customEnvs = localContainer.Env ?? [];
153
157
  delete localContainer.HostConfig;
@@ -160,7 +164,7 @@ class BlockInstanceRunner {
160
164
  }
161
165
  const realLocalPath = node_fs_1.default.realpathSync(baseDir);
162
166
  const Mounts = containerManager_1.containerManager.toDockerMounts({
163
- [workingDir]: (0, containerManager_1.toLocalBindVolume)(realLocalPath)
167
+ [workingDir]: (0, containerManager_1.toLocalBindVolume)(realLocalPath),
164
168
  });
165
169
  const systemUri = (0, nodejs_utils_1.parseKapetaUri)(this._systemId);
166
170
  return this.ensureContainer({
@@ -189,10 +193,20 @@ class BlockInstanceRunner {
189
193
  HostConfig: {
190
194
  ...customHostConfigs,
191
195
  Binds: [
192
- `${(0, containerManager_1.toLocalBindVolume)(local_cluster_config_1.default.getKapetaBasedir())}:${homeDir}/.kapeta`
196
+ `${(0, containerManager_1.toLocalBindVolume)(local_cluster_config_1.default.getKapetaBasedir())}:${homeDir}/.kapeta`,
197
+ ...Binds.map((bind) => {
198
+ let [host, container] = bind.split(':');
199
+ if (host.startsWith('~')) {
200
+ host = node_os_1.default.homedir() + host.substring(1);
201
+ }
202
+ if (container.startsWith('~')) {
203
+ container = homeDir + container.substring(1);
204
+ }
205
+ return `${(0, containerManager_1.toLocalBindVolume)(host)}:${container}`;
206
+ }),
193
207
  ],
194
208
  PortBindings,
195
- Mounts
209
+ Mounts,
196
210
  },
197
211
  });
198
212
  }
package/dist/cjs/start.js CHANGED
@@ -8,6 +8,6 @@ index_1.default
8
8
  .start()
9
9
  .then(({ host, port }) => console.log('Listening on port %s:%s', host, port))
10
10
  .catch((e) => {
11
- console.error('Failed to start local cluster due to an error:\n\t - %s', e.toString());
11
+ console.error('Failed to start local cluster due to an error:\n\t - %s', e);
12
12
  process.exit(1);
13
13
  });
package/dist/esm/index.js CHANGED
@@ -141,7 +141,7 @@ exports.default = {
141
141
  throw new Error(`Cluster service already running on: ${clusterHost}:${clusterPort}.`);
142
142
  }
143
143
  await clusterService_1.clusterService.init();
144
- await authManager_1.authManager.listenForChanges();
144
+ authManager_1.authManager.listenForChanges();
145
145
  currentServer = createServer();
146
146
  const port = clusterService_1.clusterService.getClusterServicePort();
147
147
  const host = clusterService_1.clusterService.getClusterServiceHost();
@@ -16,10 +16,6 @@ declare class OperatorManager {
16
16
  _getMountPoint(operatorType: string, mountName: string): string;
17
17
  /**
18
18
  * Get operator definition for resource type
19
- *
20
- * @param {string} resourceType
21
- * @param {string} version
22
- * @return {Operator}
23
19
  */
24
20
  getOperator(resourceType: string, version: string): Promise<Operator>;
25
21
  /**
@@ -45,10 +45,6 @@ class OperatorManager {
45
45
  }
46
46
  /**
47
47
  * Get operator definition for resource type
48
- *
49
- * @param {string} resourceType
50
- * @param {string} version
51
- * @return {Operator}
52
48
  */
53
49
  async getOperator(resourceType, version) {
54
50
  const operators = await definitionsManager_1.definitionsManager.getDefinitions(exports.KIND_OPERATOR);
@@ -84,7 +80,12 @@ class OperatorManager {
84
80
  if (!blockDefinition) {
85
81
  throw new Error(`Unknown block: ${currentInstance.block.ref} in plan ${systemId}`);
86
82
  }
87
- const blockResource = blockDefinition.definition.spec?.consumers?.find((resource) => resource.metadata.name === name);
83
+ const blockResource = blockDefinition.definition.spec?.consumers?.find((resource) => {
84
+ if (resource.metadata.name !== name) {
85
+ return false;
86
+ }
87
+ return (0, nodejs_utils_1.parseKapetaUri)(resource.kind).fullName === resourceType;
88
+ });
88
89
  if (!blockResource) {
89
90
  throw new Error(`Unknown resource: ${name} in block ${currentInstance.block.ref} in plan ${systemId}`);
90
91
  }
@@ -14,6 +14,7 @@ const LogData_1 = require("./LogData");
14
14
  const clusterService_1 = require("../clusterService");
15
15
  const types_1 = require("../types");
16
16
  const definitionsManager_1 = require("../definitionsManager");
17
+ const node_os_1 = __importDefault(require("node:os"));
17
18
  const KIND_BLOCK_TYPE_OPERATOR = 'core/block-type-operator';
18
19
  const KAPETA_SYSTEM_ID = 'KAPETA_SYSTEM_ID';
19
20
  const KAPETA_BLOCK_REF = 'KAPETA_BLOCK_REF';
@@ -46,7 +47,8 @@ function getProviderPorts(assetVersion, providerVersion) {
46
47
  }
47
48
  return [serviceManager_1.DEFAULT_PORT_TYPE];
48
49
  }
49
- return out;
50
+ // Duplicated port types are not allowed
51
+ return Array.from(new Set(out));
50
52
  }
51
53
  class BlockInstanceRunner {
52
54
  _systemId;
@@ -148,6 +150,8 @@ class BlockInstanceRunner {
148
150
  const homeDir = localContainer.userHome ? localContainer.userHome : '/root';
149
151
  const workingDir = localContainer.workingDir ? localContainer.workingDir : '/workspace';
150
152
  const customHostConfigs = localContainer.HostConfig ?? {};
153
+ const Binds = customHostConfigs.Binds ?? [];
154
+ delete customHostConfigs.Binds;
151
155
  const customLabels = localContainer.Labels ?? {};
152
156
  const customEnvs = localContainer.Env ?? [];
153
157
  delete localContainer.HostConfig;
@@ -160,7 +164,7 @@ class BlockInstanceRunner {
160
164
  }
161
165
  const realLocalPath = node_fs_1.default.realpathSync(baseDir);
162
166
  const Mounts = containerManager_1.containerManager.toDockerMounts({
163
- [workingDir]: (0, containerManager_1.toLocalBindVolume)(realLocalPath)
167
+ [workingDir]: (0, containerManager_1.toLocalBindVolume)(realLocalPath),
164
168
  });
165
169
  const systemUri = (0, nodejs_utils_1.parseKapetaUri)(this._systemId);
166
170
  return this.ensureContainer({
@@ -189,10 +193,20 @@ class BlockInstanceRunner {
189
193
  HostConfig: {
190
194
  ...customHostConfigs,
191
195
  Binds: [
192
- `${(0, containerManager_1.toLocalBindVolume)(local_cluster_config_1.default.getKapetaBasedir())}:${homeDir}/.kapeta`
196
+ `${(0, containerManager_1.toLocalBindVolume)(local_cluster_config_1.default.getKapetaBasedir())}:${homeDir}/.kapeta`,
197
+ ...Binds.map((bind) => {
198
+ let [host, container] = bind.split(':');
199
+ if (host.startsWith('~')) {
200
+ host = node_os_1.default.homedir() + host.substring(1);
201
+ }
202
+ if (container.startsWith('~')) {
203
+ container = homeDir + container.substring(1);
204
+ }
205
+ return `${(0, containerManager_1.toLocalBindVolume)(host)}:${container}`;
206
+ }),
193
207
  ],
194
208
  PortBindings,
195
- Mounts
209
+ Mounts,
196
210
  },
197
211
  });
198
212
  }
package/dist/esm/start.js CHANGED
@@ -8,6 +8,6 @@ index_1.default
8
8
  .start()
9
9
  .then(({ host, port }) => console.log('Listening on port %s:%s', host, port))
10
10
  .catch((e) => {
11
- console.error('Failed to start local cluster due to an error:\n\t - %s', e.toString());
11
+ console.error('Failed to start local cluster due to an error:\n\t - %s', e);
12
12
  process.exit(1);
13
13
  });
package/index.ts CHANGED
@@ -162,7 +162,8 @@ export default {
162
162
  }
163
163
 
164
164
  await clusterService.init();
165
- await authManager.listenForChanges();
165
+
166
+ authManager.listenForChanges();
166
167
 
167
168
  currentServer = createServer();
168
169
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.21.5",
3
+ "version": "0.22.1",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -59,10 +59,6 @@ class OperatorManager {
59
59
 
60
60
  /**
61
61
  * Get operator definition for resource type
62
- *
63
- * @param {string} resourceType
64
- * @param {string} version
65
- * @return {Operator}
66
62
  */
67
63
  async getOperator(resourceType: string, version: string) {
68
64
  const operators = await definitionsManager.getDefinitions(KIND_OPERATOR);
@@ -122,9 +118,13 @@ class OperatorManager {
122
118
  throw new Error(`Unknown block: ${currentInstance.block.ref} in plan ${systemId}`);
123
119
  }
124
120
 
125
- const blockResource = blockDefinition.definition.spec?.consumers?.find(
126
- (resource: Resource) => resource.metadata.name === name
127
- );
121
+ const blockResource = blockDefinition.definition.spec?.consumers?.find((resource: Resource) => {
122
+ if (resource.metadata.name !== name) {
123
+ return false;
124
+ }
125
+ return parseKapetaUri(resource.kind).fullName === resourceType;
126
+ });
127
+
128
128
  if (!blockResource) {
129
129
  throw new Error(`Unknown resource: ${name} in block ${currentInstance.block.ref} in plan ${systemId}`);
130
130
  }
@@ -15,6 +15,7 @@ import { clusterService } from '../clusterService';
15
15
  import { AnyMap, BlockProcessParams, InstanceType, ProcessInfo, StringMap } from '../types';
16
16
  import { definitionsManager } from '../definitionsManager';
17
17
  import Docker from 'dockerode';
18
+ import OS from 'node:os';
18
19
 
19
20
  const KIND_BLOCK_TYPE_OPERATOR = 'core/block-type-operator';
20
21
  const KAPETA_SYSTEM_ID = 'KAPETA_SYSTEM_ID';
@@ -53,8 +54,8 @@ function getProviderPorts(assetVersion: DefinitionInfo, providerVersion: Definit
53
54
  }
54
55
  return [DEFAULT_PORT_TYPE];
55
56
  }
56
-
57
- return out;
57
+ // Duplicated port types are not allowed
58
+ return Array.from(new Set<string>(out));
58
59
  }
59
60
 
60
61
  export class BlockInstanceRunner {
@@ -194,6 +195,8 @@ export class BlockInstanceRunner {
194
195
  const workingDir = localContainer.workingDir ? localContainer.workingDir : '/workspace';
195
196
 
196
197
  const customHostConfigs = localContainer.HostConfig ?? {};
198
+ const Binds = customHostConfigs.Binds ?? [];
199
+ delete customHostConfigs.Binds;
197
200
  const customLabels = localContainer.Labels ?? {};
198
201
  const customEnvs = localContainer.Env ?? [];
199
202
  delete localContainer.HostConfig;
@@ -214,7 +217,7 @@ export class BlockInstanceRunner {
214
217
  const realLocalPath = FS.realpathSync(baseDir);
215
218
 
216
219
  const Mounts = containerManager.toDockerMounts({
217
- [workingDir]: toLocalBindVolume(realLocalPath)
220
+ [workingDir]: toLocalBindVolume(realLocalPath),
218
221
  });
219
222
 
220
223
  const systemUri = parseKapetaUri(this._systemId);
@@ -245,10 +248,22 @@ export class BlockInstanceRunner {
245
248
  HostConfig: {
246
249
  ...customHostConfigs,
247
250
  Binds: [
248
- `${toLocalBindVolume(ClusterConfig.getKapetaBasedir())}:${homeDir}/.kapeta`
251
+ `${toLocalBindVolume(ClusterConfig.getKapetaBasedir())}:${homeDir}/.kapeta`,
252
+ ...Binds.map((bind: string) => {
253
+ let [host, container] = bind.split(':');
254
+ if (host.startsWith('~')) {
255
+ host = OS.homedir() + host.substring(1);
256
+ }
257
+
258
+ if (container.startsWith('~')) {
259
+ container = homeDir + container.substring(1);
260
+ }
261
+
262
+ return `${toLocalBindVolume(host)}:${container}`;
263
+ }),
249
264
  ],
250
265
  PortBindings,
251
- Mounts
266
+ Mounts,
252
267
  },
253
268
  });
254
269
  }
package/start.ts CHANGED
@@ -4,6 +4,6 @@ localClusterService
4
4
  .start()
5
5
  .then(({ host, port }) => console.log('Listening on port %s:%s', host, port))
6
6
  .catch((e) => {
7
- console.error('Failed to start local cluster due to an error:\n\t - %s', e.toString());
7
+ console.error('Failed to start local cluster due to an error:\n\t - %s', e);
8
8
  process.exit(1);
9
9
  });