-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpipe.go
44 lines (38 loc) · 853 Bytes
/
pipe.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
package forge
import (
"context"
"io"
)
type Pipe struct {
From Runnable
To Runnable
}
func (o *Pipe) Run(ctx context.Context, containerRuntime ContainerRuntime, opts ...RunOpt) (err error) {
var (
opt = runOptsWithDefaults(opts...)
pr, pw = io.Pipe()
)
go func() {
defer pw.Close()
_ = pw.CloseWithError(o.From.Run(ctx, containerRuntime, &RunOpts{
Mounts: opt.Mounts,
Streams: &Streams{
Out: pw,
In: opt.Streams.In,
Err: opt.Streams.Err,
Tty: opt.Streams.Tty,
DetachKeys: opt.Streams.DetachKeys,
},
}))
}()
return o.To.Run(ctx, containerRuntime, &RunOpts{
Mounts: opt.Mounts,
Streams: &Streams{
Out: opt.Streams.Out,
In: pr,
Err: opt.Streams.Err,
Tty: opt.Streams.Tty,
DetachKeys: opt.Streams.DetachKeys,
},
})
}