TIL: buildpacks can rebase to save needless compute work

CNCF buildpacks have a nice trick that if you work with dockerfiles a lot you might appreciate.

It’s pretty common to use things like Dockerfiles to make it easier to deploy applications online, but as someone who professionally used Heroku, and was much more interested in docker indirectly, via a Platform as a Service, I’ve appreciated the existence of Buildpacks offered by Heroku.

They were ultimately superceded by Cloud Native Buildpacks, and one thing I didn’t realise was that buildpacks have a nice treat up their sleeve – they can rebase, when lower level dependencies are updated, without needing to create a totally new docker image.

Let’s imagine you have a image, like so, and you need to update the operating system:

A diagram showing a multi layer image, with the OS layer being updated

With buildpacks, you only need to update the base – SHA hashes are taken of the all the other layers, and rebase on top it

Buildpacks rebase process ultimately constructs a new container image using both the existing layers and the new operating system layers, without the need for build.

Reduce, Reuse, Rebase: Sustainable Containers with Buildpacks

You can read more on the Cloud Native Sustainability Technical Architectruee Group website.