|
@@ -14,11 +14,24 @@ import (
|
|
|
"github.com/docker/docker/layer"
|
|
|
"github.com/docker/docker/pkg/archive"
|
|
|
"github.com/docker/docker/pkg/chrootarchive"
|
|
|
+ "github.com/docker/docker/pkg/progress"
|
|
|
+ "github.com/docker/docker/pkg/streamformatter"
|
|
|
+ "github.com/docker/docker/pkg/stringid"
|
|
|
"github.com/docker/docker/pkg/symlink"
|
|
|
"github.com/docker/docker/reference"
|
|
|
)
|
|
|
|
|
|
-func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer) error {
|
|
|
+func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool) error {
|
|
|
+ var (
|
|
|
+ sf = streamformatter.NewJSONStreamFormatter()
|
|
|
+ progressOutput progress.Output
|
|
|
+ )
|
|
|
+ if !quiet {
|
|
|
+ progressOutput = sf.NewProgressOutput(outStream, false)
|
|
|
+ } else {
|
|
|
+ progressOutput = nil
|
|
|
+ }
|
|
|
+
|
|
|
tmpDir, err := ioutil.TempDir("", "docker-import-")
|
|
|
if err != nil {
|
|
|
return err
|
|
@@ -36,7 +49,7 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer) error {
|
|
|
manifestFile, err := os.Open(manifestPath)
|
|
|
if err != nil {
|
|
|
if os.IsNotExist(err) {
|
|
|
- return l.legacyLoad(tmpDir, outStream)
|
|
|
+ return l.legacyLoad(tmpDir, outStream, progressOutput)
|
|
|
}
|
|
|
return manifestFile.Close()
|
|
|
}
|
|
@@ -77,7 +90,7 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer) error {
|
|
|
r.Append(diffID)
|
|
|
newLayer, err := l.ls.Get(r.ChainID())
|
|
|
if err != nil {
|
|
|
- newLayer, err = l.loadLayer(layerPath, rootFS)
|
|
|
+ newLayer, err = l.loadLayer(layerPath, rootFS, diffID.String(), progressOutput)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -111,7 +124,7 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (l *tarexporter) loadLayer(filename string, rootFS image.RootFS) (layer.Layer, error) {
|
|
|
+func (l *tarexporter) loadLayer(filename string, rootFS image.RootFS, id string, progressOutput progress.Output) (layer.Layer, error) {
|
|
|
rawTar, err := os.Open(filename)
|
|
|
if err != nil {
|
|
|
logrus.Debugf("Error reading embedded tar: %v", err)
|
|
@@ -125,6 +138,17 @@ func (l *tarexporter) loadLayer(filename string, rootFS image.RootFS) (layer.Lay
|
|
|
}
|
|
|
defer inflatedLayerData.Close()
|
|
|
|
|
|
+ if progressOutput != nil {
|
|
|
+ fileInfo, err := os.Stat(filename)
|
|
|
+ if err != nil {
|
|
|
+ logrus.Debugf("Error statting file: %v", err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ progressReader := progress.NewProgressReader(inflatedLayerData, progressOutput, fileInfo.Size(), stringid.TruncateID(id), "Loading layer")
|
|
|
+
|
|
|
+ return l.ls.Register(progressReader, rootFS.ChainID())
|
|
|
+ }
|
|
|
return l.ls.Register(inflatedLayerData, rootFS.ChainID())
|
|
|
}
|
|
|
|
|
@@ -139,7 +163,7 @@ func (l *tarexporter) setLoadedTag(ref reference.NamedTagged, imgID image.ID, ou
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (l *tarexporter) legacyLoad(tmpDir string, outStream io.Writer) error {
|
|
|
+func (l *tarexporter) legacyLoad(tmpDir string, outStream io.Writer, progressOutput progress.Output) error {
|
|
|
legacyLoadedMap := make(map[string]image.ID)
|
|
|
|
|
|
dirs, err := ioutil.ReadDir(tmpDir)
|
|
@@ -150,7 +174,7 @@ func (l *tarexporter) legacyLoad(tmpDir string, outStream io.Writer) error {
|
|
|
// every dir represents an image
|
|
|
for _, d := range dirs {
|
|
|
if d.IsDir() {
|
|
|
- if err := l.legacyLoadImage(d.Name(), tmpDir, legacyLoadedMap); err != nil {
|
|
|
+ if err := l.legacyLoadImage(d.Name(), tmpDir, legacyLoadedMap, progressOutput); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
@@ -196,7 +220,7 @@ func (l *tarexporter) legacyLoad(tmpDir string, outStream io.Writer) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (l *tarexporter) legacyLoadImage(oldID, sourceDir string, loadedMap map[string]image.ID) error {
|
|
|
+func (l *tarexporter) legacyLoadImage(oldID, sourceDir string, loadedMap map[string]image.ID, progressOutput progress.Output) error {
|
|
|
if _, loaded := loadedMap[oldID]; loaded {
|
|
|
return nil
|
|
|
}
|
|
@@ -220,7 +244,7 @@ func (l *tarexporter) legacyLoadImage(oldID, sourceDir string, loadedMap map[str
|
|
|
for {
|
|
|
var loaded bool
|
|
|
if parentID, loaded = loadedMap[img.Parent]; !loaded {
|
|
|
- if err := l.legacyLoadImage(img.Parent, sourceDir, loadedMap); err != nil {
|
|
|
+ if err := l.legacyLoadImage(img.Parent, sourceDir, loadedMap, progressOutput); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
} else {
|
|
@@ -247,7 +271,7 @@ func (l *tarexporter) legacyLoadImage(oldID, sourceDir string, loadedMap map[str
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- newLayer, err := l.loadLayer(layerPath, *rootFS)
|
|
|
+ newLayer, err := l.loadLayer(layerPath, *rootFS, oldID, progressOutput)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|