Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions build/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
gateway "github.com/moby/buildkit/frontend/gateway/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/tonistiigi/fsutil/types"
)

type InvokeConfig struct {
Expand Down Expand Up @@ -145,6 +146,14 @@ func (c *Container) Exec(ctx context.Context, cfg *InvokeConfig, stdin io.ReadCl
return err
}

func (c *Container) ReadFile(ctx context.Context, req gateway.ReadRequest) ([]byte, error) {
return c.container.ReadFile(ctx, req)
}

func (c *Container) ReadDir(ctx context.Context, req gateway.ReadDirRequest) ([]*types.Stat, error) {
return c.container.ReadDir(ctx, req)
}

func exec(ctx context.Context, resultCtx *ResultHandle, cfg *InvokeConfig, ctr gateway.Container, stdin io.ReadCloser, stdout io.WriteCloser, stderr io.WriteCloser) error {
processCfg, err := resultCtx.getProcessConfig(cfg, stdin, stdout, stderr)
if err != nil {
Expand Down
15 changes: 8 additions & 7 deletions dap/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,14 @@ func (t *thread) pause(c Context, ref gateway.Reference, err error, mounts map[s
}
t.paused = make(chan stepType, 1)

ctx, cancel := context.WithCancelCause(c)
t.collectStackTrace(ctx, pos, mounts)
t.cancel = cancel

if ref != nil || err != nil {
t.prepareResultHandle(c, ref, err)
}

ctx, cancel := context.WithCancelCause(c)
t.collectStackTrace(ctx, pos)
t.cancel = cancel

event.ThreadId = t.id
c.C() <- &dap.StoppedEvent{
Event: dap.Event{Event: "stopped"},
Expand Down Expand Up @@ -544,12 +544,13 @@ func (t *thread) releaseState() {
t.variables.Reset()
}

func (t *thread) collectStackTrace(ctx context.Context, pos *step, mounts map[string]gateway.Reference) {
func (t *thread) collectStackTrace(ctx context.Context, pos *step) {
res := t.rCtx
for pos != nil {
frame := pos.frame
frame.ExportVars(ctx, mounts, t.variables)
frame.ExportVars(ctx, res, t.variables)
t.stackTrace = append(t.stackTrace, int32(frame.Id))
pos, mounts = pos.out, nil
pos, res = pos.out, nil
}
}

Expand Down
44 changes: 25 additions & 19 deletions dap/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"
"unicode/utf8"

"github.com/docker/buildx/build"
"github.com/google/go-dap"
"github.com/moby/buildkit/client/llb"
gateway "github.com/moby/buildkit/frontend/gateway/client"
Expand Down Expand Up @@ -67,10 +68,10 @@ func (f *frame) fillLocation(def *llb.Definition, loc *pb.Locations, ws string,
}
}

func (f *frame) ExportVars(ctx context.Context, mounts map[string]gateway.Reference, refs *variableReferences) {
func (f *frame) ExportVars(ctx context.Context, res *build.ResultHandle, refs *variableReferences) {
f.fillVarsFromOp(f.op, refs)
if len(mounts) > 0 {
f.fillVarsFromResult(ctx, mounts, refs)
if res != nil {
f.fillVarsFromResult(ctx, res, refs)
}
}

Expand Down Expand Up @@ -186,30 +187,35 @@ func execOpVars(exec *pb.ExecOp, refs *variableReferences) dap.Variable {
}
}

func (f *frame) fillVarsFromResult(ctx context.Context, mounts map[string]gateway.Reference, refs *variableReferences) {
func (f *frame) fillVarsFromResult(ctx context.Context, res *build.ResultHandle, refs *variableReferences) {
f.scopes = append(f.scopes, dap.Scope{
Name: "File Explorer",
PresentationHint: "locals",
VariablesReference: refs.New(func() []dap.Variable {
return fsVars(ctx, mounts, "/", refs)
ctr, err := build.NewContainer(ctx, res, &build.InvokeConfig{})
if err != nil {
return []dap.Variable{
{
Name: "error1",
Value: err.Error(),
},
}
}
return fsVars(ctx, ctr, "/", refs)
}),
Expensive: true,
})
}

func fsVars(ctx context.Context, mounts map[string]gateway.Reference, path string, vars *variableReferences) []dap.Variable {
path, ref := lookupPath(path, mounts)
if ref == nil {
return nil
}

files, err := ref.ReadDir(ctx, gateway.ReadDirRequest{
func fsVars(ctx context.Context, ctr *build.Container, path string, vars *variableReferences) []dap.Variable {
req := gateway.ReadDirRequest{
Path: path,
})
}
files, err := ctr.ReadDir(ctx, req)
if err != nil {
return []dap.Variable{
{
Name: "error",
Name: "error2",
Value: err.Error(),
},
}
Expand All @@ -233,15 +239,15 @@ func fsVars(ctx context.Context, mounts map[string]gateway.Reference, path strin
return statVars(file)
}),
}
return append([]dap.Variable{dvar}, fsVars(ctx, mounts, fullpath, vars)...)
return append([]dap.Variable{dvar}, fsVars(ctx, ctr, fullpath, vars)...)
})
fv.Value = ""
} else {
fv.Value = stat
fv.VariablesReference = vars.New(func() (dvars []dap.Variable) {
if fs.FileMode(file.Mode).IsRegular() {
// Regular file so display a small blurb of the file.
dvars = append(dvars, fileVars(ctx, ref, fullpath)...)
dvars = append(dvars, fileVars(ctx, ctr, fullpath)...)
}
return append(dvars, statVars(file)...)
})
Expand All @@ -257,8 +263,8 @@ func statf(st *types.Stat) string {
return fmt.Sprintf("%s %d:%d %s", mode, st.Uid, st.Gid, modTime.Format("Jan 2 15:04:05 2006"))
}

func fileVars(ctx context.Context, ref gateway.Reference, fullpath string) []dap.Variable {
b, err := ref.ReadFile(ctx, gateway.ReadRequest{
func fileVars(ctx context.Context, ctr *build.Container, fullpath string) []dap.Variable {
b, err := ctr.ReadFile(ctx, gateway.ReadRequest{
Filename: fullpath,
Range: &gateway.FileRange{Length: 512},
})
Expand All @@ -274,7 +280,7 @@ func fileVars(ctx context.Context, ref gateway.Reference, fullpath string) []dap
} else {
if len(b) == 512 {
// Get the remainder of the file.
remaining, err := ref.ReadFile(ctx, gateway.ReadRequest{
remaining, err := ctr.ReadFile(ctx, gateway.ReadRequest{
Filename: fullpath,
Range: &gateway.FileRange{Offset: 512},
})
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,5 @@ exclude (

// restore junctions to have os.ModeSymlink flag set on Windows: https://github.com/docker/buildx/issues/3221
godebug winsymlink=0

replace github.com/moby/buildkit => ../buildkit
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ github.com/containerd/fifo v1.1.0 h1:4I2mbh5stb1u6ycIABlBw9zgtlK8viPI9QkQNRQEEmY
github.com/containerd/fifo v1.1.0/go.mod h1:bmC4NWMbXlt2EZ0Hc7Fx7QzTFxgPID13eH0Qu+MAb2o=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/containerd/nydus-snapshotter v0.15.2 h1:qsHI4M+Wwrf6Jr4eBqhNx8qh+YU0dSiJ+WPmcLFWNcg=
github.com/containerd/nydus-snapshotter v0.15.2/go.mod h1:FfwH2KBkNYoisK/e+KsmNr7xTU53DmnavQHMFOcXwfM=
github.com/containerd/nydus-snapshotter v0.15.4 h1:l59kGRVMtwMLDLh322HsWhEsBCkRKMkGWYV5vBeLYCE=
github.com/containerd/nydus-snapshotter v0.15.4/go.mod h1:eRJqnxQDr48HNop15kZdLZpFF5B6vf6Q11Aq1K0E4Ms=
github.com/containerd/platforms v1.0.0-rc.1 h1:83KIq4yy1erSRgOVHNk1HYdPvzdJ5CnsWaRoJX4C41E=
github.com/containerd/platforms v1.0.0-rc.1/go.mod h1:J71L7B+aiM5SdIEqmd9wp6THLVRzJGXfNuWCZCllLA4=
github.com/containerd/plugin v1.0.0 h1:c8Kf1TNl6+e2TtMHZt+39yAPDbouRH9WAToRjex483Y=
Expand Down Expand Up @@ -255,8 +255,6 @@ github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTS
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/mitchellh/mapstructure v0.0.0-20150613213606-2caf8efc9366/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/moby/buildkit v0.25.0 h1:cRgh74ymzyHxS5a/lsYT4OCyVU8iC3UgkwasIEUi0og=
github.com/moby/buildkit v0.25.0/go.mod h1:phM8sdqnvgK2y1dPDnbwI6veUCXHOZ6KFSl6E164tkc=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ=
Expand Down
30 changes: 30 additions & 0 deletions vendor/github.com/moby/buildkit/client/build.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/moby/buildkit/frontend/gateway/pb/caps.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading