@kapeta/local-cluster-service 0.1.0 → 0.1.2

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.1.2](https://github.com/kapetacom/local-cluster-service/compare/v0.1.1...v0.1.2) (2023-05-06)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Moved all docker init things into init - and rely on that ([9a012c3](https://github.com/kapetacom/local-cluster-service/commit/9a012c3a40a6b4e4ef55757a4b8454d48bd3987c))
7
+
8
+ ## [0.1.1](https://github.com/kapetacom/local-cluster-service/compare/v0.1.0...v0.1.1) (2023-05-06)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Add missing import ([54a570c](https://github.com/kapetacom/local-cluster-service/commit/54a570c8c0746ae014fbf9411c85dbf255bf8cea))
14
+
1
15
  # [0.1.0](https://github.com/kapetacom/local-cluster-service/compare/v0.0.76...v0.1.0) (2023-05-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.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -2,7 +2,7 @@ const {Docker} = require("node-docker-api");
2
2
  const path = require("path");
3
3
  const _ = require('lodash');
4
4
  const FS = require("node:fs");
5
-
5
+ const os = require("os");
6
6
  const LABEL_PORT_PREFIX = "kapeta_port-";
7
7
 
8
8
  const NANO_SECOND = 1000000;
@@ -44,6 +44,7 @@ class ContainerManager {
44
44
  const client = new Docker(opts);
45
45
  await client.ping();
46
46
  this._docker = client;
47
+ this._alive = true;
47
48
  return;
48
49
  } catch (err) {
49
50
  // silently ignore bad configs
@@ -52,38 +53,26 @@ class ContainerManager {
52
53
  throw new Error("Unable to connect to docker");
53
54
  }
54
55
 
55
- async ping() {
56
- await this._docker.ping();
57
- this._alive = true;
58
- }
59
-
60
56
  async ping() {
61
57
 
62
58
  try {
63
- const pingResult = await this._docker.ping();
59
+ const pingResult = await this.docker().ping();
64
60
  if (pingResult !== 'OK') {
65
61
  throw new Error(`Ping failed: ${pingResult}`);
66
62
  }
67
63
  } catch (e) {
68
64
  throw new Error(`Docker not running. Please start the docker daemon before running this command. Error: ${e.message}`);
69
65
  }
70
-
71
- this._alive = true;
72
66
  }
73
-
74
- async ensureAlive() {
75
- if (!this._alive) {
76
- await this.ping();
67
+ docker() {
68
+ if (!this._docker) {
69
+ throw new Error(`Docker not running`);
77
70
  }
78
- }
79
-
80
- async docker() {
81
- await this.ensureAlive();
82
71
  return this._docker;
83
72
  }
84
73
 
85
74
  async getContainerByName(containerName) {
86
- const containers = await this._docker.container.list({all: true});
75
+ const containers = await this.docker().container.list({all: true});
87
76
  return containers.find(container => {
88
77
  return container.data.Names.indexOf(`/${containerName}`) > -1;
89
78
  });
@@ -95,7 +84,7 @@ class ContainerManager {
95
84
  tag = 'latest';
96
85
  }
97
86
 
98
- await this._docker.image
87
+ await this.docker().image
99
88
  .create(
100
89
  {},
101
90
  {
@@ -190,7 +179,7 @@ class ContainerManager {
190
179
  }
191
180
 
192
181
  async startContainer(opts) {
193
- const dockerContainer = await this._docker.container.create(opts);
182
+ const dockerContainer = await this.docker().container.create(opts);
194
183
 
195
184
  await dockerContainer.start();
196
185
 
@@ -235,7 +224,7 @@ class ContainerManager {
235
224
  let dockerContainer = null;
236
225
 
237
226
  try {
238
- dockerContainer = await this._docker.container.get(name);
227
+ dockerContainer = await this.docker().container.get(name);
239
228
  await dockerContainer.status();
240
229
  } catch (err) {
241
230
  //Ignore