9 "github.com/docker/distribution"
10 "github.com/docker/distribution/manifest/schema2"
11 "github.com/docker/docker/api/types"
12 "github.com/docker/docker/distribution/metadata"
13 "github.com/docker/docker/distribution/xfer"
14 "github.com/docker/docker/image"
15 "github.com/docker/docker/layer"
16 "github.com/docker/docker/pkg/ioutils"
17 "github.com/docker/docker/pkg/progress"
18 "github.com/docker/docker/pkg/system"
19 refstore "github.com/docker/docker/reference"
20 "github.com/docker/docker/registry"
21 "github.com/docker/libtrust"
22 "github.com/opencontainers/go-digest"
23 "golang.org/x/net/context"
26 // Config stores configuration for communicating
29 // MetaHeaders stores HTTP headers with metadata about the image
30 MetaHeaders map[string][]string
31 // AuthConfig holds authentication credentials for authenticating with
33 AuthConfig *types.AuthConfig
34 // ProgressOutput is the interface for showing the status of the pull
36 ProgressOutput progress.Output
37 // RegistryService is the registry service to use for TLS configuration
38 // and endpoint lookup.
39 RegistryService registry.Service
40 // ImageEventLogger notifies events for a given image
41 ImageEventLogger func(id, name, action string)
42 // MetadataStore is the storage backend for distribution-specific
44 MetadataStore metadata.Store
45 // ImageStore manages images.
46 ImageStore ImageConfigStore
47 // ReferenceStore manages tags. This value is optional, when excluded
48 // content will not be tagged.
49 ReferenceStore refstore.Store
50 // RequireSchema2 ensures that only schema2 manifests are used.
54 // ImagePullConfig stores pull configuration.
55 type ImagePullConfig struct {
58 // DownloadManager manages concurrent pulls.
59 DownloadManager RootFSDownloadManager
60 // Schema2Types is the valid schema2 configuration types allowed
61 // by the pull operation.
63 // Platform is the requested platform of the image being pulled to ensure it can be validated
64 // when the host platform supports multiple image operating systems.
68 // ImagePushConfig stores push configuration.
69 type ImagePushConfig struct {
72 // ConfigMediaType is the configuration media type for
74 ConfigMediaType string
75 // LayerStore manages layers.
76 LayerStore PushLayerProvider
77 // TrustKey is the private key for legacy signatures. This is typically
78 // an ephemeral key, since these signatures are no longer verified.
79 TrustKey libtrust.PrivateKey
80 // UploadManager dispatches uploads.
81 UploadManager *xfer.LayerUploadManager
84 // ImageConfigStore handles storing and getting image configurations
85 // by digest. Allows getting an image configurations rootfs from the
87 type ImageConfigStore interface {
88 Put([]byte) (digest.Digest, error)
89 Get(digest.Digest) ([]byte, error)
90 GetTarSeekStream(digest.Digest) (ioutils.ReadSeekCloser, error)
91 RootFSAndPlatformFromConfig([]byte) (*image.RootFS, layer.Platform, error)
94 // PushLayerProvider provides layers to be pushed by ChainID.
95 type PushLayerProvider interface {
96 Get(layer.ChainID) (PushLayer, error)
99 // PushLayer is a pushable layer with metadata about the layer
100 // and access to the content of the layer.
101 type PushLayer interface {
102 ChainID() layer.ChainID
103 DiffID() layer.DiffID
105 Open() (io.ReadCloser, error)
106 Size() (int64, error)
111 // RootFSDownloadManager handles downloading of the rootfs
112 type RootFSDownloadManager interface {
113 // Download downloads the layers into the given initial rootfs and
114 // returns the final rootfs.
115 // Given progress output to track download progress
116 // Returns function to release download resources
117 Download(ctx context.Context, initialRootFS image.RootFS, platform layer.Platform, layers []xfer.DownloadDescriptor, progressOutput progress.Output) (image.RootFS, func(), error)
120 type imageConfigStore struct {
122 deltaStore image.Store
125 // NewImageConfigStoreFromStore returns an ImageConfigStore backed
126 // by an image.Store for container images.
127 func NewImageConfigStoreFromStore(is, deltaImageStore image.Store) ImageConfigStore {
128 return &imageConfigStore{
130 deltaStore: deltaImageStore,
134 func (s *imageConfigStore) Put(c []byte) (digest.Digest, error) {
135 id, err := s.Store.Create(c)
136 return digest.Digest(id), err
139 func (s *imageConfigStore) Get(d digest.Digest) ([]byte, error) {
140 img, err := s.Store.Get(image.IDFromDigest(d))
144 return img.RawJSON(), nil
147 func (s *imageConfigStore) GetTarSeekStream(d digest.Digest) (ioutils.ReadSeekCloser, error) {
148 stream, err := s.Store.GetTarSeekStream(image.IDFromDigest(d))
149 if err != nil && s.deltaStore != nil {
150 return s.deltaStore.GetTarSeekStream(image.IDFromDigest(d))
155 func (s *imageConfigStore) RootFSAndPlatformFromConfig(c []byte) (*image.RootFS, layer.Platform, error) {
156 var unmarshalledConfig image.Image
157 if err := json.Unmarshal(c, &unmarshalledConfig); err != nil {
161 // fail immediately on Windows when downloading a non-Windows image
162 // and vice versa. Exception on Windows if Linux Containers are enabled.
163 if runtime.GOOS == "windows" && unmarshalledConfig.OS == "linux" && !system.LCOWSupported() {
164 return nil, "", fmt.Errorf("image operating system %q cannot be used on this platform", unmarshalledConfig.OS)
165 } else if runtime.GOOS != "windows" && unmarshalledConfig.OS == "windows" {
166 return nil, "", fmt.Errorf("image operating system %q cannot be used on this platform", unmarshalledConfig.OS)
170 if runtime.GOOS == "windows" {
171 platform = unmarshalledConfig.OS
173 return unmarshalledConfig.RootFS, layer.Platform(platform), nil
176 type storeLayerProvider struct {
180 // NewLayerProviderFromStore returns a layer provider backed by
181 // an instance of LayerStore. Only getting layers as gzipped
182 // tars is supported.
183 func NewLayerProviderFromStore(ls layer.Store) PushLayerProvider {
184 return &storeLayerProvider{
189 func (p *storeLayerProvider) Get(lid layer.ChainID) (PushLayer, error) {
192 Layer: layer.EmptyLayer,
195 l, err := p.ls.Get(lid)
204 if d, ok := l.(distribution.Describable); ok {
205 return &describableStoreLayer{
214 type storeLayer struct {
219 func (l *storeLayer) Parent() PushLayer {
220 p := l.Layer.Parent()
228 if d, ok := p.(distribution.Describable); ok {
229 return &describableStoreLayer{
238 func (l *storeLayer) Open() (io.ReadCloser, error) {
239 return l.Layer.TarStream()
242 func (l *storeLayer) Size() (int64, error) {
243 return l.Layer.DiffSize()
246 func (l *storeLayer) MediaType() string {
247 // layer store always returns uncompressed tars
248 return schema2.MediaTypeUncompressedLayer
251 func (l *storeLayer) Release() {
253 layer.ReleaseAndLog(l.ls, l.Layer)
257 type describableStoreLayer struct {
259 describable distribution.Describable
262 func (l *describableStoreLayer) Descriptor() distribution.Descriptor {
263 return l.describable.Descriptor()