-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image delta client support with progress reporting #35
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
868fefc
pkg/ioutils: export SeekerSize utility
petrosagg 8e77735
image/delta: client support with progress reporting
petrosagg 02d889d
api: move delta creation under POST images/delta
petrosagg bd14e2f
delta: revert automatic tag generation for delta image
petrosagg 18d8604
daemon: compute and print summary of delta efficiency
petrosagg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package client | ||
|
||
import ( | ||
"io" | ||
"net/url" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
// ImageImport creates a new image based in the source options. | ||
// It returns the JSON content in the response body. | ||
func (cli *Client) ImageDelta(ctx context.Context, src, dest string) (io.ReadCloser, error) { | ||
query := url.Values{} | ||
query.Set("src", src) | ||
query.Set("dest", dest) | ||
|
||
resp, err := cli.postRaw(ctx, "/images/delta", query, nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return resp.body, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ import ( | |
"github.com/pkg/errors" | ||
|
||
"github.com/Sirupsen/logrus" | ||
"github.com/docker/distribution/reference" | ||
apierrors "github.com/docker/docker/api/errors" | ||
"github.com/docker/docker/api/types" | ||
containertypes "github.com/docker/docker/api/types/container" | ||
|
@@ -25,10 +24,13 @@ import ( | |
"github.com/docker/docker/image" | ||
"github.com/docker/docker/layer" | ||
"github.com/docker/docker/pkg/idtools" | ||
"github.com/docker/docker/pkg/ioutils" | ||
"github.com/docker/docker/pkg/progress" | ||
"github.com/docker/docker/pkg/stringid" | ||
"github.com/docker/docker/pkg/streamformatter" | ||
"github.com/docker/docker/pkg/system" | ||
"github.com/docker/docker/runconfig" | ||
"github.com/opencontainers/go-digest" | ||
units "github.com/docker/go-units" | ||
"github.com/opencontainers/selinux/go-selinux/label" | ||
"github.com/resin-os/librsync-go" | ||
) | ||
|
@@ -341,42 +343,63 @@ func (daemon *Daemon) verifyNetworkingConfig(nwConfig *networktypes.NetworkingCo | |
|
||
// DeltaCreate creates a delta of the specified src and dest images | ||
// This is called directly from the Engine API | ||
func (daemon *Daemon) DeltaCreate(deltaSrc, deltaDest string) (string, error) { | ||
func (daemon *Daemon) DeltaCreate(deltaSrc, deltaDest string, outStream io.Writer) error { | ||
progressOutput := streamformatter.NewJSONProgressOutput(outStream, false) | ||
|
||
srcImg, err := daemon.GetImage(deltaSrc) | ||
if err != nil { | ||
return "", errors.Wrapf(err, "no such image: %s", deltaSrc) | ||
return errors.Wrapf(err, "no such image: %s", deltaSrc) | ||
} | ||
|
||
dstImg, err := daemon.GetImage(deltaDest) | ||
if err != nil { | ||
return "", errors.Wrapf(err, "no such image: %s", deltaDest) | ||
return errors.Wrapf(err, "no such image: %s", deltaDest) | ||
} | ||
|
||
is := daemon.stores[dstImg.Platform()].imageStore | ||
ls := daemon.stores[dstImg.Platform()].layerStore | ||
|
||
srcData, err := is.GetTarSeekStream(srcImg.ID()) | ||
if err != nil { | ||
return "", err | ||
return err | ||
} | ||
defer srcData.Close() | ||
|
||
srcSig, err := librsync.Signature(bufio.NewReaderSize(srcData, 65536), ioutil.Discard, 512, 32, librsync.BLAKE2_SIG_MAGIC) | ||
srcDataLen, err := ioutils.SeekerSize(srcData) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
progressReader := progress.NewProgressReader(srcData, progressOutput, srcDataLen, deltaSrc, "Fingerprinting") | ||
defer progressReader.Close() | ||
|
||
srcSig, err := librsync.Signature(bufio.NewReaderSize(progressReader, 65536), ioutil.Discard, 512, 32, librsync.BLAKE2_SIG_MAGIC) | ||
if err != nil { | ||
return "", err | ||
return err | ||
} | ||
|
||
progress.Update(progressOutput, deltaSrc, "Fingerprint complete") | ||
|
||
deltaRootFS := image.NewRootFS() | ||
|
||
for _, diffID := range dstImg.RootFS.DiffIDs { | ||
progress.Update(progressOutput, stringid.TruncateID(diffID.String()), "Waiting") | ||
} | ||
|
||
statTotalSize := int64(0) | ||
statDetlaSize := int64(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: detla |
||
|
||
for i, diffID := range dstImg.RootFS.DiffIDs { | ||
var ( | ||
layerData io.Reader | ||
platform layer.Platform | ||
) | ||
commonLayer := false | ||
|
||
// We're only interested in layers that are different. Push empty | ||
// layers for common layers | ||
if i < len(srcImg.RootFS.DiffIDs) && srcImg.RootFS.DiffIDs[i] == diffID { | ||
commonLayer = true | ||
layerData, _ = layer.EmptyLayer.TarStream() | ||
platform = layer.EmptyLayer.Platform() | ||
} else { | ||
|
@@ -385,31 +408,41 @@ func (daemon *Daemon) DeltaCreate(deltaSrc, deltaDest string) (string, error) { | |
|
||
l, err := ls.Get(dstRootFS.ChainID()) | ||
if err != nil { | ||
return "", err | ||
return err | ||
} | ||
defer layer.ReleaseAndLog(ls, l) | ||
|
||
platform = l.Platform() | ||
|
||
input, err := l.TarStream() | ||
if err != nil { | ||
return "", err | ||
return err | ||
} | ||
defer input.Close() | ||
|
||
inputSize, err := l.DiffSize() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
statTotalSize += inputSize | ||
|
||
progressReader := progress.NewProgressReader(input, progressOutput, inputSize, stringid.TruncateID(diffID.String()), "Computing delta") | ||
defer progressReader.Close() | ||
|
||
pR, pW := io.Pipe() | ||
|
||
layerData = pR | ||
|
||
tmpDelta, err := ioutil.TempFile("", "docker-delta-") | ||
if err != nil { | ||
return "", err | ||
return err | ||
} | ||
defer os.Remove(tmpDelta.Name()) | ||
|
||
go func() { | ||
w := bufio.NewWriter(tmpDelta) | ||
err := librsync.Delta(srcSig, bufio.NewReader(input), w) | ||
err := librsync.Delta(srcSig, bufio.NewReader(progressReader), w) | ||
if err != nil { | ||
pW.CloseWithError(err) | ||
return | ||
|
@@ -456,10 +489,21 @@ func (daemon *Daemon) DeltaCreate(deltaSrc, deltaDest string) (string, error) { | |
|
||
newLayer, err := ls.Register(layerData, deltaRootFS.ChainID(), platform) | ||
if err != nil { | ||
return "", err | ||
return err | ||
} | ||
defer layer.ReleaseAndLog(ls, newLayer) | ||
|
||
if commonLayer { | ||
progress.Update(progressOutput, stringid.TruncateID(diffID.String()), "Skipping common layer") | ||
} else { | ||
deltaSize, err := newLayer.DiffSize() | ||
if err != nil { | ||
return err | ||
} | ||
statDetlaSize += deltaSize | ||
progress.Update(progressOutput, stringid.TruncateID(diffID.String()), "Delta complete") | ||
} | ||
|
||
deltaRootFS.Append(newLayer.DiffID()) | ||
} | ||
|
||
|
@@ -478,23 +522,22 @@ func (daemon *Daemon) DeltaCreate(deltaSrc, deltaDest string) (string, error) { | |
|
||
rawConfig, err := json.Marshal(config) | ||
if err != nil { | ||
return "", err | ||
return err | ||
} | ||
|
||
id, err := is.Create(rawConfig) | ||
if err != nil { | ||
return "", err | ||
return err | ||
} | ||
|
||
ref, _ := reference.WithName("delta") | ||
|
||
deltaTag := "delta-" + digest.FromString(srcImg.ID().String() + "-" + dstImg.ImageID()).Hex()[:8] | ||
|
||
ref2, _ := reference.WithTag(ref, deltaTag) | ||
|
||
if err := daemon.TagImageWithReference(id, "linux", ref2); err != nil { | ||
return "", err | ||
humanTotal := units.HumanSize(float64(statTotalSize)) | ||
humanDelta := units.HumanSize(float64(statDetlaSize)) | ||
deltaRatio := float64(statTotalSize) / float64(statDetlaSize) | ||
if statTotalSize == 0 { | ||
deltaRatio = 1 | ||
} | ||
|
||
return id.String(), nil | ||
outStream.Write(streamformatter.FormatStatus("", "Normal size: %s, Delta size: %s, %.2fx improvement", humanTotal, humanDelta, deltaRatio)) | ||
outStream.Write(streamformatter.FormatStatus("", "Created delta: %s", id.String())) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
/images/delta
? Either that orclient/image_delta.go:17
is correct, can't be both :P