google / go-containerregistry

Go library and CLIs for working with container registries
Apache License 2.0
3.17k stars 545 forks source link

crane: deleted files persist in crane export output #2029

Open alexey-igrychev opened 1 month ago

alexey-igrychev commented 1 month ago

Describe the bug

When using crane export to export an image from a registry, deleted files are not ignored despite being removed during the build process.

To Reproduce

  1. Create a Dockerfile with the following commands:

    FROM alpine:3.12
    RUN mkdir -p test
    RUN echo "Hello World" > /test/hello.txt
    RUN rm -rf /test
    RUN mkdir -p /test
    RUN echo "Hello World" > /test/hello2.txt
  2. Start a local registry:

    docker run -d --name=registry --restart=always -e REGISTRY_STORAGE_DELETE_ENABLED=true -p 5000:5000 registry
  3. Build the Docker image:

    docker build -t localhost:5000/test .
  4. Push the image to the local registry:

    docker push localhost:5000/test
  5. Export the image using crane and check for files in the test directory:

    crane export localhost:5000/test - | tar -ztv | grep "test/"
    
    -rw-r--r--  0 0      0          12 Oct 29 22:12 test/hello2.txt
    -rw-r--r--  0 0      0          12 Oct 29 21:45 test/hello.txt
  6. Compare with Docker's export behavior:

    docker run --name test localhost:5000/test
    docker export test | tar -ztv | grep "test/"
    
    drwxr-xr-x  0 0      0           0 Oct 29 22:12 test/
    -rw-r--r--  0 0      0          12 Oct 29 22:12 test/hello2.txt

Expected behavior

crane export should ignore deleted files, consistent with Docker's export behavior.

Additional context

alexey-igrychev commented 1 month ago

The same issue with crane flatten command:

$ crane flatten localhost:5000/test --tag localhost:5000/test:flatten                                  
2024/10/29 22:32:01 pushed blob: sha256:2c695611fb1e094624385a8e6f26d9617ea095d295fd879088569f69b48e983c
2024/10/29 22:32:01 existing blob: sha256:2c695611fb1e094624385a8e6f26d9617ea095d295fd879088569f69b48e983c
2024/10/29 22:32:01 pushed blob: sha256:472616afd54c24f0d61cd3dd307cae5ae24aaf2b14a527db49bd38bfd8b9c4e5
2024/10/29 22:32:01 localhost:5001/test:flatten: digest: sha256:19b2ab1c17df3c87b88235dc6b54b6f53766801cb56f0a8a3d65361dea25a096 size: 428
localhost:5001/test@sha256:19b2ab1c17df3c87b88235dc6b54b6f53766801cb56f0a8a3d65361dea25a096

$ crane export localhost:5000/test:flatten - | tar -ztv | grep "test/"
-rw-r--r--  0 0      0          12 Oct 29 22:12 test/hello2.txt
-rw-r--r--  0 0      0          12 Oct 29 21:45 test/hello.txt
nabokihms commented 1 month ago

@imjasonh hello! I think we can fix this but firstly need your approval.