@kapeta/local-cluster-service 0.5.1 → 0.5.3

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.5.3](https://github.com/kapetacom/local-cluster-service/compare/v0.5.2...v0.5.3) (2023-06-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Make sure bound ports are exposed and ([#29](https://github.com/kapetacom/local-cluster-service/issues/29)) ([fe088b4](https://github.com/kapetacom/local-cluster-service/commit/fe088b424fa159ca1d04e721ace4558a778c5dcd))
7
+
8
+ ## [0.5.2](https://github.com/kapetacom/local-cluster-service/compare/v0.5.1...v0.5.2) (2023-06-06)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Use internal docker host when inside docker ([#28](https://github.com/kapetacom/local-cluster-service/issues/28)) ([3b0ae9d](https://github.com/kapetacom/local-cluster-service/commit/3b0ae9d7612ae54b38ec8e39f632932f8543206e))
14
+
1
15
  ## [0.5.1](https://github.com/kapetacom/local-cluster-service/compare/v0.5.0...v0.5.1) (2023-06-06)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -134,7 +134,8 @@ router.get('/consumes/resource/:resourceType/:portType/:name', async (req, res)
134
134
  req.kapeta.instanceId,
135
135
  req.params.resourceType,
136
136
  req.params.portType,
137
- req.params.name
137
+ req.params.name,
138
+ req.kapeta.environment
138
139
  );
139
140
 
140
141
  res.send(operatorInfo);
@@ -13,7 +13,7 @@ const LABEL_PORT_PREFIX = 'kapeta_port-';
13
13
 
14
14
  const NANO_SECOND = 1000000;
15
15
  const HEALTH_CHECK_INTERVAL = 2000;
16
- const HEALTH_CHECK_MAX = 20;
16
+ const HEALTH_CHECK_MAX = 30;
17
17
  const IMAGE_PULL_CACHE_TTL = 30 * 60 * 1000;
18
18
  const IMAGE_PULL_CACHE = {};
19
19
 
@@ -54,6 +54,8 @@ class ContainerManager {
54
54
  // Default http
55
55
  { protocol: 'http', host: 'localhost', port: 2375 },
56
56
  { protocol: 'https', host: 'localhost', port: 2376 },
57
+ { protocol: 'http', host: '127.0.0.1', port: 2375 },
58
+ { protocol: 'https', host: '127.0.0.1', port: 2376 },
57
59
  ];
58
60
  for (const opts of connectOptions) {
59
61
  try {
@@ -197,7 +199,10 @@ class ContainerManager {
197
199
 
198
200
  console.log('Image pulled: %s', image);
199
201
 
202
+ const ExposedPorts = {};
203
+
200
204
  _.forEach(opts.ports, (portInfo, containerPort) => {
205
+ ExposedPorts['' + containerPort] = {};
201
206
  PortBindings['' + containerPort] = [
202
207
  {
203
208
  HostPort: '' + portInfo.hostPort,
@@ -219,11 +224,12 @@ class ContainerManager {
219
224
  if (opts.health) {
220
225
  HealthCheck = this.toDockerHealth(opts.health);
221
226
  }
222
-
223
227
  const dockerContainer = await this.startContainer({
224
228
  name: name,
225
229
  Image: image,
226
230
  Labels,
231
+ Cmd: opts.cmd,
232
+ ExposedPorts,
227
233
  Env,
228
234
  HealthCheck,
229
235
  HostConfig: {
@@ -349,6 +355,10 @@ class ContainerInfo {
349
355
  this._container = dockerContainer;
350
356
  }
351
357
 
358
+ get native() {
359
+ return this._container;
360
+ }
361
+
352
362
  async isRunning() {
353
363
  const inspectResult = await this.getStatus();
354
364
 
@@ -71,7 +71,7 @@ class OperatorManager {
71
71
  * @param {string} name
72
72
  * @returns {Promise<{host: string, port: (*|string), type: *, protocol: *, credentials: *}>}
73
73
  */
74
- async getResourceInfo(systemId, fromServiceId, resourceType, portType, name) {
74
+ async getResourceInfo(systemId, fromServiceId, resourceType, portType, name, environment) {
75
75
 
76
76
  const operator = this.getOperator(resourceType);
77
77
 
@@ -88,7 +88,7 @@ class OperatorManager {
88
88
  const dbName = name + '_' + fromServiceId.replace(/[^a-z0-9]/gi, '');
89
89
 
90
90
  return {
91
- host: 'localhost',
91
+ host: environment === 'docker' ? 'host.docker.internal' : '127.0.0.1',
92
92
  port: portInfo.hostPort,
93
93
  type: portType,
94
94
  protocol: portInfo.protocol,
@@ -163,10 +163,21 @@ class OperatorManager {
163
163
  mounts,
164
164
  ports,
165
165
  health: operatorData.health,
166
- env: operatorData.env
166
+ env: operatorData.env,
167
+ cmd: operatorData.cmd
167
168
  });
168
169
  }
169
170
 
171
+ try {
172
+ if (operatorData.health) {
173
+ await containerManager.waitForHealthy(container.native);
174
+ } else {
175
+ await containerManager.waitForReady(container.native);
176
+ }
177
+ } catch (e) {
178
+ console.error(e.message);
179
+ }
180
+
170
181
  return container;
171
182
  }
172
183
  }
@@ -274,10 +274,14 @@ class BlockInstanceRunner {
274
274
  ...dockerOpts
275
275
  });
276
276
 
277
- if (HealthCheck) {
278
- await containerManager.waitForHealthy(container);
279
- } else {
280
- await containerManager.waitForReady(container);
277
+ try {
278
+ if (HealthCheck) {
279
+ await containerManager.waitForHealthy(container);
280
+ } else {
281
+ await containerManager.waitForReady(container);
282
+ }
283
+ } catch (e) {
284
+ logs.addLog(e.message, 'ERROR');
281
285
  }
282
286
 
283
287
  return this._handleContainer(container, logs);
@@ -408,7 +412,11 @@ class BlockInstanceRunner {
408
412
  }
409
413
  });
410
414
 
411
- await containerManager.waitForReady(container);
415
+ try {
416
+ await containerManager.waitForReady(container);
417
+ } catch (e) {
418
+ logs.addLog(e.message, 'ERROR');
419
+ }
412
420
  }
413
421
 
414
422
  return this._handleContainer(container, logs);
@@ -543,10 +551,14 @@ class BlockInstanceRunner {
543
551
  ]
544
552
  });
545
553
 
546
- if (HealthCheck) {
547
- await containerManager.waitForHealthy(container);
548
- } else {
549
- await containerManager.waitForReady(container);
554
+ try {
555
+ if (HealthCheck) {
556
+ await containerManager.waitForHealthy(container);
557
+ } else {
558
+ await containerManager.waitForReady(container);
559
+ }
560
+ } catch (e) {
561
+ logs.addLog(e.message, 'ERROR');
550
562
  }
551
563
  }
552
564