@@ -8,12 +8,41 @@ import (
88 "sync/atomic"
99 "syscall"
1010
11- controllerapi "github.com/docker/buildx/controller/pb"
1211 gateway "github.com/moby/buildkit/frontend/gateway/client"
1312 "github.com/pkg/errors"
1413 "github.com/sirupsen/logrus"
1514)
1615
16+ type InvokeConfig struct {
17+ Entrypoint []string
18+ Cmd []string
19+ NoCmd bool
20+ Env []string
21+ User string
22+ NoUser bool
23+ Cwd string
24+ NoCwd bool
25+ Tty bool
26+ Rollback bool
27+ Initial bool
28+ SuspendOn SuspendOn
29+ }
30+
31+ func (cfg * InvokeConfig ) NeedsDebug (err error ) bool {
32+ return cfg .SuspendOn .DebugEnabled (err )
33+ }
34+
35+ type SuspendOn int
36+
37+ const (
38+ SuspendError SuspendOn = iota
39+ SuspendAlways
40+ )
41+
42+ func (s SuspendOn ) DebugEnabled (err error ) bool {
43+ return err != nil || s == SuspendAlways
44+ }
45+
1746type Container struct {
1847 cancelOnce sync.Once
1948 containerCancel func (error )
@@ -24,7 +53,7 @@ type Container struct {
2453 resultCtx * ResultHandle
2554}
2655
27- func NewContainer (ctx context.Context , resultCtx * ResultHandle , cfg * controllerapi. InvokeConfig ) (* Container , error ) {
56+ func NewContainer (ctx context.Context , resultCtx * ResultHandle , cfg * InvokeConfig ) (* Container , error ) {
2857 mainCtx := ctx
2958
3059 ctrCh := make (chan * Container )
@@ -97,7 +126,7 @@ func (c *Container) markUnavailable() {
97126 c .isUnavailable .Store (true )
98127}
99128
100- func (c * Container ) Exec (ctx context.Context , cfg * controllerapi. InvokeConfig , stdin io.ReadCloser , stdout io.WriteCloser , stderr io.WriteCloser ) error {
129+ func (c * Container ) Exec (ctx context.Context , cfg * InvokeConfig , stdin io.ReadCloser , stdout io.WriteCloser , stderr io.WriteCloser ) error {
101130 if isInit := c .initStarted .CompareAndSwap (false , true ); isInit {
102131 defer func () {
103132 // container can't be used after init exits
@@ -112,7 +141,7 @@ func (c *Container) Exec(ctx context.Context, cfg *controllerapi.InvokeConfig, s
112141 return err
113142}
114143
115- func exec (ctx context.Context , resultCtx * ResultHandle , cfg * controllerapi. InvokeConfig , ctr gateway.Container , stdin io.ReadCloser , stdout io.WriteCloser , stderr io.WriteCloser ) error {
144+ func exec (ctx context.Context , resultCtx * ResultHandle , cfg * InvokeConfig , ctr gateway.Container , stdin io.ReadCloser , stdout io.WriteCloser , stderr io.WriteCloser ) error {
116145 processCfg , err := resultCtx .getProcessConfig (cfg , stdin , stdout , stderr )
117146 if err != nil {
118147 return err
0 commit comments