@kapeta/local-cluster-service 0.33.6 → 0.33.7

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,10 @@
1
+ ## [0.33.7](https://github.com/kapetacom/local-cluster-service/compare/v0.33.6...v0.33.7) (2024-01-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Re-pull "latest" images every 15 mins ([#116](https://github.com/kapetacom/local-cluster-service/issues/116)) ([4b71fcc](https://github.com/kapetacom/local-cluster-service/commit/4b71fcce131dcd5b6cea955dc663b93aa3c3c930))
7
+
1
8
  ## [0.33.6](https://github.com/kapetacom/local-cluster-service/compare/v0.33.5...v0.33.6) (2024-01-09)
2
9
 
3
10
 
@@ -43,6 +43,7 @@ declare class ContainerManager {
43
43
  private _version;
44
44
  private _lastDockerAccessCheck;
45
45
  private logStreams;
46
+ private _latestImagePulls;
46
47
  constructor();
47
48
  initialize(): Promise<void>;
48
49
  checkAlive(): Promise<boolean>;
@@ -27,6 +27,7 @@ exports.CONTAINER_LABEL_PORT_PREFIX = 'kapeta_port-';
27
27
  const NANO_SECOND = 1000000;
28
28
  const HEALTH_CHECK_INTERVAL = 3000;
29
29
  const HEALTH_CHECK_MAX = 100;
30
+ const LATEST_PULL_TIMEOUT = 1000 * 60 * 15; // 15 minutes
30
31
  exports.COMPOSE_LABEL_PROJECT = 'com.docker.compose.project';
31
32
  exports.COMPOSE_LABEL_SERVICE = 'com.docker.compose.service';
32
33
  exports.HEALTH_CHECK_TIMEOUT = HEALTH_CHECK_INTERVAL * HEALTH_CHECK_MAX * 2;
@@ -69,11 +70,13 @@ class ContainerManager {
69
70
  _version;
70
71
  _lastDockerAccessCheck = 0;
71
72
  logStreams = {};
73
+ _latestImagePulls = {};
72
74
  constructor() {
73
75
  this._docker = null;
74
76
  this._alive = false;
75
77
  this._version = '';
76
78
  this._mountDir = path_1.default.join(storageService_1.storageService.getKapetaBasedir(), 'mounts');
79
+ this._latestImagePulls = {};
77
80
  fs_extra_1.default.mkdirpSync(this._mountDir);
78
81
  }
79
82
  async initialize() {
@@ -221,7 +224,20 @@ class ContainerManager {
221
224
  const imageTagList = (await this.docker().listImages({}))
222
225
  .filter((imageData) => !!imageData.RepoTags)
223
226
  .map((imageData) => imageData.RepoTags);
224
- if (imageTagList.some((imageTags) => imageTags.indexOf(image) > -1)) {
227
+ const imageExists = imageTagList.some((imageTags) => imageTags.includes(image));
228
+ if (tag === 'latest') {
229
+ if (imageExists && this._latestImagePulls[imageName]) {
230
+ const lastPull = this._latestImagePulls[imageName];
231
+ const timeSinceLastPull = Date.now() - lastPull;
232
+ if (timeSinceLastPull < LATEST_PULL_TIMEOUT) {
233
+ console.log('Image found and was pulled %s seconds ago: %s', Math.round(timeSinceLastPull / 1000), image);
234
+ // Last pull was less than the timeout - don't pull again
235
+ return false;
236
+ }
237
+ }
238
+ this._latestImagePulls[imageName] = Date.now();
239
+ }
240
+ else if (imageExists) {
225
241
  console.log('Image found: %s', image);
226
242
  return false;
227
243
  }
@@ -43,6 +43,7 @@ declare class ContainerManager {
43
43
  private _version;
44
44
  private _lastDockerAccessCheck;
45
45
  private logStreams;
46
+ private _latestImagePulls;
46
47
  constructor();
47
48
  initialize(): Promise<void>;
48
49
  checkAlive(): Promise<boolean>;
@@ -27,6 +27,7 @@ exports.CONTAINER_LABEL_PORT_PREFIX = 'kapeta_port-';
27
27
  const NANO_SECOND = 1000000;
28
28
  const HEALTH_CHECK_INTERVAL = 3000;
29
29
  const HEALTH_CHECK_MAX = 100;
30
+ const LATEST_PULL_TIMEOUT = 1000 * 60 * 15; // 15 minutes
30
31
  exports.COMPOSE_LABEL_PROJECT = 'com.docker.compose.project';
31
32
  exports.COMPOSE_LABEL_SERVICE = 'com.docker.compose.service';
32
33
  exports.HEALTH_CHECK_TIMEOUT = HEALTH_CHECK_INTERVAL * HEALTH_CHECK_MAX * 2;
@@ -69,11 +70,13 @@ class ContainerManager {
69
70
  _version;
70
71
  _lastDockerAccessCheck = 0;
71
72
  logStreams = {};
73
+ _latestImagePulls = {};
72
74
  constructor() {
73
75
  this._docker = null;
74
76
  this._alive = false;
75
77
  this._version = '';
76
78
  this._mountDir = path_1.default.join(storageService_1.storageService.getKapetaBasedir(), 'mounts');
79
+ this._latestImagePulls = {};
77
80
  fs_extra_1.default.mkdirpSync(this._mountDir);
78
81
  }
79
82
  async initialize() {
@@ -221,7 +224,20 @@ class ContainerManager {
221
224
  const imageTagList = (await this.docker().listImages({}))
222
225
  .filter((imageData) => !!imageData.RepoTags)
223
226
  .map((imageData) => imageData.RepoTags);
224
- if (imageTagList.some((imageTags) => imageTags.indexOf(image) > -1)) {
227
+ const imageExists = imageTagList.some((imageTags) => imageTags.includes(image));
228
+ if (tag === 'latest') {
229
+ if (imageExists && this._latestImagePulls[imageName]) {
230
+ const lastPull = this._latestImagePulls[imageName];
231
+ const timeSinceLastPull = Date.now() - lastPull;
232
+ if (timeSinceLastPull < LATEST_PULL_TIMEOUT) {
233
+ console.log('Image found and was pulled %s seconds ago: %s', Math.round(timeSinceLastPull / 1000), image);
234
+ // Last pull was less than the timeout - don't pull again
235
+ return false;
236
+ }
237
+ }
238
+ this._latestImagePulls[imageName] = Date.now();
239
+ }
240
+ else if (imageExists) {
225
241
  console.log('Image found: %s', image);
226
242
  return false;
227
243
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.33.6",
3
+ "version": "0.33.7",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -87,6 +87,7 @@ export const CONTAINER_LABEL_PORT_PREFIX = 'kapeta_port-';
87
87
  const NANO_SECOND = 1000000;
88
88
  const HEALTH_CHECK_INTERVAL = 3000;
89
89
  const HEALTH_CHECK_MAX = 100;
90
+ const LATEST_PULL_TIMEOUT = 1000 * 60 * 15; // 15 minutes
90
91
  export const COMPOSE_LABEL_PROJECT = 'com.docker.compose.project';
91
92
  export const COMPOSE_LABEL_SERVICE = 'com.docker.compose.service';
92
93
 
@@ -135,12 +136,14 @@ class ContainerManager {
135
136
  private _version: string;
136
137
  private _lastDockerAccessCheck: number = 0;
137
138
  private logStreams: { [p: string]: { stream?: ClosableLogStream; timer?: NodeJS.Timeout } } = {};
139
+ private _latestImagePulls: { [p: string]: number } = {};
138
140
 
139
141
  constructor() {
140
142
  this._docker = null;
141
143
  this._alive = false;
142
144
  this._version = '';
143
145
  this._mountDir = Path.join(storageService.getKapetaBasedir(), 'mounts');
146
+ this._latestImagePulls = {};
144
147
  FSExtra.mkdirpSync(this._mountDir);
145
148
  }
146
149
 
@@ -321,7 +324,24 @@ class ContainerManager {
321
324
  .filter((imageData) => !!imageData.RepoTags)
322
325
  .map((imageData) => imageData.RepoTags as string[]);
323
326
 
324
- if (imageTagList.some((imageTags) => imageTags.indexOf(image) > -1)) {
327
+ const imageExists = imageTagList.some((imageTags) => imageTags.includes(image));
328
+
329
+ if (tag === 'latest') {
330
+ if (imageExists && this._latestImagePulls[imageName]) {
331
+ const lastPull = this._latestImagePulls[imageName];
332
+ const timeSinceLastPull = Date.now() - lastPull;
333
+ if (timeSinceLastPull < LATEST_PULL_TIMEOUT) {
334
+ console.log(
335
+ 'Image found and was pulled %s seconds ago: %s',
336
+ Math.round(timeSinceLastPull / 1000),
337
+ image
338
+ );
339
+ // Last pull was less than the timeout - don't pull again
340
+ return false;
341
+ }
342
+ }
343
+ this._latestImagePulls[imageName] = Date.now();
344
+ } else if (imageExists) {
325
345
  console.log('Image found: %s', image);
326
346
  return false;
327
347
  }