buildkit
buildkit copied to clipboard
progress: if not escaped, backslashes `\` not printed on the progress stream dockerfile steps
However, prints when escaped or put within "..":
Minimal repro dockerfile:
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
RUN echo C:\hello\world\path
RUN echo C:\\hello\\escaped\\path
RUN echo "C:\hello\quoted\path"
Result:
#5 [2/4] RUN echo C:helloworldpath
#5 1.359 C:\hello\world\path
#5 DONE 1.7s
#6 [3/4] RUN echo C:\hello\escaped\path
#6 1.734 C:\\hello\\escaped\\path
#6 DONE 2.1s
#7 [4/4] RUN echo "C:\hello\quoted\path"
#7 1.765 "C:\hello\quoted\path"
#7 DONE 2.1s
With classic docker build:
Result:
Step 2/4 : RUN echo C:\hello\world\path
---> Running in 94d37a87e491
C:\hello\world\path
---> Removed intermediate container 94d37a87e491
---> b098d8792b7c
Step 3/4 : RUN echo C:\\hello\\escaped\\path
---> Running in d2fcea089fb1
C:\\hello\\escaped\\path
---> Removed intermediate container d2fcea089fb1
---> e6c9869a97f8
Step 4/4 : RUN echo "C:\hello\quoted\path"
---> Running in 2e2c603aebe2
"C:\hello\quoted\path"
---> Removed intermediate container 2e2c603aebe2
---> 56ba89eb540e
It can also be reproduced on Linux:
$ cat Dockerfile
FROM alpine
RUN echo mkdir C:\another\sample
RUN echo mkdir C:\\another\\sample
$ docker build -t backslash-test --no-cache .
[+] Building 0.8s (7/7) FINISHED docker:default
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 118B 0.0s
=> [internal] load metadata for docker.io/library/alpine:latest 0.2s
=> CACHED [1/3] FROM docker.io/library/alpine@sha256:0a4eaa0eecf5f8c050e5bba433f58c052be7587ee8af3e8b3910ef9ab5fbe9f5 0.0s
=> [2/3] RUN echo mkdir C:anothersample 0.2s
=> [3/3] RUN echo mkdir C:\another\sample 0.2s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:cfbd890f4a908e48975d6c462a8b7b447effe943208c64625f2e0601942af236 0.0s
=> => naming to docker.io/library/backslash-test 0.0s
@ardrabczyk -- good catch, thanks! Updated the title and description.
I have narrowed down to this, frontend/dockerfile/dockerfile2llb/convert.go:2055
> github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb.processCmdEnv() C:/dev/buildkit/frontend/dockerfile/dockerfile2llb/convert.go:2057 (PC: 0x238dec1)
2055: func processCmdEnv(shlex *shell.Lex, cmd string, env shell.EnvGetter) string {
2056: w, _, err := shlex.ProcessWord(cmd, env)
=>2057: if err != nil {
2058: return cmd
2059: }
2060: return w
2061: }
2062:
(dlv) p cmd
"RUN echo C:\\hello\\world\\path"
(dlv) p w
"RUN echo C:helloworldpath"
~~~~~~~~~~~^^--- backslashes being stripped off by the lexer.
(dlv)
I'm not really conversant with this lexer, will appreciate any tips? @tonistiigi