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
88 changes: 81 additions & 7 deletions dap/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/moby/buildkit/solver/pb"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/tonistiigi/fsutil/types"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -323,16 +324,12 @@ func (t *thread) pause(c Context, k string, refs map[string]gateway.Reference, e
}
t.paused = make(chan stepType, 1)

t.prepareResultHandle(c, k, refs, err)

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

// Used for exec. Only works if there was an error or if the step returns
// a root mount.
if ref, ok := refs[k]; ok || err != nil {
t.prepareResultHandle(c, ref, err)
}

event.ThreadId = t.id
c.C() <- &dap.StoppedEvent{
Event: dap.Event{Event: "stopped"},
Expand All @@ -341,7 +338,15 @@ func (t *thread) pause(c Context, k string, refs map[string]gateway.Reference, e
return t.paused
}

func (t *thread) prepareResultHandle(c Context, ref gateway.Reference, err error) {
func (t *thread) prepareResultHandle(c Context, k string, refs map[string]gateway.Reference, err error) {
var ref gateway.Reference
if err == nil {
var ok bool
if ref, ok = refs[k]; !ok {
return
}
}

// Create a context for cancellations and make the cancel function
// block on the wait group.
var wg sync.WaitGroup
Expand All @@ -353,6 +358,26 @@ func (t *thread) prepareResultHandle(c Context, ref gateway.Reference, err error

t.rCtx = build.NewResultHandle(ctx, t.c, ref, t.meta, err)

if err != nil {
var solveErr *errdefs.SolveError
if errors.As(err, &solveErr) {
if exec, ok := solveErr.Op.Op.(*pb.Op_Exec); ok {
rCtx := t.rCtx

getContainer := sync.OnceValues(func() (gateway.Container, error) {
return rCtx.NewContainer(ctx, &build.InvokeConfig{})
})

for i, m := range exec.Exec.Mounts {
refs[m.Dest] = &mountReference{
getContainer: getContainer,
index: i,
}
}
}
}
}

// Start the attach. Use the context we created and perform it in
// a goroutine. We aren't necessarily assuming this will actually work.
wg.Add(1)
Expand Down Expand Up @@ -680,3 +705,52 @@ func (t *thread) rewind(ctx Context, inErr error) (k string, result *step, mount
}
return k, result, mounts, inErr
}

type mountReference struct {
getContainer func() (gateway.Container, error)
index int
}

func (r *mountReference) ToState() (llb.State, error) {
return llb.State{}, errors.New("unimplemented")
}

func (r *mountReference) Evaluate(ctx context.Context) error {
return nil
}

func (r *mountReference) ReadFile(ctx context.Context, req gateway.ReadRequest) ([]byte, error) {
ctr, err := r.getContainer()
if err != nil {
return nil, err
}

return ctr.ReadFile(ctx, gateway.ReadContainerRequest{
ReadRequest: req,
Index: r.index,
})
}

func (r *mountReference) StatFile(ctx context.Context, req gateway.StatRequest) (*types.Stat, error) {
ctr, err := r.getContainer()
if err != nil {
return nil, err
}

return ctr.StatFile(ctx, gateway.StatContainerRequest{
StatRequest: req,
Index: r.index,
})
}

func (r *mountReference) ReadDir(ctx context.Context, req gateway.ReadDirRequest) ([]*types.Stat, error) {
ctr, err := r.getContainer()
if err != nil {
return nil, err
}

return ctr.ReadDir(ctx, gateway.ReadDirContainerRequest{
ReadDirRequest: req,
Index: r.index,
})
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,5 @@ require (

// 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 => github.com/jsternberg/buildkit v0.12.1-0.20260108212518-d47b53f94598
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jsternberg/buildkit v0.12.1-0.20260108212518-d47b53f94598 h1:cWId6kOBQvY6PHRhlRTnFx/TTrZaKjol6rlh1ogfPsY=
github.com/jsternberg/buildkit v0.12.1-0.20260108212518-d47b53f94598/go.mod h1:LtUhyzVLAD0ilniDZRbghEyRq9CgZAY7ywMXlVo9MBI=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
Expand All @@ -210,8 +212,6 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
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/moby/buildkit v0.26.1-0.20260106154623-ed6dc749ce40 h1:h45o8dTo7Cq1Su49bs9VHP83Fdp3olgMfgo3tZULXUw=
github.com/moby/buildkit v0.26.1-0.20260106154623-ed6dc749ce40/go.mod h1:LtUhyzVLAD0ilniDZRbghEyRq9CgZAY7ywMXlVo9MBI=
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.2.0 h1:zg5QDUM2mi0JIM9fdQZWC7U8+2ZfixfTYoHL7rWUcP8=
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.

18 changes: 18 additions & 0 deletions vendor/github.com/moby/buildkit/frontend/gateway/client/client.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.

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