diff --git a/commands/bake.go b/commands/bake.go index 574a6874..d6780d29 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "os" + "strings" "github.com/containerd/console" "github.com/containerd/containerd/platforms" @@ -142,11 +143,19 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com } } }() - + localFilesArg, remoteFilesArg := getFilesArgs(in.files) if url != "" { - files, inp, err = bake.ReadRemoteFiles(ctx, nodes, url, in.files, printer) + files, inp, err = bake.ReadRemoteFiles(ctx, nodes, url, remoteFilesArg, printer) + if len(localFilesArg) > 0 { + var localFiles []bake.File + localFiles, err = bake.ReadLocalFiles(localFilesArg, dockerCli.In()) + files = append(files, localFiles...) + } } else { - files, err = bake.ReadLocalFiles(in.files, dockerCli.In()) + var filesArg []string + filesArg = append(filesArg, localFilesArg...) + filesArg = append(filesArg, remoteFilesArg...) + files, err = bake.ReadLocalFiles(filesArg, dockerCli.In()) } if err != nil { return err @@ -257,3 +266,16 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { return cmd } + +func getFilesArgs(s []string) ([]string, []string) { + var localFiles []string + var remoteFiles []string + for _, v := range s { + if strings.HasPrefix(v, "cwd://") { + localFiles = append(localFiles, strings.TrimPrefix(v, "cwd://")) + } else { + remoteFiles = append(remoteFiles, v) + } + } + return localFiles, remoteFiles +} diff --git a/tests/bake.go b/tests/bake.go index b76a8bb8..1791ead4 100644 --- a/tests/bake.go +++ b/tests/bake.go @@ -21,6 +21,7 @@ var bakeTests = []func(t *testing.T, sb integration.Sandbox){ testBakeLocal, testBakeRemote, testBakeRemoteCmdContext, + testBakeRemoteLocalOverride, testBakeRemoteCmdContextOverride, testBakeRemoteContextSubdir, testBakeRemoteCmdContextEscapeRoot, @@ -48,6 +49,11 @@ target "default" { require.NoError(t, err, out) require.FileExists(t, filepath.Join(dirDest, "foo")) + + out, err = bakeCmd(sb, withDir(dir), withArgs("--file", "cwd://docker-bake.hcl", "--set", "*.output=type=local,dest="+dirDest)) + require.NoError(t, err, out) + + require.FileExists(t, filepath.Join(dirDest, "foo")) } func testBakeRemote(t *testing.T, sb integration.Sandbox) { @@ -80,6 +86,48 @@ EOT require.FileExists(t, filepath.Join(dirDest, "foo")) } +func testBakeRemoteLocalOverride(t *testing.T, sb integration.Sandbox) { + remoteBakefile := []byte(` +target "default" { + dockerfile-inline = <