Skip to content

Commit 0949a14

Browse files
committed
šŸ› fix(store): unconditional tagPrecision repair on startup and outside try-catch (#270)
- Add repairDataOnStartup() that backfills missing tagPrecision on every startup, independent of the version migration gate - Extract backfillStoredTagPrecision() and call it before the image-inspect try-catch so a failed getImage().inspect() no longer silently prevents the backfill
1 parent 327e101 commit 0949a14

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

ā€Žapp/store/app.tsā€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import * as migrate from './migrate.js';
55

6-
const { migrate: migrateData } = migrate;
6+
const { migrate: migrateData, repairDataOnStartup } = migrate;
77

88
import { getVersion } from '../configuration/index.js';
99
import { initCollection } from './util.js';
@@ -39,6 +39,7 @@ function saveAppInfosAndMigrate() {
3939
if (currentVersion !== versionFromStore) {
4040
migrateData(versionFromStore, currentVersion);
4141
}
42+
repairDataOnStartup();
4243
if (appInfosSaved) {
4344
app.remove(appInfosSaved);
4445
}

ā€Žapp/store/migrate.tsā€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ function shouldBackfillMissingTagPrecision(from?: string, to?: string) {
4444
return semver.valid(from) ? semver.lt(from, TAG_PRECISION_BACKFILL_VERSION) : true;
4545
}
4646

47+
export function repairDataOnStartup() {
48+
backfillMissingTagPrecision();
49+
}
50+
4751
/**
4852
* Data migration function.
4953
* @param from version

ā€Žapp/watchers/providers/docker/docker-image-details-orchestration.tsā€Ž

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ function reconcileStoredContainerStatus(
230230
}
231231
}
232232

233+
function backfillStoredTagPrecision(containerInStore: Container) {
234+
if (containerInStore.image?.tag && containerInStore.image.tag.tagPrecision === undefined) {
235+
containerInStore.image.tag.tagPrecision = classifyTagPrecision(
236+
containerInStore.image.tag.value,
237+
containerInStore.transformTags,
238+
);
239+
}
240+
}
241+
233242
async function refreshStoredContainerImageFields(
234243
watcher: DockerImageDetailsWatcher,
235244
container: DockerContainerSummary,
@@ -239,6 +248,8 @@ async function refreshStoredContainerImageFields(
239248
containerInStore: Container,
240249
containerInspect: DockerContainerInspectPayload | undefined,
241250
) {
251+
backfillStoredTagPrecision(containerInStore);
252+
242253
try {
243254
const currentImage = await watcher.dockerApi.getImage(container.Image).inspect();
244255
const freshDigestRepo = getRepoDigest(currentImage);
@@ -298,13 +309,6 @@ async function refreshStoredContainerImageFields(
298309
}
299310
}
300311

301-
if (containerInStore.image?.tag && containerInStore.image.tag.tagPrecision === undefined) {
302-
containerInStore.image.tag.tagPrecision = classifyTagPrecision(
303-
containerInStore.image.tag.value,
304-
containerInStore.transformTags,
305-
);
306-
}
307-
308312
// Keep local digest value populated for digest-watch containers, even when
309313
// image id/repo digest are unchanged from cached state.
310314
if (freshDigestRepo !== undefined && containerInStore.image.digest.value === undefined) {

0 commit comments

Comments
Ā (0)