summaryrefslogtreecommitdiff
path: root/daemon/images/image_exporter.go
blob: 88877b01c6b2179c8400af8fe7e08ec1a929c2e8 (plain)
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
package images // import "github.com/docker/docker/daemon/images"

import (
	"context"
	"io"

	"github.com/docker/docker/container"
	"github.com/docker/docker/image/tarexport"
	"github.com/sirupsen/logrus"
)

// ExportImage exports a list of images to the given output stream. The
// exported images are archived into a tar when written to the output
// stream. All images with the given tag and all versions containing
// the same tag are exported. names is the set of tags to export, and
// outStream is the writer which the images are written to.
func (i *ImageService) ExportImage(ctx context.Context, names []string, outStream io.Writer) error {
	imageExporter := tarexport.NewTarExporter(i.imageStore, i.layerStore, i.referenceStore, i)
	return imageExporter.Save(names, outStream)
}

func (i *ImageService) PerformWithBaseFS(ctx context.Context, c *container.Container, fn func(root string) error) error {
	rwlayer, err := i.layerStore.GetRWLayer(c.ID)
	if err != nil {
		return err
	}
	defer func() {
		if err != nil {
			err2 := i.ReleaseLayer(rwlayer)
			if err2 != nil {
				logrus.WithError(err2).WithField("container", c.ID).Warn("Failed to release layer")
			}
		}
	}()

	basefs, err := rwlayer.Mount(c.GetMountLabel())
	if err != nil {
		return err
	}

	return fn(basefs)
}

// LoadImage uploads a set of images into the repository. This is the
// complement of ExportImage.  The input stream is an uncompressed tar
// ball containing images and metadata.
func (i *ImageService) LoadImage(ctx context.Context, inTar io.ReadCloser, outStream io.Writer, quiet bool) error {
	imageExporter := tarexport.NewTarExporter(i.imageStore, i.layerStore, i.referenceStore, i)
	return imageExporter.Load(inTar, outStream, quiet)
}