Skip to content

Commit 7fad79f

Browse files
committed
fix copose labels peristent container state
1 parent 701b08e commit 7fad79f

File tree

3 files changed

+108
-3
lines changed

3 files changed

+108
-3
lines changed

app/watchers/providers/docker/Docker.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,47 @@ describe('Docker Watcher', () => {
592592
expect(docker.configuration.watchatstart).toBe(false);
593593
});
594594

595+
test('should ensure compose trigger from persisted container state during init', async () => {
596+
storeContainer.getContainers.mockReturnValue([
597+
{
598+
id: 'existing-compose',
599+
name: 'web',
600+
watcher: 'test',
601+
labels: {
602+
'dd.compose.file': '/tmp/my-stack/docker-compose.yml',
603+
'dd.compose.auto': 'true',
604+
'dd.compose.prune': 'false',
605+
},
606+
triggerInclude: 'ntfy.default:major',
607+
},
608+
]);
609+
610+
await docker.register('watcher', 'docker', 'test', {
611+
watchatstart: true,
612+
});
613+
614+
await docker.init();
615+
616+
expect(docker.configuration.watchatstart).toBe(false);
617+
expect(registry.ensureDockercomposeTriggerForContainer).toHaveBeenCalledWith(
618+
'web',
619+
'/tmp/my-stack/docker-compose.yml',
620+
{
621+
auto: 'true',
622+
prune: 'false',
623+
},
624+
);
625+
expect(docker.composeTriggersByContainer['existing-compose']).toBe(
626+
'dockercompose.my-stack-web',
627+
);
628+
expect(storeContainer.updateContainer).toHaveBeenCalledWith(
629+
expect.objectContaining({
630+
id: 'existing-compose',
631+
triggerInclude: 'ntfy.default:major,dockercompose.my-stack-web',
632+
}),
633+
);
634+
});
635+
595636
test('should keep watchatstart disabled when explicitly set to false', async () => {
596637
storeContainer.getContainers.mockReturnValue([]);
597638
await docker.register('watcher', 'docker', 'test', {

app/watchers/providers/docker/Docker.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,8 @@ class Docker extends Watcher {
12421242
}).length === 0;
12431243
this.configuration.watchatstart = this.configuration.watchatstart && isWatcherStoreEmpty;
12441244

1245+
await this.ensureComposeTriggersFromStore();
1246+
12451247
// watch at startup if enabled (after all components have been registered)
12461248
if (this.configuration.watchatstart) {
12471249
this.watchCronTimeout = setTimeout(this.watchFromCron.bind(this), START_WATCHER_DELAY_MS);
@@ -1257,6 +1259,49 @@ class Docker extends Watcher {
12571259
}
12581260
}
12591261

1262+
async ensureComposeTriggersFromStore() {
1263+
const containersInStore = storeContainer.getContainers({
1264+
watcher: this.name,
1265+
});
1266+
1267+
for (const containerInStore of containersInStore) {
1268+
const containerLabels = containerInStore.labels || {};
1269+
const composeFilePath = getLabel(containerLabels, ddComposeFile, wudComposeFile);
1270+
if (!composeFilePath) {
1271+
continue;
1272+
}
1273+
1274+
let dockercomposeTriggerId = this.composeTriggersByContainer[containerInStore.id];
1275+
if (!dockercomposeTriggerId) {
1276+
try {
1277+
dockercomposeTriggerId = await registry.ensureDockercomposeTriggerForContainer(
1278+
containerInStore.name,
1279+
composeFilePath,
1280+
getDockercomposeTriggerConfigurationFromLabels(containerLabels),
1281+
);
1282+
this.composeTriggersByContainer[containerInStore.id] = dockercomposeTriggerId;
1283+
} catch (e: any) {
1284+
this.ensureLogger();
1285+
this.log.warn(
1286+
`Unable to create dockercompose trigger for ${containerInStore.name} (${e.message})`,
1287+
);
1288+
continue;
1289+
}
1290+
}
1291+
1292+
const triggerIncludeUpdated = appendTriggerId(
1293+
containerInStore.triggerInclude,
1294+
dockercomposeTriggerId,
1295+
);
1296+
if (triggerIncludeUpdated !== containerInStore.triggerInclude) {
1297+
storeContainer.updateContainer({
1298+
...containerInStore,
1299+
triggerInclude: triggerIncludeUpdated,
1300+
});
1301+
}
1302+
}
1303+
}
1304+
12601305
initWatcher() {
12611306
const options: Dockerode.DockerOptions = {};
12621307
if (this.configuration.host) {

ui/src/services/registry.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,20 @@ const REGISTRY_PROVIDER_ICONS = {
3535
docr: 'fab fa-digital-ocean',
3636
};
3737

38+
function getRegistryProviderName(provider) {
39+
return `${provider || ''}`.split('.')[0];
40+
}
41+
42+
function getRegistryDisplayName(registryName) {
43+
const [provider, name] = `${registryName || ''}`.split('.');
44+
if (provider === 'custom' && name) {
45+
return name;
46+
}
47+
return provider || '';
48+
}
49+
3850
function getRegistryProviderIcon(provider) {
39-
const providerName = `${provider || ''}`.split('.')[0];
51+
const providerName = getRegistryProviderName(provider);
4052
return REGISTRY_PROVIDER_ICONS[providerName] || 'fas fa-cube';
4153
}
4254

@@ -71,7 +83,7 @@ const REGISTRY_PROVIDER_COLORS = {
7183
};
7284

7385
function getRegistryProviderColor(provider) {
74-
return REGISTRY_PROVIDER_COLORS[provider.split('.')[0]] || '#6B7280';
86+
return REGISTRY_PROVIDER_COLORS[getRegistryProviderName(provider)] || '#6B7280';
7587
}
7688

7789
/**
@@ -83,4 +95,11 @@ async function getAllRegistries() {
8395
return response.json();
8496
}
8597

86-
export { getRegistryIcon, getRegistryProviderIcon, getRegistryProviderColor, getAllRegistries };
98+
export {
99+
getRegistryIcon,
100+
getRegistryProviderName,
101+
getRegistryDisplayName,
102+
getRegistryProviderIcon,
103+
getRegistryProviderColor,
104+
getAllRegistries,
105+
};

0 commit comments

Comments
 (0)