buildkit
buildkit copied to clipboard
Using a named context to replace an image source panics when the name does not refer to a valid registry image
Small reproducer:
FROM scratch AS a
COPY /a.txt /
FROM a AS b
RUN find . -type f
Note that the RUN command would fail if this completed successfully because find doesn't exist inside of the image and neither does /bin/sh.
When you have a dockerfile like above and perform the following command, it causes the buildkit daemon to panic.
$ docker buildx --build-context a=./alt .
[+] Building 0.0s (2/2) FINISHED remote:dev
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 206B 0.0s
=> [context a] load .dockerignore 0.0s
=> => transferring a: 2B 0.0s
WARNING: No output specified with remote driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
ERROR: failed to receive status: rpc error: code = Unavailable desc = error reading from server: EOF
$ docker logs buildkit-dev
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xd72d8c]
goroutine 174 [running]:
github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb.toDispatchState({_, _}, {_, _, _}, {{0x40003308d0, {0x0, 0x0}, {0x0, 0x
0}, ...}, ...})
/src/frontend/dockerfile/dockerfile2llb/convert.go:490 +0x1b8c
github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb.Dockerfile2LLB({_, _}, {_, _, _}, {{0x40003308d0, {0x0, 0x0}, {0x0, 0x0
}, ...}, ...})
/src/frontend/dockerfile/dockerfile2llb/convert.go:74 +0x4c
github.com/moby/buildkit/frontend/dockerfile/builder.Build.func5({0x1624cc0, 0x400055c190}, 0x0, 0x0?)
/src/frontend/dockerfile/builder/build.go:119 +0xb4
github.com/moby/buildkit/frontend/dockerui.(*Client).Build.func1()
/src/frontend/dockerui/build.go:39 +0x60
golang.org/x/sync/errgroup.(*Group).Go.func1()
/src/vendor/golang.org/x/sync/errgroup/errgroup.go:75 +0x5c
created by golang.org/x/sync/errgroup.(*Group).Go
/src/vendor/golang.org/x/sync/errgroup/errgroup.go:72 +0x9c
This panic doesn't happen if the name is something that matches an image in the docker registry. If I use alpine as the stage name, I get a more appropriate error about my dockerfile being invalid.
#5 [b 1/1] RUN find . -type f
#5 0.048 runc run failed: unable to start container process: exec: "/bin/sh": stat /bin/sh: no such file or directory
#5 ERROR: process "/bin/sh -c find . -type f" did not complete successfully: exit code: 1
------
> [b 1/1] RUN find . -type f:
0.048 runc run failed: unable to start container process: exec: "/bin/sh": stat /bin/sh: no such file or directory
------
WARNING: No output specified with remote driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile:9
--------------------
7 |
8 | FROM alpine AS b
9 | >>> RUN find . -type f
10 |
--------------------
ERROR: failed to solve: process "/bin/sh -c find . -type f" did not complete successfully: exit code: 1
This will end up being fixed by #4161 when that's merged.
The above was merged but I think I forgot to close this. Closing it now.