-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunnable.go
60 lines (49 loc) · 978 Bytes
/
runnable.go
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
package forge
import (
"context"
"github.com/google/uuid"
)
func runOptsWithDefaults(opts ...RunOpt) *RunOpts {
o := &RunOpts{
WorkingDir: "/" + uuid.NewString(),
}
for _, opt := range opts {
opt.Apply(o)
}
return o
}
type RunOpts struct {
Streams *Streams
Mounts []Mount
InterceptDockerSock bool
WorkingDir string
}
func (o *RunOpts) Apply(opts *RunOpts) {
if opts == nil {
opts = &RunOpts{}
}
if o.Streams != nil {
opts.Streams = o.Streams
}
opts.Mounts = overrideMounts(opts.Mounts, o.Mounts...)
if o.InterceptDockerSock {
opts.InterceptDockerSock = true
}
if o.WorkingDir != "" {
opts.WorkingDir = o.WorkingDir
}
}
func WithStreams(streams *Streams) RunOpt {
return &RunOpts{
Streams: streams,
}
}
func WithStdStreams() RunOpt {
return WithStreams(StdStreams())
}
type RunOpt interface {
Apply(*RunOpts)
}
type Runnable interface {
Run(context.Context, ContainerRuntime, ...RunOpt) error
}