Skip to content

Commit 8cf2b0a

Browse files
Ensure dockercompose trigger creation uses existing dd/wud.compose.file labels only (#6)
* Initial plan * fix docker compose label-based trigger creation Co-authored-by: Crow-Control <7613738+Crow-Control@users.noreply.github.com> * test compose project label trigger fallback Co-authored-by: Crow-Control <7613738+Crow-Control@users.noreply.github.com> * revert compose metadata trigger fallback Co-authored-by: Crow-Control <7613738+Crow-Control@users.noreply.github.com> * fix compose trigger creation for cached labeled containers Co-authored-by: Crow-Control <7613738+Crow-Control@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Crow-Control <7613738+Crow-Control@users.noreply.github.com>
1 parent 6a794f7 commit 8cf2b0a

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,30 @@ describe('Docker Watcher', () => {
23372337
expect(result).toBe(existingContainer);
23382338
});
23392339

2340+
test('should not short-circuit existing container when compose label needs trigger creation', async () => {
2341+
const container = await setupContainerDetailTest(docker, {
2342+
container: {
2343+
Image: 'nginx:1.0.0',
2344+
Names: ['/existing-compose-container'],
2345+
Labels: {
2346+
'dd.compose.file': '/tmp/docker-compose.yml',
2347+
},
2348+
},
2349+
});
2350+
const existingContainer = { id: container.Id, error: undefined };
2351+
storeContainer.getContainer.mockReturnValue(existingContainer);
2352+
2353+
const result = await docker.addImageDetailsToContainer(container);
2354+
2355+
expect(result).not.toBe(existingContainer);
2356+
expect(registry.ensureDockercomposeTriggerForContainer).toHaveBeenCalledWith(
2357+
'existing-compose-container',
2358+
'/tmp/docker-compose.yml',
2359+
{},
2360+
);
2361+
expect(result.triggerInclude).toBe('dockercompose.tmp-existing-compose-container');
2362+
});
2363+
23402364
test('should add image details to new container', async () => {
23412365
const container = await setupContainerDetailTest(docker, {
23422366
container: { Image: 'nginx:1.0.0' },

app/watchers/providers/docker/Docker.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,10 +2417,17 @@ class Docker extends Watcher {
24172417
async addImageDetailsToContainer(container: any, labelOverrides: ContainerLabelOverrides = {}) {
24182418
const containerId = container.Id;
24192419
const containerLabels = container.Labels || {};
2420+
const composeFilePath = containerLabels[ddComposeFile] || containerLabels[wudComposeFile];
2421+
const needsComposeTriggerCreation =
2422+
!!composeFilePath && !this.composeTriggersByContainer[containerId];
24202423

24212424
// Is container already in store? just return it :)
24222425
const containerInStore = storeContainer.getContainer(containerId);
2423-
if (containerInStore !== undefined && containerInStore.error === undefined) {
2426+
if (
2427+
containerInStore !== undefined &&
2428+
containerInStore.error === undefined &&
2429+
!needsComposeTriggerCreation
2430+
) {
24242431
this.ensureLogger();
24252432
this.log.debug(`Container ${containerInStore.id} already in store`);
24262433
return containerInStore;
@@ -2472,7 +2479,6 @@ class Docker extends Watcher {
24722479
}
24732480
const containerName = getContainerName(container);
24742481
let triggerIncludeUpdated = resolvedConfig.triggerInclude;
2475-
const composeFilePath = containerLabels[ddComposeFile] || containerLabels[wudComposeFile];
24762482
const dockercomposeTriggerConfiguration =
24772483
getDockercomposeTriggerConfigurationFromLabels(containerLabels);
24782484
if (composeFilePath) {

0 commit comments

Comments
 (0)