-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement incremental file sync using client session
Also exposes shared cache and garbage collection/prune for the source data. Signed-off-by: Tonis Tiigi <[email protected]>
- Loading branch information
1 parent
7cfcf74
commit 5c3d2d5
Showing
42 changed files
with
2,872 additions
and
185 deletions.
There are no files selected for viewing
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
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,78 @@ | ||
package dockerfile | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/docker/docker/builder/fscache" | ||
"github.com/docker/docker/builder/remotecontext" | ||
"github.com/docker/docker/client/session" | ||
"github.com/docker/docker/client/session/filesync" | ||
"github.com/pkg/errors" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
const sessionConnectTimeout = 5 * time.Second | ||
|
||
// ClientSessionTransport is a transport for copying files from docker client | ||
// to the daemon. | ||
type ClientSessionTransport struct{} | ||
|
||
// NewClientSessionTransport returns new ClientSessionTransport instance | ||
func NewClientSessionTransport() *ClientSessionTransport { | ||
return &ClientSessionTransport{} | ||
} | ||
|
||
// Copy data from a remote to a destination directory. | ||
func (cst *ClientSessionTransport) Copy(ctx context.Context, id fscache.RemoteIdentifier, dest string, cu filesync.CacheUpdater) error { | ||
csi, ok := id.(*ClientSessionSourceIdentifier) | ||
if !ok { | ||
return errors.New("invalid identifier for client session") | ||
} | ||
|
||
return filesync.FSSync(ctx, csi.caller, filesync.FSSendRequestOpt{ | ||
SrcPaths: csi.srcPaths, | ||
DestDir: dest, | ||
CacheUpdater: cu, | ||
}) | ||
} | ||
|
||
// ClientSessionSourceIdentifier is an identifier that can be used for requesting | ||
// files from remote client | ||
type ClientSessionSourceIdentifier struct { | ||
srcPaths []string | ||
caller session.Caller | ||
sharedKey string | ||
uuid string | ||
} | ||
|
||
// NewClientSessionSourceIdentifier returns new ClientSessionSourceIdentifier instance | ||
func NewClientSessionSourceIdentifier(ctx context.Context, sg SessionGetter, uuid string, sources []string) (*ClientSessionSourceIdentifier, error) { | ||
csi := &ClientSessionSourceIdentifier{ | ||
uuid: uuid, | ||
srcPaths: sources, | ||
} | ||
caller, err := sg.Get(ctx, uuid) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to get session for %s", uuid) | ||
} | ||
|
||
csi.caller = caller | ||
return csi, nil | ||
} | ||
|
||
// Transport returns transport identifier for remote identifier | ||
func (csi *ClientSessionSourceIdentifier) Transport() string { | ||
return remotecontext.ClientSessionRemote | ||
} | ||
|
||
// SharedKey returns shared key for remote identifier. Shared key is used | ||
// for finding the base for a repeated transfer. | ||
func (csi *ClientSessionSourceIdentifier) SharedKey() string { | ||
return csi.caller.SharedKey() | ||
} | ||
|
||
// Key returns unique key for remote identifier. Requests with same key return | ||
// same data. | ||
func (csi *ClientSessionSourceIdentifier) Key() string { | ||
return csi.uuid | ||
} |
Oops, something went wrong.