GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.88k stars 1.44k forks source link

Using --reproducible loads entire image into memory #862

Open nathan-c opened 5 years ago

nathan-c commented 5 years ago

Actual behavior When running with --reproducible=true the entire image is loaded into memory.

Expected behavior Memory profile should remain stable regardless of size of image being built.

To Reproduce Steps to reproduce the behavior:

  1. Create following Dockerfile
    FROM ubuntu:latest
    RUN dd if=/dev/zero of=output.dat  bs=1M  count=1000
  2. Execute kaniko with the following parameters
    --context=/some-empty-directory
    --dockerfile=/some-empty-directory/Dockerfile
    --destination=<any destination>
    --cache=true
    --reproducible=true
  3. Watch as memory consumption climbs dramatically near the end of the build.

Additional Information

nathan-c commented 5 years ago

I should probably mention that this means we cannot use --reproducible for our builds because the containers running the build are being killed by k8s on our dev cluster and increasing the node RAM capacity is not a cost effective solution

macrotex commented 4 years ago

We are having this issue as well. We need to use reproducible builds so that our daily builds do not get added to our container registry if there is no "real" change to the docker image.

darkdragon-001 commented 3 years ago

@Phylu Will this also be closed in the 1.7.0 release as of #1722?

Phylu commented 3 years ago

@Phylu Will this also be closed in the 1.7.0 release as of #1722?

I am not sure. Did not try this flag with my changes. If you are lucky, it could be that way.

bh-tt commented 1 year ago

@zx96 do you plan to create a PR for the linked commit? It would save many people a lot of frustration if our image builds would stop crashing at the end of a build due to being killed.

zx96 commented 1 year ago

@zx96 do you plan to create a PR for the linked commit? It would save many people a lot of frustration if our image builds would stop crashing at the end of a build due to being killed.

I certainly can. I was planning on merging it shortly after I made the branch but ran into another bug (that also broke my use case) and got frustrated. I'll rebase my branch tomorrow and see if the other issue is still around - can't recall what issue number it was.

zx96 commented 1 year ago

After rebasing my branch onto the latest main, it looks like I'm able to build an image with a 16GB test file in 512MB of memory with --compressed-caching=false --zero-file-timestamps! 🥳

2477 opened - thanks for reminding me about this @bh-tt .

philippe-granet commented 10 months ago

With kaniko-project/executor:v1.19.2-debug, building the same image:

Activing profiling (https://github.com/GoogleContainerTools/kaniko#kaniko-builds---profiling) I see lot of traces inflate/deflate with --reproducible flag : kaniko.zip

peter-volkov commented 8 months ago

Still causes problems

bh-tt commented 3 weeks ago

To make the code causing the problem a bit clearer:

There are several options:

I'm having some trouble running kaniko in my dev setup so it is hard to see the gains of 2-4, but until metadata is stripped out during build I think implementing them could save a lot of memory (at the cost of disk usage) and result in a small performance gain.

bh-tt commented 3 weeks ago

I've found a 5th option: submitting a PR to go-containerregistry making the layerTime function a lazy transformation. Since the problem lies in a dependency, that may be the best way to achieve this result.