Repository navigation
Conversation
projectOrName only loaded the Compose model when -f was passed or when no project name was given. With -p and COMPOSE_FILE, the model was skipped, so commands like stop received no project and rebuilt it from container labels, which don't carry pre_stop hooks: the hooks were silently not run. COMPOSE_FILE is the environment equivalent of -f, so treat it the same way when deciding to load the model. Fixes docker#14535 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
…ilure When the Compose model can't be loaded, projectOrName falls back to the label-driven project and used COMPOSE_PROJECT_NAME while ignoring an explicit -p. With -p x and COMPOSE_PROJECT_NAME=y, commands such as ps, down or rm then targeted project y instead of x. Use -p first and COMPOSE_PROJECT_NAME only when -p is empty, matching the usual precedence. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
7d54ab6 to
e5a989e
Compare
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟡 NEEDS ATTENTION
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| var project *types.Project | ||
| if len(o.ConfigPaths) > 0 || o.ProjectName == "" { | ||
| // COMPOSE_FILE is the environment equivalent of -f | ||
| if len(o.ConfigPaths) > 0 || os.Getenv(consts.ComposeFilePath) != "" || o.ProjectName == "" { |
There was a problem hiding this comment.
COMPOSE_FILE is treated as -f for loading, but not for the failure policy of #14151 (hard error for an explicit file, warning only for an implicit one). With both PRs, -p x + broken COMPOSE_FILE + COMPOSE_PROJECT_NAME falls back to label mode with a warning, which is what docker-agent's medium comment describes. Suggest a shared explicitFile() helper (ConfigPaths or COMPOSE_FILE) used here and by the hard-error check in #14151.
Also, os.Getenv misses a COMPOSE_FILE set in .env, which compose-go reads (WithConfigFileEnv uses the project environment). With -p, #14535 stays unfixed in that case: handle it or document the limit.
Behavior change worth stating in the description: -p x stop now fails on a stale/invalid COMPOSE_FILE or a missing required variable, where it used to work label-only.
| if envProjectName != "" { | ||
| return nil, envProjectName, nil | ||
| if envProjectName := os.Getenv(ComposeProjectName); envProjectName != "" { | ||
| // -p takes precedence over COMPOSE_PROJECT_NAME |
There was a problem hiding this comment.
Both PRs rewrite this block. After #14151 this fallback can't be reached with -p set (no load, or hard error), so the name-precedence change becomes dead code, and the -p wins… / …used without -p subtests (explicit ConfigPaths + missing file) turn into hard errors. Land #14151 first and rebase, or fold the two.
nit: add a COMPOSE_FILE-based variant to the fallback tests.
…wed load error, strict service validation projectOrName and toProjectName resolved the project with opposite precedences, and projectOrName silently swallowed any load error when COMPOSE_PROJECT_NAME was set: a broken compose file sent stop, down, ps... into label-based reconstruction without a word — even when the file was named explicitly with --file. One precedence now, documented on both resolvers and applied identically by compose-go while loading: --project-name, then COMPOSE_PROJECT_NAME, then the model's name. The failure policy becomes explicit: an unreadable explicit --file is a hard error; no file around with COMPOSE_PROJECT_NAME set stays the silent file-less workflow; a present-but-broken implicit file falls back to label-based mode with a warning. Service-name validation follows one rule — strict whenever a model is available: restart and wait no longer silently no-op on a typo (validateServiceNames, profile-disabled services remain legitimate targets), and the hand-rolled checks in ps and volumes are removed as dead code, the load-time selection already rejecting unknown names (pinned by test). Epic docker#14074, F.4. Rebased onto main, which since merged the jobs work (docker#14093, docker#14234): projectOrName's job-target detection (jobTargetErr) is restored ahead of the new explicit-file hard-error branch -- the file loaded fine here, only the target's selection failed -- and validateServiceNames now checks project.AllJobs() too, since restart/wait route their service arguments through it instead of projectOrName's own selection. docker-agent review: the "compose file found but could not be loaded" warning's suppression guard only matched errdefs.IsNotFoundError (compose-go's own ErrNotFound sentinel) -- a raw os.ErrNotExist (e.g. a nonexistent --project-directory) wasn't recognized and would have printed a misleading warning. Added errors.Is(err, os.ErrNotExist) as a fallback, and TestProjectOrNameResolution now asserts the warning's presence/absence in both directions instead of just the fallback name. COMPOSE_FILE counts as an explicit file, like --file (explicitFile(): process environment or .env, as compose-go reads it): it is loaded even with --project-name (docker#14535, also addressed by docker#14540), and failing to load it is a hard error rather than a label-based fallback. Consistent with docker#14540's reading of COMPOSE_FILE as the environment equivalent of -f. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…wed load error, strict service validation projectOrName and toProjectName resolved the project with opposite precedences, and projectOrName silently swallowed any load error when COMPOSE_PROJECT_NAME was set: a broken compose file sent stop, down, ps... into label-based reconstruction without a word — even when the file was named explicitly with --file. One precedence now, documented on both resolvers and applied identically by compose-go while loading: --project-name, then COMPOSE_PROJECT_NAME, then the model's name. The failure policy becomes explicit: an unreadable explicit --file is a hard error; no file around with COMPOSE_PROJECT_NAME set stays the silent file-less workflow; a present-but-broken implicit file falls back to label-based mode with a warning. Service-name validation follows one rule — strict whenever a model is available: restart and wait no longer silently no-op on a typo (validateServiceNames, profile-disabled services remain legitimate targets), and the hand-rolled checks in ps and volumes are removed as dead code, the load-time selection already rejecting unknown names (pinned by test). Epic docker#14074, F.4. Rebased onto main, which since merged the jobs work (docker#14093, docker#14234): projectOrName's job-target detection (jobTargetErr) is restored ahead of the new explicit-file hard-error branch -- the file loaded fine here, only the target's selection failed -- and validateServiceNames now checks project.AllJobs() too, since restart/wait route their service arguments through it instead of projectOrName's own selection. docker-agent review: the "compose file found but could not be loaded" warning's suppression guard only matched errdefs.IsNotFoundError (compose-go's own ErrNotFound sentinel) -- a raw os.ErrNotExist (e.g. a nonexistent --project-directory) wasn't recognized and would have printed a misleading warning. Added errors.Is(err, os.ErrNotExist) as a fallback, and TestProjectOrNameResolution now asserts the warning's presence/absence in both directions instead of just the fallback name. COMPOSE_FILE counts as an explicit file, like --file (explicitFile(): process environment or .env, as compose-go reads it): it is loaded even with --project-name (docker#14535, also addressed by docker#14540), and failing to load it is a hard error rather than a label-based fallback. Consistent with docker#14540's reading of COMPOSE_FILE as the environment equivalent of -f. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…wed load error, strict service validation projectOrName and toProjectName resolved the project with opposite precedences, and projectOrName silently swallowed any load error when COMPOSE_PROJECT_NAME was set: a broken compose file sent stop, down, ps... into label-based reconstruction without a word — even when the file was named explicitly with --file. One precedence now, documented on both resolvers and applied identically by compose-go while loading: --project-name, then COMPOSE_PROJECT_NAME, then the model's name. The failure policy becomes explicit: an unreadable explicit --file is a hard error; no file around with COMPOSE_PROJECT_NAME set stays the silent file-less workflow; a present-but-broken implicit file falls back to label-based mode with a warning. Service-name validation follows one rule — strict whenever a model is available: restart and wait no longer silently no-op on a typo (validateServiceNames, profile-disabled services remain legitimate targets), and the hand-rolled checks in ps and volumes are removed as dead code, the load-time selection already rejecting unknown names (pinned by test). Epic docker#14074, F.4. Rebased onto main, which since merged the jobs work (docker#14093, docker#14234): projectOrName's job-target detection (jobTargetErr) is restored ahead of the new explicit-file hard-error branch -- the file loaded fine here, only the target's selection failed -- and validateServiceNames now checks project.AllJobs() too, since restart/wait route their service arguments through it instead of projectOrName's own selection. docker-agent review: the "compose file found but could not be loaded" warning's suppression guard only matched errdefs.IsNotFoundError (compose-go's own ErrNotFound sentinel) -- a raw os.ErrNotExist (e.g. a nonexistent --project-directory) wasn't recognized and would have printed a misleading warning. Added errors.Is(err, os.ErrNotExist) as a fallback, and TestProjectOrNameResolution now asserts the warning's presence/absence in both directions instead of just the fallback name. COMPOSE_FILE counts as an explicit file, like --file (explicitFile(): process environment or .env, as compose-go reads it): it is loaded even with --project-name (docker#14535, also addressed by docker#14540), and failing to load it is a hard error rather than a label-based fallback. Consistent with docker#14540's reading of COMPOSE_FILE as the environment equivalent of -f. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Fixes #14535
COMPOSE_FILEis now handled like-fwhen-pis set: the model is loaded, sostoprunspre_stophooks instead of rebuilding a label-only project that doesn't carry them.-pnow takes precedence overCOMPOSE_PROJECT_NAMEin the label-driven fallback (previously the env var won, and commands targeted the wrong project).