Skip to content
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

Fix sync #1253

Merged
merged 2 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions pkg/skaffold/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"path"
"path/filepath"

"github.com/sirupsen/logrus"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
Expand Down Expand Up @@ -92,23 +94,31 @@ func intersect(context string, syncMap map[string]string, files []string) (map[s
if err != nil {
return nil, errors.Wrapf(err, "changed file %s can't be found relative to context %s", f, context)
}
var matches bool
for p, dst := range syncMap {
match, err := filepath.Match(p, relPath)
if err != nil {
return nil, errors.Wrapf(err, "pattern error for %s", relPath)
}
if !match {
return nil, nil
}
// If the source has special match characters,
// the destination must be a directory
// The path package must be used here, since the destination is always
// a linux filesystem.
if util.HasMeta(p) {
dst = path.Join(dst, filepath.Base(relPath))
if match {
// Every file must match at least one sync pattern, if not we'll have to
// skip the entire sync
matches = true
// If the source has special match characters,
// the destination must be a directory
// The path package must be used here, since the destination is always
// a linux filesystem.
if util.HasMeta(p) {
dst = path.Join(dst, filepath.Base(relPath))
}
ret[f] = dst
}
ret[f] = dst
}
if !matches {
logrus.Infof("Changed file %s does not match any sync pattern. Skipping sync", relPath)
return nil, nil
}

}
return ret, nil
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/skaffold/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,39 @@ func TestNewSyncItem(t *testing.T) {
},
shouldErr: true,
},
{
description: "multiple sync patterns",
artifact: &latest.Artifact{
ImageName: "test",
Sync: map[string]string{
"*.js": ".",
"*.html": ".",
"*.json": ".",
},
Workspace: "node",
},
builds: []build.Artifact{
{
ImageName: "test",
Tag: "test:123",
},
},
evt: watch.Events{
Added: []string{filepath.Join("node", "index.html")},
Modified: []string{filepath.Join("node", "server.js")},
Deleted: []string{filepath.Join("node", "package.json")},
},
expected: &Item{
Image: "test:123",
Copy: map[string]string{
filepath.Join("node", "server.js"): "server.js",
filepath.Join("node", "index.html"): "index.html",
},
Delete: map[string]string{
filepath.Join("node", "package.json"): "package.json",
},
},
},
{
description: "sync all",
artifact: &latest.Artifact{
Expand Down