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

Receive multiple dests #135

Closed

Conversation

a-palchikov
Copy link

This PR implements support for syncing to multiple directories for moby/buildkit#2760 as needed when multiple output destinations of type local have been specified on the buildctl command line.

I'm open to suggestions on how to change/simplify this approach but that's the minimum I came up with.

Signed-off-by: a-palchikov <deemok@gmail.com>
…tay closer to the original and make it easier to grok

Signed-off-by: a-palchikov <deemok@gmail.com>
Signed-off-by: a-palchikov <deemok@gmail.com>
wcs []io.WriteCloser
}

func newMultiErr(errs ...error) error {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not attempt to introduce another dependency on something like go-multierror so this is ad-hoc multiple errors wrapper.

@@ -158,17 +158,16 @@ func TestWalkerWriterSimple(t *testing.T) {
err = Walk(context.Background(), dest, nil, bufWalk(b))
assert.NoError(t, err)

assert.Equal(t, string(b.Bytes()), `dir bar
assert.Equal(t, `dir bar
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapped the arguments to match the error message better - expected is the first followed by actual. Otherwise, the error message on failure is confusing.

@@ -26,15 +26,18 @@ type ReceiveOpt struct {
Merge bool
Filter FilterFunc
Differ DiffType

diskWriterOpt DiskWriterOpt
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added explicit configuration attribute to work around the necessity to run the test as root (see below).

@@ -67,8 +67,6 @@ func TestInvalidExcludePatterns(t *testing.T) {
}

func TestCopyWithSubDir(t *testing.T) {
requiresRoot(t)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of running as root, the test records changes to the file metadata.

@@ -178,7 +240,7 @@ func TestCopySimple(t *testing.T) {
"ADD zzz/bb dir",
"ADD zzz/bb/cc dir",
"ADD zzz/bb/cc/dd symlink ../../",
"ADD zzz.aa zzdata",
"ADD zzz.aa file zzdata",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was confusing - was the omission of the file type intended? Let me know if this is the case and how to interpret the test then. I had to add the file type as I updated the changes language parser to panic on unexpected input.

@@ -112,10 +174,10 @@ func TestCopySwitchDirToFile(t *testing.T) {

dest, err := tmpDir(changeStream([]string{
"ADD foo dir",
"ADD foo/bar dile data2",
"ADD foo/bar file data2",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a typo or intended?

@@ -231,6 +231,8 @@ func parseChange(str string) *change {
}
st.Mode |= uint32(os.ModeSymlink)
st.Linkname = f[3]
default:
panic(fmt.Sprint("unrecognized file type:", typ))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to find suspected typos in input (see above). If this is intended - please let me know.

}

func Receive(ctx context.Context, conn Stream, dest string, opt ReceiveOpt) error {
ctx, cancel := context.WithCancel(ctx)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looked like a no-op - was it intended?

Copy link
Owner

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a good use-case in mind for this? It seems quite complicated and I don't consider this aspect a blocker for moby/buildkit#2760 . Or I'm also fine if this edge case is handled non-optimally by just transferring things twice.

if r.merge {
err = createDir(ctx, dw.HandleChange, w.fill)
} else {
err = doubleWalkDiff(ctx, dw.HandleChange, getWalkerFn(r.dests[0]), w.fill, r.filter, r.differ)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this works if the comparison for the differ is always based on the first path?

@a-palchikov
Copy link
Author

I have to agree to complexity. I will rewrite it as a corner case of copying twice (or however many times) which I was hesitating to implement. Thanks for your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants