Skip to content

Commit 46f8d3e

Browse files
committed
restructure native default via env vars
1 parent 89c9616 commit 46f8d3e

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- **Compose-file digest update support** — Docker-compose trigger now supports digest-pinned image references in compose files (`image@sha256:...` and `image:tag@sha256:...`) so digest-based services can be updated without dropping pinning.
1717

1818
- **Compose-native auto-compose discovery** — Added `dd.compose.native` / `wud.compose.native` container labels to enable deriving compose file paths from native Compose labels (`com.docker.compose.project.config_files` + `com.docker.compose.project.working_dir`) when `dd.compose.file` is not set. This requires the resolved compose path to exist inside the drydock container (same path context used by `docker compose`).
19-
- **Watcher-wide compose-native default** — Added `DD_WATCHER_DOCKER_{name}_COMPOSENATIVE=true` to enable compose-native path discovery for all containers watched by a Docker watcher, with per-container `dd.compose.native` still taking precedence.
19+
- **Watcher-wide compose-native default** — Added `DD_WATCHER_{name}_COMPOSE_NATIVE=true` to enable compose-native path discovery for all containers watched by a Docker watcher, with per-container `dd.compose.native` still taking precedence.
2020

2121
### Fixed
2222

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ When using the Docker Compose trigger, container labels can override trigger set
402402
| `dd.compose.prune` | `wud.compose.prune` | `DD_TRIGGER_DOCKERCOMPOSE_xxx_PRUNE` | `true` / `false` |
403403
| `dd.compose.dryrun` | `wud.compose.dryrun` | `DD_TRIGGER_DOCKERCOMPOSE_xxx_DRYRUN` | `true` / `false` |
404404
| `dd.compose.auto` | `wud.compose.auto` | `DD_TRIGGER_DOCKERCOMPOSE_xxx_AUTO` | `true` / `false` |
405-
| `dd.compose.native` | `wud.compose.native` | `DD_WATCHER_DOCKER_xxx_COMPOSENATIVE` | `true` / `false` |
405+
| `dd.compose.native` | `wud.compose.native` | `DD_WATCHER_<WATCHER_NAME>_COMPOSE_NATIVE` | `true` / `false` |
406406
| `dd.compose.threshold` | `wud.compose.threshold` | `DD_TRIGGER_DOCKERCOMPOSE_xxx_THRESHOLD` | `all` / `major` / `minor` / `patch` |
407407

408408
Behavior notes:
@@ -411,13 +411,14 @@ Behavior notes:
411411
- That generated compose trigger is set with `requireinclude=true` and auto-appended to the container include list, so it only runs for explicitly associated containers.
412412
- `dd.compose.native` / `wud.compose.native` enables deriving compose file paths from native Compose labels (`com.docker.compose.project.config_files` and `com.docker.compose.project.working_dir`).
413413
- Compose-native/automatic detection requires the resolved compose file path to be valid inside the drydock container (same path that `docker compose` uses); if Compose was run from a host-only path, bind-mount that path into drydock at the same location or set `dd.compose.file` explicitly.
414-
- `DD_WATCHER_DOCKER_xxx_COMPOSENATIVE=true` enables compose-native lookup by default for all containers in that watcher (container label can still override).
414+
- `DD_WATCHER_<WATCHER_NAME>_COMPOSE_NATIVE=true` enables compose-native lookup by default for all containers in that watcher (container label can still override).
415415
- If `dd.compose.auto` is omitted, normal trigger default applies (`auto=true`).
416416
- You can set watcher-level defaults via env vars (per watcher):
417417
- `DD_WATCHER_<WATCHER_NAME>_COMPOSE_BACKUP`
418418
- `DD_WATCHER_<WATCHER_NAME>_COMPOSE_PRUNE`
419419
- `DD_WATCHER_<WATCHER_NAME>_COMPOSE_DRYRUN`
420420
- `DD_WATCHER_<WATCHER_NAME>_COMPOSE_AUTO`
421+
- `DD_WATCHER_<WATCHER_NAME>_COMPOSE_NATIVE`
421422
- `DD_WATCHER_<WATCHER_NAME>_COMPOSE_THRESHOLD`
422423
These defaults apply when corresponding compose labels are not present.
423424

app/configuration/index.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ test('getWatcherConfiguration should return configured watchers when overridden'
4848
});
4949
});
5050

