bake: fix BUILDX_BAKE_FILE env behavior

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2025-06-30 15:17:21 +02:00
parent 6deb9ff384
commit f1db389f07
2 changed files with 20 additions and 4 deletions
+4 -4
View File
@@ -465,12 +465,12 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
filesFromEnv := false
if len(options.files) == 0 {
envFiles, err := bakeEnvFiles(os.LookupEnv)
if err != nil {
if envFiles, err := bakeEnvFiles(os.LookupEnv); err != nil {
return err
} else if len(envFiles) > 0 {
options.files = envFiles
filesFromEnv = true
}
options.files = envFiles
filesFromEnv = true
}
// reset to nil to avoid override is unset
if !cmd.Flags().Lookup("no-cache").Changed {
+16
View File
@@ -2204,6 +2204,22 @@ target "second" {
}
`)
t.Run("no env", func(t *testing.T) {
dir := tmpdir(t,
fstest.CreateFile("docker-bake.hcl", bakeFileFirst, 0600),
fstest.CreateFile("first", []byte("first"), 0600),
)
cmd := buildxCmd(sb,
withDir(dir),
withArgs("bake", "--progress=plain", "first"))
dt, err := cmd.CombinedOutput()
require.NoError(t, err, string(dt))
require.Contains(t, string(dt), `#1 [internal] load local bake definitions`)
require.NotContains(t, string(dt), `from BUILDX_BAKE_FILE env`)
require.Contains(t, string(dt), `#1 reading docker-bake.hcl`)
})
t.Run("single file", func(t *testing.T) {
dir := tmpdir(t,
fstest.CreateFile("first.hcl", bakeFileFirst, 0600),