2017-11-21 08:08:36 +00:00
|
|
|
package executor
|
|
|
|
|
|
|
|
import (
|
2018-01-16 22:30:10 +00:00
|
|
|
"context"
|
2020-07-30 23:44:42 +00:00
|
|
|
"fmt"
|
2017-11-21 08:08:36 +00:00
|
|
|
"io"
|
2018-08-01 21:15:43 +00:00
|
|
|
"net"
|
2017-11-21 08:08:36 +00:00
|
|
|
|
|
|
|
"github.com/moby/buildkit/cache"
|
2018-08-04 19:42:01 +00:00
|
|
|
"github.com/moby/buildkit/solver/pb"
|
2017-11-21 08:08:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Meta struct {
|
2018-03-26 13:51:08 +00:00
|
|
|
Args []string
|
|
|
|
Env []string
|
|
|
|
User string
|
|
|
|
Cwd string
|
|
|
|
Tty bool
|
|
|
|
ReadonlyRootFS bool
|
2018-08-04 19:42:01 +00:00
|
|
|
ExtraHosts []HostIP
|
|
|
|
NetMode pb.NetMode
|
2019-01-10 02:24:25 +00:00
|
|
|
SecurityMode pb.SecurityMode
|
2017-11-21 08:08:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Mount struct {
|
|
|
|
Src cache.Mountable
|
|
|
|
Selector string
|
|
|
|
Dest string
|
|
|
|
Readonly bool
|
|
|
|
}
|
|
|
|
|
2020-07-30 23:44:42 +00:00
|
|
|
type WinSize struct {
|
|
|
|
Rows uint32
|
|
|
|
Cols uint32
|
|
|
|
Xpixel uint32
|
|
|
|
Ypixel uint32
|
|
|
|
}
|
|
|
|
|
2020-07-09 23:07:28 +00:00
|
|
|
type ProcessInfo struct {
|
|
|
|
Meta Meta
|
|
|
|
Stdin io.ReadCloser
|
|
|
|
Stdout, Stderr io.WriteCloser
|
2020-07-30 23:44:42 +00:00
|
|
|
Resize <-chan WinSize
|
2020-07-09 23:07:28 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 08:08:36 +00:00
|
|
|
type Executor interface {
|
2020-07-13 20:16:05 +00:00
|
|
|
// Run will start a container for the given process with rootfs, mounts.
|
|
|
|
// `id` is an optional name for the container so it can be referenced later via Exec.
|
|
|
|
// `started` is an optional channel that will be closed when the container setup completes and has started running.
|
2020-07-10 22:05:30 +00:00
|
|
|
Run(ctx context.Context, id string, rootfs cache.Mountable, mounts []Mount, process ProcessInfo, started chan<- struct{}) error
|
2020-07-13 20:16:05 +00:00
|
|
|
// Exec will start a process in container matching `id`. An error will be returned
|
|
|
|
// if the container failed to start (via Run) or has exited before Exec is called.
|
2020-07-09 23:07:28 +00:00
|
|
|
Exec(ctx context.Context, id string, process ProcessInfo) error
|
2017-11-21 08:08:36 +00:00
|
|
|
}
|
2018-08-01 21:15:43 +00:00
|
|
|
|
|
|
|
type HostIP struct {
|
|
|
|
Host string
|
|
|
|
IP net.IP
|
|
|
|
}
|
2020-07-30 23:44:42 +00:00
|
|
|
|
|
|
|
// ExitError will be returned from Run and Exec when the container process exits with
|
|
|
|
// a non-zero exit code.
|
|
|
|
type ExitError struct {
|
|
|
|
ExitCode uint32
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *ExitError) Error() string {
|
|
|
|
if err.Err != nil {
|
|
|
|
return err.Err.Error()
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("exit code: %d", err.ExitCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *ExitError) Unwrap() error {
|
|
|
|
if err.Err == nil {
|
|
|
|
return fmt.Errorf("exit code: %d", err.ExitCode)
|
|
|
|
}
|
|
|
|
return err.Err
|
|
|
|
}
|