moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
https://github.com/moby/moby/issues/34227
Apache License 2.0
8.03k stars 1.12k forks source link

exporter: expeted output local tarball, but if build failed, an empty output tarball left #1305

Open jingxiaolu opened 4 years ago

jingxiaolu commented 4 years ago

Dockerfile:

FROM alpine
RUN exit 1

Build log:

# buildctl build --frontend dockerfile.v0 --local dockerfile=. --local context=. --output type=oci,dest=`pwd`/oci.tar
[+] Building 7.9s (5/5) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                         0.0s
 => => transferring dockerfile: 60B                                                                                                                                                                          0.0s
 => [internal] load .dockerignore                                                                                                                                                                            0.0s
 => => transferring context: 2B                                                                                                                                                                              0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                                                             7.8s
 => CACHED [1/2] FROM docker.io/library/alpine@sha256:2171658620155679240babee0a7714f6509fae66898db422ad803b951257db78                                                                                       0.0s
 => => resolve docker.io/library/alpine@sha256:2171658620155679240babee0a7714f6509fae66898db422ad803b951257db78                                                                                              0.0s
 => ERROR [2/2] RUN exit 1                                                                                                                                                                                   0.1s
------
 > [2/2] RUN exit 1:
------
error: failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to build LLB: executor failed running [/bin/sh -c exit 1]: buildkit-runc did not terminate sucessfully
# ls -al
total 12
drwxr-xr-x  2 root root 4096 Dec 30 11:21 .
drwxr-xr-x 11 root root 4096 Dec 30 11:20 ..
-rw-r--r--  1 root root   23 Dec 30 11:20 Dockerfile
-rw-rw-rw-  1 root root    0 Dec 30 11:21 oci.tar
# tar -xvf oci.tar
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors

Tarball also left with tarball exporter and docker tarball:

Versions:

# buildctl -v
buildctl github.com/moby/buildkit v0.6.1-165-g8e4ab0b 8e4ab0b04e97d2e594bea0a1ea33cdcf8b3d67df
# buildkitd -v
buildkitd github.com/moby/buildkit v0.6.1-165-g8e4ab0b 8e4ab0b04e97d2e594bea0a1ea33cdcf8b3d67df

I think buildctl should delete the lefted oci.tar when building failed. Please share your comments~

AkihiroSuda commented 4 years ago

Deleting SGTM, could you open PR?

jingxiaolu commented 4 years ago

OK, I'll push a PR. Thanks~