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

monitor: Allow launching container from non-exec op with on-error #1807

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ktock
Copy link
Collaborator

@ktock ktock commented May 17, 2023

Following-up #1640 (comment) :

From @jedevc 's comment:

We should support breaking on other failed commands, like COPY - atm, on-error stops in the right place, but I can't spawn any session. Even if we just drop into a default shell, with no extra args, environment variables, that's alright for now. This will be necessary to provide a good experience with monitor: breakpoint debugger on monitor and on IDEs (via DAP) #1656 as well.

Currently on-error launches container only from the errored ExecOp. This commit allows it from FileOp (COPY instruction) as well.

Unfortunately buildkitd doesn't seem to return the container execution information (*pb.Meta) on non-exec op failure, so we lanch the container from the result of the previous op of the failed one. Currently this is supported only for FileOp but we can expand this feature for other types of Ops if needed in the future.

In the following example Dockerfile, the build fails on COPY --from=dev /none / and the debugger container is created by the result of the input (COPY --from=dev /hi /).

FROM ubuntu:22.04 AS dev
RUN echo hi > /hi

FROM ubuntu:22.04
ENV a=test
COPY --from=dev /hi /
COPY --from=dev /none /
$  BUILDX_EXPERIMENTAL=1 /tmp/out/buildx build --detach=false --invoke sh /tmp/ctx4
[+] Building 2.2s (9/9) FINISHED                        docker-container:latest
 => [internal] connecting to local controller                              0.0s
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 156B                                       0.0s
 => [internal] load metadata for docker.io/library/ubuntu:22.04            1.5s
 => [auth] library/ubuntu:pull token for registry-1.docker.io              0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => CACHED [dev 1/2] FROM docker.io/library/ubuntu:22.04@sha256:dfd64a3b4  0.0s
 => => resolve docker.io/library/ubuntu:22.04@sha256:dfd64a3b4296d8c9b62a  0.0s
 => [dev 2/2] RUN echo hi > /hi                                            0.2s
 => CANCELED [stage-1 2/3] COPY --from=dev /hi /                           0.1s
 => ERROR [stage-1 3/3] COPY --from=dev /none /                            0.0s
------
 > [stage-1 3/3] COPY --from=dev /none /:
------
WARNING: No output specified with docker-container 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
Launching interactive container. Press Ctrl-a-c to switch to monitor console
Interactive container was restarted with process "qls4gawl4ui0nytxdj7fste7r". Press Ctrl-a-c to switch to the new container
# echo $a
test
# cat hi
hi
# 

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
var parentSelector func(inputs []llb.Output) llb.Output
switch r.solveErr.Solve.Op.GetOp().(type) {
case *pb.Op_File:
parentSelector = func(inputs []llb.Output) llb.Output { return inputs[0] } // TODO: allow user selecting one input?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An op can have multiple inputs and the current implementation always uses the first input (input[0]). But maybe we need to introduce a way to ensure the input is actually the previous step's rootfs. Or maybe we can introduce a way to let the user choose one of the inputs.
Currently I don't have good idea for them so please let me know if there is a good way to solve it.

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.

None yet

1 participant