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

Enable to reuse cached results #24

Merged
merged 1 commit into from
May 19, 2022
Merged

Enable to reuse cached results #24

merged 1 commit into from
May 19, 2022

Conversation

ktock
Copy link
Owner

@ktock ktock commented May 19, 2022

Add --cache-reuse option which allows sharing the build cache among invocation of buildg debug to make the 2nd-time debugging faster. This is useful to speed up running buildg multiple times for debugging an errored step.

Note that breakpoints on cached steps are ignored as of now. Because of this limitation, this feature is optional as of now. We should fix this limitation and make it the default behaviour in the future.

The build data is stored to the default common location (e.g. "/var/lib/buildg/data"). To prune the cache, user can manually remove that directory.

example

Here we debug a failed step at line 4 (RUN echo fail > /).

FROM registry2-buildkit:5000/busybox:1
RUN echo foo > /foo
RUN echo bar > /bar
RUN echo fail > /

1st time invocation computes all steps and caches the result at a common location.

$ buildg.sh debug --cache-reuse /tmp/ctx2
INFO[2022-05-19T00:08:14Z] storing the build data to "/home/ktock/.local/share/buildg/data". to prune the data, remove that directory manually. 
WARN[2022-05-19T00:08:14Z] using host network as the default            
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 134B done
#1 DONE 0.1s

#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.1s

#3 [auth] sharing credentials for registry2-buildkit:5000
INFO[2022-05-19T00:08:15Z] debug session started. type "help" for command reference. 
Filename: "Dockerfile"
 =>   1| FROM registry2-buildkit:5000/busybox:1
      2| RUN echo foo > /foo
      3| RUN echo bar > /bar
      4| RUN echo fail > /
(buildg) n
#3 DONE 0.0s

#4 [internal] load metadata for registry2-buildkit:5000/busybox:1
#4 DONE 0.1s

#5 [1/4] FROM registry2-buildkit:5000/busybox:1@sha256:52f431d980baa76878329b68ddb69cb124c25efa6e206d8b0bd797a828f0528e
#5 resolve registry2-buildkit:5000/busybox:1@sha256:52f431d980baa76878329b68ddb69cb124c25efa6e206d8b0bd797a828f0528e done
#5 sha256:50e8d59317eb665383b2ef4d9434aeaa394dcd6f54b96bb7810fdde583e9c2d1 0B / 772.81kB 0.2s
n
#5 sha256:50e8d59317eb665383b2ef4d9434aeaa394dcd6f54b96bb7810fdde583e9c2d1 772.81kB / 772.81kB 5.0s done
Filename: "Dockerfile"
      1| FROM registry2-buildkit:5000/busybox:1
 =>   2| RUN echo foo > /foo
      3| RUN echo bar > /bar
      4| RUN echo fail > /
(buildg) n
#5 extracting sha256:50e8d59317eb665383b2ef4d9434aeaa394dcd6f54b96bb7810fdde583e9c2d1 0.0s done
#5 DONE 10.5s

#6 [2/4] RUN echo foo > /foo
#6 DONE 6.9s

#7 [3/4] RUN echo bar > /bar
Filename: "Dockerfile"
      1| FROM registry2-buildkit:5000/busybox:1
      2| RUN echo foo > /foo
 =>   3| RUN echo bar > /bar
      4| RUN echo fail > /
(buildg) n
#7 DONE 1.3s

#8 [4/4] RUN echo fail > /
#0 0.093 /bin/sh: can't create /: Is a directory
Breakpoint[on-fail]: caught error process "/bin/sh -c echo fail > /" did not complete successfully: exit code: 1
Filename: "Dockerfile"
      1| FROM registry2-buildkit:5000/busybox:1
      2| RUN echo foo > /foo
      3| RUN echo bar > /bar
 =>   4| RUN echo fail > /
(buildg) n
#8 ERROR: process "/bin/sh -c echo fail > /" did not complete successfully: exit code: 1
------
 > [4/4] RUN echo fail > /:
#0 0.093 /bin/sh: can't create /: Is a directory
------
failed to build: failed to solve: process "/bin/sh -c echo fail > /" did not complete successfully: exit code: 1
[rootlesskit:child ] error: command [/bin/sh -c rm -f /run/runc; exec buildg debug --cache-reuse /tmp/ctx2] exited: exit status 1
[rootlesskit:parent] error: child exited: exit status 1

2nd time invocation can reuse the cache and we can quickly debug the errored step (line 4: RUN echo fail > /) multiple times.
All breakpoints on the cached steps are ignored and the debug session starts from line 4.

$ buildg.sh debug --cache-reuse /tmp/ctx2
INFO[2022-05-19T00:08:51Z] storing the build data to "/home/ktock/.local/share/buildg/data". to prune the data, remove that directory manually. 
WARN[2022-05-19T00:08:51Z] using host network as the default            
#1 [internal] load .dockerignore
#1 transferring context: 2B done
#1 DONE 0.0s

#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 134B done
#2 DONE 0.0s

#3 [internal] load metadata for registry2-buildkit:5000/busybox:1
#3 DONE 0.0s

#4 [auth] sharing credentials for registry2-buildkit:5000
#4 DONE 0.0s

#5 [1/4] FROM registry2-buildkit:5000/busybox:1@sha256:52f431d980baa76878329b68ddb69cb124c25efa6e206d8b0bd797a828f0528e
#5 resolve registry2-buildkit:5000/busybox:1@sha256:52f431d980baa76878329b68ddb69cb124c25efa6e206d8b0bd797a828f0528e done
#5 DONE 0.0s

#6 [2/4] RUN echo foo > /foo
#6 CACHED

#7 [3/4] RUN echo bar > /bar
#7 CACHED

#8 [4/4] RUN echo fail > /
#0 0.069 /bin/sh: can't create /: Is a directory
Breakpoint[on-fail]: caught error process "/bin/sh -c echo fail > /" did not complete successfully: exit code: 1
INFO[2022-05-19T00:08:51Z] debug session started. type "help" for command reference. 
Filename: "Dockerfile"
      1| FROM registry2-buildkit:5000/busybox:1
      2| RUN echo foo > /foo
      3| RUN echo bar > /bar
 =>   4| RUN echo fail > /
(buildg) n
#8 ERROR: process "/bin/sh -c echo fail > /" did not complete successfully: exit code: 1
------
 > [4/4] RUN echo fail > /:
#0 0.069 /bin/sh: can't create /: Is a directory
------
failed to build: failed to solve: process "/bin/sh -c echo fail > /" did not complete successfully: exit code: 1
[rootlesskit:child ] error: command [/bin/sh -c rm -f /run/runc; exec buildg debug --cache-reuse /tmp/ctx2] exited: exit status 1
[rootlesskit:parent] error: child exited: exit status 1

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
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.

1 participant