Repository navigation
fix(cli): load the project from COMPOSE_FILE when -p is set #14540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import ( | |
| "syscall" | ||
|
|
||
| "github.com/compose-spec/compose-go/v2/cli" | ||
| "github.com/compose-spec/compose-go/v2/consts" | ||
| "github.com/compose-spec/compose-go/v2/dotenv" | ||
| "github.com/compose-spec/compose-go/v2/loader" | ||
| composepaths "github.com/compose-spec/compose-go/v2/paths" | ||
|
|
@@ -281,7 +282,8 @@ func defaultStringArrayVar(env string) []string { | |
| func (o *ProjectOptions) projectOrName(ctx context.Context, dockerCli command.Cli, services ...string) (*types.Project, string, error) { | ||
| name := o.ProjectName | ||
| 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 == "" { | ||
| backend, err := compose.NewComposeService(dockerCli) | ||
| if err != nil { | ||
| return nil, "", err | ||
|
|
@@ -299,9 +301,12 @@ func (o *ProjectOptions) projectOrName(ctx context.Context, dockerCli command.Cl | |
| if jobErr, replaced := jobTargetErr(ctx, dockerCli, o, services, err); replaced { | ||
| return nil, "", jobErr | ||
| } | ||
| envProjectName := os.Getenv(ComposeProjectName) | ||
| if envProjectName != "" { | ||
| return nil, envProjectName, nil | ||
| if envProjectName := os.Getenv(ComposeProjectName); envProjectName != "" { | ||
| // -p takes precedence over COMPOSE_PROJECT_NAME | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both PRs rewrite this block. After #14151 this fallback can't be reached with nit: add a |
||
| if name == "" { | ||
| name = envProjectName | ||
| } | ||
| return nil, name, nil | ||
| } | ||
|
glours marked this conversation as resolved.
Resolved
|
||
| return nil, "", err | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
COMPOSE_FILEis treated as-ffor 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+ brokenCOMPOSE_FILE+COMPOSE_PROJECT_NAMEfalls back to label mode with a warning, which is what docker-agent's medium comment describes. Suggest a sharedexplicitFile()helper (ConfigPathsorCOMPOSE_FILE) used here and by the hard-error check in #14151.Also,
os.Getenvmisses aCOMPOSE_FILEset in.env, which compose-go reads (WithConfigFileEnvuses 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 stopnow fails on a stale/invalidCOMPOSE_FILEor a missing required variable, where it used to work label-only.