Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
| ... | ... |
@@ -140,8 +140,7 @@ func (bm *BuildManager) initializeClientSession(ctx context.Context, cancel func |
| 140 | 140 |
}() |
| 141 | 141 |
if options.RemoteContext == remotecontext.ClientSessionRemote {
|
| 142 | 142 |
st := time.Now() |
| 143 |
- csi, err := NewClientSessionSourceIdentifier(ctx, bm.sg, |
|
| 144 |
- options.SessionID, []string{"/"})
|
|
| 143 |
+ csi, err := NewClientSessionSourceIdentifier(ctx, bm.sg, options.SessionID) |
|
| 145 | 144 |
if err != nil {
|
| 146 | 145 |
return nil, err |
| 147 | 146 |
} |
| ... | ... |
@@ -30,26 +30,25 @@ func (cst *ClientSessionTransport) Copy(ctx context.Context, id fscache.RemoteId |
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 | 32 |
return filesync.FSSync(ctx, csi.caller, filesync.FSSendRequestOpt{
|
| 33 |
- SrcPaths: csi.srcPaths, |
|
| 34 |
- DestDir: dest, |
|
| 35 |
- CacheUpdater: cu, |
|
| 33 |
+ IncludePatterns: csi.includePatterns, |
|
| 34 |
+ DestDir: dest, |
|
| 35 |
+ CacheUpdater: cu, |
|
| 36 | 36 |
}) |
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 | 39 |
// ClientSessionSourceIdentifier is an identifier that can be used for requesting |
| 40 | 40 |
// files from remote client |
| 41 | 41 |
type ClientSessionSourceIdentifier struct {
|
| 42 |
- srcPaths []string |
|
| 43 |
- caller session.Caller |
|
| 44 |
- sharedKey string |
|
| 45 |
- uuid string |
|
| 42 |
+ includePatterns []string |
|
| 43 |
+ caller session.Caller |
|
| 44 |
+ sharedKey string |
|
| 45 |
+ uuid string |
|
| 46 | 46 |
} |
| 47 | 47 |
|
| 48 | 48 |
// NewClientSessionSourceIdentifier returns new ClientSessionSourceIdentifier instance |
| 49 |
-func NewClientSessionSourceIdentifier(ctx context.Context, sg SessionGetter, uuid string, sources []string) (*ClientSessionSourceIdentifier, error) {
|
|
| 49 |
+func NewClientSessionSourceIdentifier(ctx context.Context, sg SessionGetter, uuid string) (*ClientSessionSourceIdentifier, error) {
|
|
| 50 | 50 |
csi := &ClientSessionSourceIdentifier{
|
| 51 |
- uuid: uuid, |
|
| 52 |
- srcPaths: sources, |
|
| 51 |
+ uuid: uuid, |
|
| 53 | 52 |
} |
| 54 | 53 |
caller, err := sg.Get(ctx, uuid) |
| 55 | 54 |
if err != nil {
|
| ... | ... |
@@ -9,9 +9,10 @@ import ( |
| 9 | 9 |
"github.com/tonistiigi/fsutil" |
| 10 | 10 |
) |
| 11 | 11 |
|
| 12 |
-func sendDiffCopy(stream grpc.Stream, dir string, excludes []string, progress progressCb) error {
|
|
| 12 |
+func sendDiffCopy(stream grpc.Stream, dir string, includes, excludes []string, progress progressCb) error {
|
|
| 13 | 13 |
return fsutil.Send(stream.Context(), stream, dir, &fsutil.WalkOpt{
|
| 14 | 14 |
ExcludePatterns: excludes, |
| 15 |
+ IncludePaths: includes, // TODO: rename IncludePatterns |
|
| 15 | 16 |
}, progress) |
| 16 | 17 |
} |
| 17 | 18 |
|
| ... | ... |
@@ -12,6 +12,11 @@ import ( |
| 12 | 12 |
"google.golang.org/grpc/metadata" |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 |
+const ( |
|
| 16 |
+ keyOverrideExcludes = "override-excludes" |
|
| 17 |
+ keyIncludePatterns = "include-patterns" |
|
| 18 |
+) |
|
| 19 |
+ |
|
| 15 | 20 |
type fsSyncProvider struct {
|
| 16 | 21 |
root string |
| 17 | 22 |
excludes []string |
| ... | ... |
@@ -54,9 +59,10 @@ func (sp *fsSyncProvider) handle(method string, stream grpc.ServerStream) error |
| 54 | 54 |
opts, _ := metadata.FromContext(stream.Context()) // if no metadata continue with empty object |
| 55 | 55 |
|
| 56 | 56 |
var excludes []string |
| 57 |
- if len(opts["Override-Excludes"]) == 0 || opts["Override-Excludes"][0] != "true" {
|
|
| 57 |
+ if len(opts[keyOverrideExcludes]) == 0 || opts[keyOverrideExcludes][0] != "true" {
|
|
| 58 | 58 |
excludes = sp.excludes |
| 59 | 59 |
} |
| 60 |
+ includes := opts[keyIncludePatterns] |
|
| 60 | 61 |
|
| 61 | 62 |
var progress progressCb |
| 62 | 63 |
if sp.p != nil {
|
| ... | ... |
@@ -69,7 +75,7 @@ func (sp *fsSyncProvider) handle(method string, stream grpc.ServerStream) error |
| 69 | 69 |
doneCh = sp.doneCh |
| 70 | 70 |
sp.doneCh = nil |
| 71 | 71 |
} |
| 72 |
- err := pr.sendFn(stream, sp.root, excludes, progress) |
|
| 72 |
+ err := pr.sendFn(stream, sp.root, includes, excludes, progress) |
|
| 73 | 73 |
if doneCh != nil {
|
| 74 | 74 |
if err != nil {
|
| 75 | 75 |
doneCh <- err |
| ... | ... |
@@ -88,7 +94,7 @@ type progressCb func(int, bool) |
| 88 | 88 |
|
| 89 | 89 |
type protocol struct {
|
| 90 | 90 |
name string |
| 91 |
- sendFn func(stream grpc.Stream, srcDir string, excludes []string, progress progressCb) error |
|
| 91 |
+ sendFn func(stream grpc.Stream, srcDir string, includes, excludes []string, progress progressCb) error |
|
| 92 | 92 |
recvFn func(stream grpc.Stream, destDir string, cu CacheUpdater) error |
| 93 | 93 |
} |
| 94 | 94 |
|
| ... | ... |
@@ -115,7 +121,7 @@ var supportedProtocols = []protocol{
|
| 115 | 115 |
|
| 116 | 116 |
// FSSendRequestOpt defines options for FSSend request |
| 117 | 117 |
type FSSendRequestOpt struct {
|
| 118 |
- SrcPaths []string |
|
| 118 |
+ IncludePatterns []string |
|
| 119 | 119 |
OverrideExcludes bool |
| 120 | 120 |
DestDir string |
| 121 | 121 |
CacheUpdater CacheUpdater |
| ... | ... |
@@ -142,7 +148,11 @@ func FSSync(ctx context.Context, c session.Caller, opt FSSendRequestOpt) error {
|
| 142 | 142 |
|
| 143 | 143 |
opts := make(map[string][]string) |
| 144 | 144 |
if opt.OverrideExcludes {
|
| 145 |
- opts["Override-Excludes"] = []string{"true"}
|
|
| 145 |
+ opts[keyOverrideExcludes] = []string{"true"}
|
|
| 146 |
+ } |
|
| 147 |
+ |
|
| 148 |
+ if opt.IncludePatterns != nil {
|
|
| 149 |
+ opts[keyIncludePatterns] = opt.IncludePatterns |
|
| 146 | 150 |
} |
| 147 | 151 |
|
| 148 | 152 |
ctx, cancel := context.WithCancel(ctx) |
| ... | ... |
@@ -10,7 +10,7 @@ import ( |
| 10 | 10 |
"google.golang.org/grpc" |
| 11 | 11 |
) |
| 12 | 12 |
|
| 13 |
-func sendTarStream(stream grpc.Stream, dir string, excludes []string, progress progressCb) error {
|
|
| 13 |
+func sendTarStream(stream grpc.Stream, dir string, includes, excludes []string, progress progressCb) error {
|
|
| 14 | 14 |
a, err := archive.TarWithOptions(dir, &archive.TarOptions{
|
| 15 | 15 |
ExcludePatterns: excludes, |
| 16 | 16 |
}) |