diff --git a/bake/bake.go b/bake/bake.go index 6168f155..59956925 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -951,7 +951,12 @@ func updateContext(t *build.Inputs, inp *Input) { if build.IsRemoteURL(t.ContextPath) { return } - st := llb.Scratch().File(llb.Copy(*inp.State, t.ContextPath, "/"), llb.WithCustomNamef("set context to %s", t.ContextPath)) + st := llb.Scratch().File( + llb.Copy(*inp.State, t.ContextPath, "/", &llb.CopyInfo{ + CopyDirContentsOnly: true, + }), + llb.WithCustomNamef("set context to %s", t.ContextPath), + ) t.ContextState = &st } @@ -1027,9 +1032,6 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) { if t.Dockerfile != nil { dockerfilePath = *t.Dockerfile } - if !build.IsRemoteURL(contextPath) && !path.IsAbs(dockerfilePath) { - dockerfilePath = path.Join(contextPath, dockerfilePath) - } bi := build.Inputs{ ContextPath: contextPath, @@ -1040,6 +1042,9 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) { bi.DockerfileInline = *t.DockerfileInline } updateContext(&bi, inp) + if !build.IsRemoteURL(bi.ContextPath) && bi.ContextState == nil && !path.IsAbs(bi.DockerfilePath) { + bi.DockerfilePath = path.Join(bi.ContextPath, bi.DockerfilePath) + } if strings.HasPrefix(bi.ContextPath, "cwd://") { bi.ContextPath = path.Clean(strings.TrimPrefix(bi.ContextPath, "cwd://")) }