buildkit icon indicating copy to clipboard operation
buildkit copied to clipboard

WCOW/dockerfile fontend: consistency in handling \ and / slashes for COPY, etc.

Open profnandaa opened this issue 4 months ago • 0 comments

I have noticed we have some inconsistencies on how the dockerfile frontend handles the paths for Windows. I'm opening this issue quickly to track this but I'll provide better details with more tests.

So far, I've noticed this with COPY, but I need to do more tests.

Repro Steps

Dockerfile:

FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
COPY hello.txt C:\
CMD ["cmd", "/C", "type C:\\hello.txt"]

Build command:

buildctl build `
    --frontend=dockerfile.v0 `
    --local context=. \ `
    --local dockerfile=. `
    --output type=image,name=docker.io/janedoe/hello-buildkit,push=false

Expected error:

[+] Building 0.3s (2/2) FINISHED
 => [internal] load build definition from Dockerfile                                                                                    0.0s
 => => transferring dockerfile: 160B                                                                                                    0.0s
 => [internal] load metadata for mcr.microsoft.com/windows/nanoserver:ltsc2022                                                          0.1s
Dockerfile:2
--------------------
   1 |         FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
   2 | >>>     COPY hello.txt C:\
   3 | >>>     CMD ["cmd", "/C", "type C:\\hello.txt"]
   4 |
--------------------
error: failed to solve: failed to process "\"type": unexpected end of statement while looking for matching double-quote

Current Fix/Work-around

General rule of thumb: Use / instead of \ for paths, for a consistent experience. For the above error, changing C:\ in COPY stanza to C:/ fixes it.

/cc. @gabriel-samfira

profnandaa avatar Feb 27 '24 08:02 profnandaa