51+
test('getWatcherConfiguration should map COMPOSE_NATIVE into compose.native', async () => {
52+
configuration.ddEnvVars.DD_WATCHER_LOCAL_COMPOSE_NATIVE = 'true';
53+
54+
const watcherConfigurations = configuration.getWatcherConfigurations();
55+
expect(watcherConfigurations.local.compose.native).toStrictEqual('true');
56+
57+
delete configuration.ddEnvVars.DD_WATCHER_LOCAL_COMPOSE_NATIVE;
58+
});
59+
5160
test('getWatcherConfiguration should map MAINTENANCE_WINDOW aliases', async () => {
5261
configuration.ddEnvVars.DD_WATCHER_LOCAL_MAINTENANCE_WINDOW = '0 2 * * *';
5362
configuration.ddEnvVars.DD_WATCHER_LOCAL_MAINTENANCE_WINDOW_TZ = 'Europe/Paris';

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,10 +2920,12 @@ describe('Docker Watcher', () => {
29202920
expect(result.triggerInclude).toBe('dockercompose.my-stack-test-container-native');
29212921
});
29222922

2923-
test('should auto-include dockercompose trigger from compose-native labels when watcher composenative is enabled', async () => {
2923+
test('should auto-include dockercompose trigger from compose-native labels when watcher compose.native is enabled', async () => {
29242924
const container = await setupContainerDetailTest(docker, {
29252925
registerConfig: {
2926-
composenative: true,
2926+
compose: {
2927+
native: true,
2928+
},
29272929
},
29282930
container: {
29292931
Image: 'nginx:1.0.0',
@@ -2948,7 +2950,9 @@ describe('Docker Watcher', () => {
29482950
test('should not auto-include dockercompose trigger from compose-native labels when dd.compose.native is false', async () => {
29492951
const container = await setupContainerDetailTest(docker, {
29502952
registerConfig: {
2951-
composenative: true,
2953+
compose: {
2954+
native: true,
2955+
},
29522956
},
29532957
container: {
29542958
Image: 'nginx:1.0.0',

app/watchers/providers/docker/Docker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ export interface DockerWatcherConfiguration extends ComponentConfiguration {
100100
watchdigest?: any;
101101
watchevents: boolean;
102102
watchatstart: boolean;
103-
composenative: boolean;
104103
maintenancewindow?: string;
105104
maintenancewindowtz: string;
106105
compose?: {
107106
backup?: boolean;
108107
prune?: boolean;
109108
dryrun?: boolean;
110109
auto?: boolean;
110+
native?: boolean;
111111
threshold?: string;
112112
};
113113
imgset?: Record<string, any>;
@@ -1159,7 +1159,6 @@ class Docker extends Watcher {
11591159
watchdigest: this.joi.any(),
11601160
watchevents: this.joi.boolean().default(true),
11611161
watchatstart: this.joi.boolean().default(true),
1162-
composenative: this.joi.boolean().default(false),
11631162
maintenancewindow: joi.string().cron().optional(),
11641163
maintenancewindowtz: this.joi.string().default('UTC'),
11651164
compose: this.joi
@@ -1168,6 +1167,7 @@ class Docker extends Watcher {
11681167
prune: this.joi.boolean(),
11691168
dryrun: this.joi.boolean(),
11701169
auto: this.joi.boolean(),
1170+
native: this.joi.boolean(),
11711171
threshold: this.joi.string(),
11721172
})
11731173
.default({}),
@@ -1371,7 +1371,7 @@ class Docker extends Watcher {
13711371
const containerLabels = containerInStore.labels || {};
13721372
const composeFilePath = getComposeFilePathFromLabels(
13731373
containerLabels,
1374-
this.configuration.composenative,
1374+
Boolean(this.configuration.compose?.native),
13751375
);
13761376
if (!composeFilePath) {
13771377
continue;
@@ -2156,7 +2156,7 @@ class Docker extends Watcher {
21562156
const containerId = containerFound.id;
21572157
const composeFilePath = getComposeFilePathFromLabels(
21582158
labelsToApply,
2159-
this.configuration.composenative,
2159+
Boolean(this.configuration.compose?.native),
21602160
);
21612161
if (composeFilePath) {
21622162
let dockercomposeTriggerId = this.composeTriggersByContainer[containerId];
@@ -2631,7 +2631,7 @@ class Docker extends Watcher {
26312631
const containerLabels = container.Labels || {};
26322632
const composeFilePath = getComposeFilePathFromLabels(
26332633
containerLabels,
2634-
this.configuration.composenative,
2634+
Boolean(this.configuration.compose?.native),
26352635
);
26362636
const needsComposeTriggerCreation =
26372637
!!composeFilePath && !this.composeTriggersByContainer[containerId];

0 commit comments

Comments
 (0)