...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package daemon
16
17 import (
18 "context"
19 "io"
20
21 "github.com/docker/docker/api/types"
22 api "github.com/docker/docker/api/types/image"
23 "github.com/docker/docker/client"
24 )
25
26
27
28 type ImageOption Option
29
30
31 type Option func(*options)
32
33 type options struct {
34 ctx context.Context
35 client Client
36 buffered bool
37 }
38
39 var defaultClient = func() (Client, error) {
40 return client.NewClientWithOpts(client.FromEnv)
41 }
42
43 func makeOptions(opts ...Option) (*options, error) {
44 o := &options{
45 buffered: true,
46 ctx: context.Background(),
47 }
48 for _, opt := range opts {
49 opt(o)
50 }
51
52 if o.client == nil {
53 client, err := defaultClient()
54 if err != nil {
55 return nil, err
56 }
57 o.client = client
58 }
59 o.client.NegotiateAPIVersion(o.ctx)
60
61 return o, nil
62 }
63
64
65 func WithBufferedOpener() Option {
66 return func(o *options) {
67 o.buffered = true
68 }
69 }
70
71
72 func WithUnbufferedOpener() Option {
73 return func(o *options) {
74 o.buffered = false
75 }
76 }
77
78
79
80
81 func WithClient(client Client) Option {
82 return func(o *options) {
83 o.client = client
84 }
85 }
86
87
88
89
90 func WithContext(ctx context.Context) Option {
91 return func(o *options) {
92 o.ctx = ctx
93 }
94 }
95
96
97
98 type Client interface {
99 NegotiateAPIVersion(ctx context.Context)
100 ImageSave(context.Context, []string) (io.ReadCloser, error)
101 ImageLoad(context.Context, io.Reader, bool) (types.ImageLoadResponse, error)
102 ImageTag(context.Context, string, string) error
103 ImageInspectWithRaw(context.Context, string) (types.ImageInspect, []byte, error)
104 ImageHistory(context.Context, string) ([]api.HistoryResponseItem, error)
105 }
106
View as plain text