Skip to content

Commit 31784b5

Browse files
committed
more fixing
1 parent 00616d1 commit 31784b5

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

app/triggers/providers/dockercompose/Dockercompose.test.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,73 @@ describe('Dockercompose Trigger', () => {
12711271
expect(result).toBeNull();
12721272
});
12731273

1274+
test('getComposeFileForContainer should use native compose labels when watcher compose.native is enabled', () => {
1275+
trigger.configuration.file = undefined;
1276+
getState.mockReturnValueOnce({
1277+
registry: {
1278+
hub: {
1279+
getImageFullName: (image, tag) => `${image.name}:${tag}`,
1280+
},
1281+
},
1282+
watcher: {
1283+
'docker.local': {
1284+
configuration: {
1285+
compose: {
1286+
native: 'true',
1287+
},
1288+
},
1289+
dockerApi: mockDockerApi,
1290+
},
1291+
},
1292+
});
1293+
1294+
const container = {
1295+
watcher: 'local',
1296+
labels: {
1297+
'com.docker.compose.project.working_dir': '/opt/stack',
1298+
'com.docker.compose.project.config_files': 'compose.yml',
1299+
},
1300+
};
1301+
1302+
const result = trigger.getComposeFileForContainer(container);
1303+
1304+
expect(result).toBe('/opt/stack/compose.yml');
1305+
});
1306+
1307+
test('getComposeFileForContainer should prioritize dd.compose.native label over watcher compose.native', () => {
1308+
trigger.configuration.file = undefined;
1309+
getState.mockReturnValueOnce({
1310+
registry: {
1311+
hub: {
1312+
getImageFullName: (image, tag) => `${image.name}:${tag}`,
1313+
},
1314+
},
1315+
watcher: {
1316+
'docker.local': {
1317+
configuration: {
1318+
compose: {
1319+
native: 'true',
1320+
},
1321+
},
1322+
dockerApi: mockDockerApi,
1323+
},
1324+
},
1325+
});
1326+
1327+
const container = {
1328+
watcher: 'local',
1329+
labels: {
1330+
'dd.compose.native': 'false',
1331+
'com.docker.compose.project.working_dir': '/opt/stack',
1332+
'com.docker.compose.project.config_files': 'compose.yml',
1333+
},
1334+
};
1335+
1336+
const result = trigger.getComposeFileForContainer(container);
1337+
1338+
expect(result).toBeNull();
1339+
});
1340+
12741341
test('getComposeFileForContainer should fall back to default config file', () => {
12751342
trigger.configuration.file = '/default/compose.yml';
12761343
const container = { labels: {} };

app/triggers/providers/dockercompose/Dockercompose.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ const DD_COMPOSE_NATIVE_LABEL = 'dd.compose.native';
1212
const WUD_COMPOSE_NATIVE_LABEL = 'wud.compose.native';
1313

1414
function isNativeComposeEnabled(labels = {}) {
15+
const normalizeToBoolean = (value) => `${value}`.trim().toLowerCase() === 'true';
16+
1517
const nativeLabel = labels[DD_COMPOSE_NATIVE_LABEL] ?? labels[WUD_COMPOSE_NATIVE_LABEL];
16-
if (nativeLabel === undefined) {
17-
return false;
18+
if (nativeLabel !== undefined) {
19+
return normalizeToBoolean(nativeLabel);
1820
}
19-
const normalizedNativeLabel = `${nativeLabel}`.trim().toLowerCase();
20-
return normalizedNativeLabel === 'true';
21+
22+
return false;
2123
}
2224

2325
function splitDigestReference(image) {
@@ -236,7 +238,12 @@ class Dockercompose extends Docker {
236238
}
237239

238240
// Fall back to native Docker Compose labels when explicitly enabled
239-
const nativeComposeEnabled = isNativeComposeEnabled(container.labels);
241+
const watcherComposeNativeEnabled = this.getWatcher(container)?.configuration?.compose?.native;
242+
const nativeComposeEnabled =
243+
isNativeComposeEnabled(container.labels) ||
244+
(container.labels?.[DD_COMPOSE_NATIVE_LABEL] === undefined &&
245+
container.labels?.[WUD_COMPOSE_NATIVE_LABEL] === undefined &&
246+
`${watcherComposeNativeEnabled}`.trim().toLowerCase() === 'true');
240247
const composeConfigFiles = container.labels?.[COMPOSE_PROJECT_CONFIG_FILES_LABEL];
241248
if (nativeComposeEnabled && composeConfigFiles && composeConfigFiles.trim() !== '') {
242249
const composeProjectWorkingDir = container.labels?.[COMPOSE_PROJECT_WORKING_DIR_LABEL];

0 commit comments

Comments
 (0)