supabase / nix-postgres

Experimental port of supabase/postgres to Nix
48 stars 7 forks source link

Steps to reduce overhead when generating Docker images #36

Closed DMills27 closed 9 months ago

DMills27 commented 10 months ago

During a conversation with @olirice last week, he mentioned that the generation of Docker images results in a significant amount of overhead. I noticed while perusing the codebase that dockerTools.buildImage is used in the flake.nix file and I suspect that this is what's generating the unnecessary overhead. My reason for saying this stems from the fact that buildImage insists on writing the entire image, with all its layers, to the Nix store (which in turn consumes unnecessary disk space since individual layers may contain information already present in the Nix store) and this is then compressed into a tarball where any change in a layer leads to a new Docker image being generated, in the form about another tarball, in the Nix store. To make matters worse, a lot of unnecessary duplication can occur between the Nix binary cache and Docker registry tarballs, since the heuristic used for layering prioritizes popular packages being grouped together.

There are a handful of ways in which this issue can be addressed. The most straightforward of which is to replace the dockerTools.buildImage function with the nix2container.buildImage function from the nix2container package which was reified from the contents in this blog post (see here for how it's used and the pitfalls to avoid when using it).

Alternatively, if greater control and further optimization is later required one can opt for one of two choices:

steve-chavez commented 10 months ago

TIL many things! Looking forward to seeing nix2container integration.

samrose commented 9 months ago

closed with #45