mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
builder: enable path filtering for filesync session
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
acf855bf10
commit
ad46348d7c
5 changed files with 28 additions and 19 deletions
|
@ -140,8 +140,7 @@ func (bm *BuildManager) initializeClientSession(ctx context.Context, cancel func
|
||||||
}()
|
}()
|
||||||
if options.RemoteContext == remotecontext.ClientSessionRemote {
|
if options.RemoteContext == remotecontext.ClientSessionRemote {
|
||||||
st := time.Now()
|
st := time.Now()
|
||||||
csi, err := NewClientSessionSourceIdentifier(ctx, bm.sg,
|
csi, err := NewClientSessionSourceIdentifier(ctx, bm.sg, options.SessionID)
|
||||||
options.SessionID, []string{"/"})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,26 +30,25 @@ func (cst *ClientSessionTransport) Copy(ctx context.Context, id fscache.RemoteId
|
||||||
}
|
}
|
||||||
|
|
||||||
return filesync.FSSync(ctx, csi.caller, filesync.FSSendRequestOpt{
|
return filesync.FSSync(ctx, csi.caller, filesync.FSSendRequestOpt{
|
||||||
SrcPaths: csi.srcPaths,
|
IncludePatterns: csi.includePatterns,
|
||||||
DestDir: dest,
|
DestDir: dest,
|
||||||
CacheUpdater: cu,
|
CacheUpdater: cu,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientSessionSourceIdentifier is an identifier that can be used for requesting
|
// ClientSessionSourceIdentifier is an identifier that can be used for requesting
|
||||||
// files from remote client
|
// files from remote client
|
||||||
type ClientSessionSourceIdentifier struct {
|
type ClientSessionSourceIdentifier struct {
|
||||||
srcPaths []string
|
includePatterns []string
|
||||||
caller session.Caller
|
caller session.Caller
|
||||||
sharedKey string
|
sharedKey string
|
||||||
uuid string
|
uuid string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClientSessionSourceIdentifier returns new ClientSessionSourceIdentifier instance
|
// NewClientSessionSourceIdentifier returns new ClientSessionSourceIdentifier instance
|
||||||
func NewClientSessionSourceIdentifier(ctx context.Context, sg SessionGetter, uuid string, sources []string) (*ClientSessionSourceIdentifier, error) {
|
func NewClientSessionSourceIdentifier(ctx context.Context, sg SessionGetter, uuid string) (*ClientSessionSourceIdentifier, error) {
|
||||||
csi := &ClientSessionSourceIdentifier{
|
csi := &ClientSessionSourceIdentifier{
|
||||||
uuid: uuid,
|
uuid: uuid,
|
||||||
srcPaths: sources,
|
|
||||||
}
|
}
|
||||||
caller, err := sg.Get(ctx, uuid)
|
caller, err := sg.Get(ctx, uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,9 +9,10 @@ import (
|
||||||
"github.com/tonistiigi/fsutil"
|
"github.com/tonistiigi/fsutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func sendDiffCopy(stream grpc.Stream, dir string, excludes []string, progress progressCb) error {
|
func sendDiffCopy(stream grpc.Stream, dir string, includes, excludes []string, progress progressCb) error {
|
||||||
return fsutil.Send(stream.Context(), stream, dir, &fsutil.WalkOpt{
|
return fsutil.Send(stream.Context(), stream, dir, &fsutil.WalkOpt{
|
||||||
ExcludePatterns: excludes,
|
ExcludePatterns: excludes,
|
||||||
|
IncludePaths: includes, // TODO: rename IncludePatterns
|
||||||
}, progress)
|
}, progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,11 @@ import (
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
keyOverrideExcludes = "override-excludes"
|
||||||
|
keyIncludePatterns = "include-patterns"
|
||||||
|
)
|
||||||
|
|
||||||
type fsSyncProvider struct {
|
type fsSyncProvider struct {
|
||||||
root string
|
root string
|
||||||
excludes []string
|
excludes []string
|
||||||
|
@ -54,9 +59,10 @@ func (sp *fsSyncProvider) handle(method string, stream grpc.ServerStream) error
|
||||||
opts, _ := metadata.FromContext(stream.Context()) // if no metadata continue with empty object
|
opts, _ := metadata.FromContext(stream.Context()) // if no metadata continue with empty object
|
||||||
|
|
||||||
var excludes []string
|
var excludes []string
|
||||||
if len(opts["Override-Excludes"]) == 0 || opts["Override-Excludes"][0] != "true" {
|
if len(opts[keyOverrideExcludes]) == 0 || opts[keyOverrideExcludes][0] != "true" {
|
||||||
excludes = sp.excludes
|
excludes = sp.excludes
|
||||||
}
|
}
|
||||||
|
includes := opts[keyIncludePatterns]
|
||||||
|
|
||||||
var progress progressCb
|
var progress progressCb
|
||||||
if sp.p != nil {
|
if sp.p != nil {
|
||||||
|
@ -69,7 +75,7 @@ func (sp *fsSyncProvider) handle(method string, stream grpc.ServerStream) error
|
||||||
doneCh = sp.doneCh
|
doneCh = sp.doneCh
|
||||||
sp.doneCh = nil
|
sp.doneCh = nil
|
||||||
}
|
}
|
||||||
err := pr.sendFn(stream, sp.root, excludes, progress)
|
err := pr.sendFn(stream, sp.root, includes, excludes, progress)
|
||||||
if doneCh != nil {
|
if doneCh != nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
doneCh <- err
|
doneCh <- err
|
||||||
|
@ -88,7 +94,7 @@ type progressCb func(int, bool)
|
||||||
|
|
||||||
type protocol struct {
|
type protocol struct {
|
||||||
name string
|
name string
|
||||||
sendFn func(stream grpc.Stream, srcDir string, excludes []string, progress progressCb) error
|
sendFn func(stream grpc.Stream, srcDir string, includes, excludes []string, progress progressCb) error
|
||||||
recvFn func(stream grpc.Stream, destDir string, cu CacheUpdater) error
|
recvFn func(stream grpc.Stream, destDir string, cu CacheUpdater) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +121,7 @@ var supportedProtocols = []protocol{
|
||||||
|
|
||||||
// FSSendRequestOpt defines options for FSSend request
|
// FSSendRequestOpt defines options for FSSend request
|
||||||
type FSSendRequestOpt struct {
|
type FSSendRequestOpt struct {
|
||||||
SrcPaths []string
|
IncludePatterns []string
|
||||||
OverrideExcludes bool
|
OverrideExcludes bool
|
||||||
DestDir string
|
DestDir string
|
||||||
CacheUpdater CacheUpdater
|
CacheUpdater CacheUpdater
|
||||||
|
@ -142,7 +148,11 @@ func FSSync(ctx context.Context, c session.Caller, opt FSSendRequestOpt) error {
|
||||||
|
|
||||||
opts := make(map[string][]string)
|
opts := make(map[string][]string)
|
||||||
if opt.OverrideExcludes {
|
if opt.OverrideExcludes {
|
||||||
opts["Override-Excludes"] = []string{"true"}
|
opts[keyOverrideExcludes] = []string{"true"}
|
||||||
|
}
|
||||||
|
|
||||||
|
if opt.IncludePatterns != nil {
|
||||||
|
opts[keyIncludePatterns] = opt.IncludePatterns
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func sendTarStream(stream grpc.Stream, dir string, excludes []string, progress progressCb) error {
|
func sendTarStream(stream grpc.Stream, dir string, includes, excludes []string, progress progressCb) error {
|
||||||
a, err := archive.TarWithOptions(dir, &archive.TarOptions{
|
a, err := archive.TarWithOptions(dir, &archive.TarOptions{
|
||||||
ExcludePatterns: excludes,
|
ExcludePatterns: excludes,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue