Debian Codegraph @

buildkit/frontend/gateway/client/client.go

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