File: client.go

package info (click to toggle)
singularity-container 4.1.5%2Bds4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 43,876 kB
  • sloc: asm: 14,840; sh: 3,190; ansic: 1,751; awk: 414; makefile: 413; python: 99
file content (165 lines) | stat: -rw-r--r-- 4,133 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package client

import (
	"context"
	"io"
	"syscall"

	"github.com/moby/buildkit/client/llb"
	"github.com/moby/buildkit/client/llb/sourceresolver"
	"github.com/moby/buildkit/solver/pb"
	"github.com/moby/buildkit/solver/result"
	spb "github.com/moby/buildkit/sourcepolicy/pb"
	"github.com/moby/buildkit/util/apicaps"
	digest "github.com/opencontainers/go-digest"
	ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
	fstypes "github.com/tonistiigi/fsutil/types"
)

type Result = result.Result[Reference]

type Attestation = result.Attestation[Reference]

type BuildFunc func(context.Context, Client) (*Result, error)

func NewResult() *Result {
	return &Result{}
}

type Client interface {
	sourceresolver.MetaResolver
	Solve(ctx context.Context, req SolveRequest) (*Result, error)
	ResolveImageConfig(ctx context.Context, ref string, opt sourceresolver.Opt) (string, digest.Digest, []byte, error)
	BuildOpts() BuildOpts
	Inputs(ctx context.Context) (map[string]llb.State, error)
	NewContainer(ctx context.Context, req NewContainerRequest) (Container, error)
	Warn(ctx context.Context, dgst digest.Digest, msg string, opts WarnOpts) error
}

// NewContainerRequest encapsulates the requirements for a client to define a
// new container, without defining the initial process.
type NewContainerRequest struct {
	Mounts      []Mount
	Hostname    string
	NetMode     pb.NetMode
	ExtraHosts  []*pb.HostIP
	Platform    *pb.Platform
	Constraints *pb.WorkerConstraints
}

// Mount allows clients to specify a filesystem mount. A Reference to a
// previously solved Result is required.
type Mount struct {
	Selector  string
	Dest      string
	ResultID  string
	Ref       Reference
	Readonly  bool
	MountType pb.MountType
	CacheOpt  *pb.CacheOpt
	SecretOpt *pb.SecretOpt
	SSHOpt    *pb.SSHOpt
}

// Container is used to start new processes inside a container and release the
// container resources when done.
type Container interface {
	Start(context.Context, StartRequest) (ContainerProcess, error)
	Release(context.Context) error
}

// StartRequest encapsulates the arguments to define a process within a
// container.
type StartRequest struct {
	Args           []string
	Env            []string
	SecretEnv      []*pb.SecretEnv
	User           string
	Cwd            string
	Tty            bool
	Stdin          io.ReadCloser
	Stdout, Stderr io.WriteCloser
	SecurityMode   pb.SecurityMode

	RemoveMountStubsRecursive bool
}

// WinSize is same as executor.WinSize, copied here to prevent circular package
// dependencies.
type WinSize struct {
	Rows uint32
	Cols uint32
}

// ContainerProcess represents a process within a container.
type ContainerProcess interface {
	Wait() error
	Resize(ctx context.Context, size WinSize) error
	Signal(ctx context.Context, sig syscall.Signal) error
}

type Reference interface {
	ToState() (llb.State, error)
	Evaluate(ctx context.Context) error
	ReadFile(ctx context.Context, req ReadRequest) ([]byte, error)
	StatFile(ctx context.Context, req StatRequest) (*fstypes.Stat, error)
	ReadDir(ctx context.Context, req ReadDirRequest) ([]*fstypes.Stat, error)
}

type ReadRequest struct {
	Filename string
	Range    *FileRange
}

type FileRange struct {
	Offset int
	Length int
}

type ReadDirRequest struct {
	Path           string
	IncludePattern string
}

type StatRequest struct {
	Path string
}

// SolveRequest is same as frontend.SolveRequest but avoiding dependency
type SolveRequest struct {
	Evaluate       bool
	Definition     *pb.Definition
	Frontend       string
	FrontendOpt    map[string]string
	FrontendInputs map[string]*pb.Definition
	CacheImports   []CacheOptionsEntry
	SourcePolicies []*spb.Policy
}

type CacheOptionsEntry struct {
	Type  string
	Attrs map[string]string
}

type WorkerInfo struct {
	ID        string
	Labels    map[string]string
	Platforms []ocispecs.Platform
}

type BuildOpts struct {
	Opts      map[string]string
	SessionID string
	Workers   []WorkerInfo
	Product   string
	LLBCaps   apicaps.CapSet
	Caps      apicaps.CapSet
}

type WarnOpts struct {
	Level      int
	SourceInfo *pb.SourceInfo
	Range      []*pb.Range
	Detail     [][]byte
	URL        string
}