Repository navigation
fix(dry-run): skip lifecycle hooks instead of failing on exec attach - #14504
Conversation
The dry-run client cannot attach to an exec, so any lifecycle hook reached under --dry-run (pre_stop on down/stop/restart, post_start on up/restart) made the command fail with "interactive exec is not supported in dry-run mode". A dry-run must have no side effects, so skip the hook in runHook, which every hook phase goes through, rather than guarding each call site. Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ndeloof
left a comment
There was a problem hiding this comment.
LGTM. Two small points, neither blocking:
- The description says the single guard covers every hook phase, but
compose --dry-run runon a service with apost_starthook never reaches it: it hangs forever (same onmain).runPostStartHooksOnEventwaits for astartevent that the dry-run client never produces, andrun.gothen waits onhookErrChafterRunStartfails. Out of scope here, but worth a follow-up. - nit: see the inline comment.
| // A dry-run must have no side effects, and the dry-run client cannot | ||
| // attach to an exec: skip the hook rather than fail on it. | ||
| if s.dryRun { | ||
| return nil |
There was a problem hiding this comment.
nit: a logrus.Debugf here would make the skip discoverable with --verbose (logrus isn't imported in hook.go yet).
WithDryRun re-initializes the Docker CLI with fresh client options, whose empty log level makes Initialize reset logrus to info. Under --dry-run, --verbose was therefore dropped as soon as the backend was created, hiding every debug log of the operation. Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
Hooks are skipped silently under --dry-run. Log each skipped hook at debug level so --verbose shows which one would have run. Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
This incremental review covers only the commits pushed since
ab56ce19494c.
The two changes in this incremental diff are correct:
-
pkg/compose/compose.go— Preserving the current logrus level beforecli.InitializeinWithDryRunby assigningoptions.LogLevel = logrus.GetLevel().String().logrus.GetLevel()uses an atomic load (no race), thelogrusimport was already present, and this correctly preventsInitializefrom resetting a non-default log level (e.g. set by--verbose) toinfo. -
pkg/compose/hook.go— Adding alogrus.Debugfcall before the existingreturn nilin theif s.dryRunguard gives useful diagnostics when hooks are skipped. Thelogrusimport added for this is correctly ordered (third-party block). One minor note:%vonhook.Command([]string) produces bracket-delimited unquoted output ([cmd arg]) that becomes ambiguous when arguments contain spaces;%qwould produce unambiguous output — but this is debug-level only with no functional impact, so no inline comment is warranted.
Under
--dry-run, any lifecycle hook (pre_stopondown/stop/restart,post_startonup/restart) made the command fail withinteractive exec is not supported in dry-run mode: the dry-run client creates the exec but cannot attach to it.runHooknow returns early in dry-run mode. Hooks are skipped, since a dry-run must have no side effects, and this single guard covers the hook phases ofup,down,stopandrestart.compose --dry-run runon a service with apost_starthook still hangs, as it does onmain. It never reachesrunHook, so it is left for a follow-up.