-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transfer.go
56 lines (45 loc) · 1.15 KB
/
Transfer.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
package container
import (
"context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"io"
"os"
)
func (container *Container) CopyFromContainer(pathContainer string, pathHost string) error {
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
defer cli.Close()
reader, _, err := cli.CopyFromContainer(ctx, container.Runtime.Id, pathContainer)
if err != nil {
panic(err)
}
container.Exports.path = pathHost
writer, err := os.Create(container.Exports.path)
if err != nil {
panic(err)
}
defer writer.Close()
defer reader.Close()
_, err = io.Copy(writer, reader)
if err != nil {
panic(err)
}
return err
}
func (container *Container) CopyToContainer(reader io.Reader, pathContainer string) error {
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
defer cli.Close()
err = cli.CopyToContainer(ctx, container.Runtime.Id, pathContainer, reader, types.CopyToContainerOptions{})
if err != nil {
panic(err)
}
return err
}