-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
LCOW: Ensure platform is populated on COPY/ADD #37563
Conversation
Signed-off-by: John Howard <jhoward@microsoft.com>
Codecov Report
@@ Coverage Diff @@
## master #37563 +/- ##
=========================================
Coverage ? 35.62%
=========================================
Files ? 610
Lines ? 44903
Branches ? 0
=========================================
Hits ? 15996
Misses ? 26705
Partials ? 2202 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a comment; I'm not super-familiar with this code, so my comment is just from digging a bit
return copier{ | ||
source: req.source, | ||
pathCache: req.builder.pathCache, | ||
download: download, | ||
imageSource: imageSource, | ||
platform: req.builder.platform, | ||
platform: platform, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that after the copier is created, builder.performCopy()
is called;
moby/builder/dockerfile/dispatchers.go
Lines 123 to 131 in 492545e
copier := copierFromDispatchRequest(d, errOnSourceDownload, im) | |
defer copier.Cleanup() | |
copyInstruction, err := copier.createCopyInstruction(c.SourcesAndDest, "COPY") | |
if err != nil { | |
return err | |
} | |
copyInstruction.chownStr = c.Chown | |
return d.builder.performCopy(d, copyInstruction) |
Looking at that function, that seems to use req.builder.platform
, not the value set on the copier.
moby/builder/dockerfile/internals.go
Line 172 in f0585d0
imageMount, err := b.imageSources.Get(state.imageID, true, req.builder.platform) |
The value is actually used, but only for path separators, and not persisted in the copy instruction itself;
moby/builder/dockerfile/copy.go
Lines 98 to 106 in b711437
// Work in platform-specific filepath semantics | |
// TODO: This OS switch for paths is NOT correct and should not be supported. | |
// Maintained for backwards compatibility | |
pathOS := runtime.GOOS | |
if o.platform != nil { | |
pathOS = o.platform.OS | |
} | |
inst.dest = fromSlash(args[last], pathOS) | |
separator := string(separator(pathOS)) |
Should a property beaded to copyInstruction
, and set to this value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thaJeztah I'll defer to @tonistiigi here. I don't think it matters, but I don't own the builder code. Just fixing a bug...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The platform in
moby/builder/dockerfile/internals.go
Line 172 in f0585d0
imageMount, err := b.imageSources.Get(state.imageID, true, req.builder.platform) |
--from
not for the current instruction so may be different.
ping @simonferquel PTAL as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: John Howard jhoward@microsoft.com
Fixes #37561, and internal VSO bug 17531561.
The copier object constructor is only using the API/dockerfile requested platform (OS) and ignoring the implicit operating system in the builder state. Hence, on LCOW (see linked issue this fixes) where no platform is passed in the API, a docker build goes down the route of assuming it's Windows paths.
@tonistiigi, @johnstep PTAL. @jterry75 FYI
Note there is an alternate fix I came up with initially. Both fixes work, but I think this is cleaner having the correct OS set at the start of the COPY command as it comes in from the dispatcher. Alternate can be found at 3bf17fc.
Using the same dockerfile from the linked issue, results with this fix (it succeeds and /foo/bar/dockerfile is shown in step 4).