1package client
2
3import (
4	"context"
5	"io"
6
7	"github.com/moby/buildkit/client/llb"
8	"github.com/moby/buildkit/solver/pb"
9	"github.com/moby/buildkit/util/apicaps"
10	digest "github.com/opencontainers/go-digest"
11	specs "github.com/opencontainers/image-spec/specs-go/v1"
12	fstypes "github.com/tonistiigi/fsutil/types"
13)
14
15type Client interface {
16	Solve(ctx context.Context, req SolveRequest) (*Result, error)
17	ResolveImageConfig(ctx context.Context, ref string, opt llb.ResolveImageConfigOpt) (digest.Digest, []byte, error)
18	BuildOpts() BuildOpts
19	Inputs(ctx context.Context) (map[string]llb.State, error)
20	NewContainer(ctx context.Context, req NewContainerRequest) (Container, error)
21}
22
23// NewContainerRequest encapsulates the requirements for a client to define a
24// new container, without defining the initial process.
25type NewContainerRequest struct {
26	Mounts      []Mount
27	NetMode     pb.NetMode
28	Platform    *pb.Platform
29	Constraints *pb.WorkerConstraints
30}
31
32// Mount allows clients to specify a filesystem mount. A Reference to a
33// previously solved Result is required.
34type Mount struct {
35	Selector  string
36	Dest      string
37	ResultID  string
38	Ref       Reference
39	Readonly  bool
40	MountType pb.MountType
41	CacheOpt  *pb.CacheOpt
42	SecretOpt *pb.SecretOpt
43	SSHOpt    *pb.SSHOpt
44}
45
46// Container is used to start new processes inside a container and release the
47// container resources when done.
48type Container interface {
49	Start(context.Context, StartRequest) (ContainerProcess, error)
50	Release(context.Context) error
51}
52
53// StartRequest encapsulates the arguments to define a process within a
54// container.
55type StartRequest struct {
56	Args           []string
57	Env            []string
58	User           string
59	Cwd            string
60	Tty            bool
61	Stdin          io.ReadCloser
62	Stdout, Stderr io.WriteCloser
63	SecurityMode   pb.SecurityMode
64}
65
66// WinSize is same as executor.WinSize, copied here to prevent circular package
67// dependencies.
68type WinSize struct {
69	Rows uint32
70	Cols uint32
71}
72
73// ContainerProcess represents a process within a container.
74type ContainerProcess interface {
75	Wait() error
76	Resize(ctx context.Context, size WinSize) error
77	// TODO Signal(ctx context.Context, sig os.Signal)
78}
79
80type Reference interface {
81	ToState() (llb.State, error)
82	ReadFile(ctx context.Context, req ReadRequest) ([]byte, error)
83	StatFile(ctx context.Context, req StatRequest) (*fstypes.Stat, error)
84	ReadDir(ctx context.Context, req ReadDirRequest) ([]*fstypes.Stat, error)
85}
86
87type ReadRequest struct {
88	Filename string
89	Range    *FileRange
90}
91
92type FileRange struct {
93	Offset int
94	Length int
95}
96
97type ReadDirRequest struct {
98	Path           string
99	IncludePattern string
100}
101
102type StatRequest struct {
103	Path string
104}
105
106// SolveRequest is same as frontend.SolveRequest but avoiding dependency
107type SolveRequest struct {
108	Evaluate       bool
109	Definition     *pb.Definition
110	Frontend       string
111	FrontendOpt    map[string]string
112	FrontendInputs map[string]*pb.Definition
113	CacheImports   []CacheOptionsEntry
114}
115
116type CacheOptionsEntry struct {
117	Type  string
118	Attrs map[string]string
119}
120
121type WorkerInfo struct {
122	ID        string
123	Labels    map[string]string
124	Platforms []specs.Platform
125}
126
127type BuildOpts struct {
128	Opts      map[string]string
129	SessionID string
130	Workers   []WorkerInfo
131	Product   string
132	LLBCaps   apicaps.CapSet
133	Caps      apicaps.CapSet
134}
135