dotnet-buildtools-prereqs-docker icon indicating copy to clipboard operation
dotnet-buildtools-prereqs-docker copied to clipboard

Implement solution for sharing common content used in Dockerfiles

Open mthalman opened this issue 7 months ago • 6 comments

The Dockerfiles in this repo have A LOT of content that is common between them, or at least a subset of them. Just a couple of examples:

  • The Debian packages that get installed in the Helix Dockerfiles are all the same between the different Debian versions.
  • Creation of the helixbot user between the Dockerfiles is (roughly) the same.

Having Dockerfiles that all contain their own implementation leads to the danger of inconsistency amongst the whole set. It's also just extra work on behalf of the contributor to have to apply the changes across Dockerfiles (this change had to be applied the same across 21 Dockerfiles: https://github.com/dotnet/dotnet-buildtools-prereqs-docker/pull/1390).

We should consider options to solve this problem. There are several things to be considered:

  • Use of ARG to parameterize the Dockerfiles: https://github.com/dotnet/dotnet-buildtools-prereqs-docker/issues/231. This solves things only partially and is really only good for simple value replacement like a version number, not for something like a set of commands to be executed. One problem is that image caching doesn't support the use of ARG: https://github.com/dotnet/docker-tools/issues/1505.
  • Encapsulating common logic in scripts that can be executed by multiple Dockerfiles that need that logic. This is nice, but there other elements of Dockerfiles that are common besides just script logic such as setting of ENV vars or just common multi-stage patterns. These script files would also not be supported by image caching: https://github.com/dotnet/docker-tools/issues/1270. In order to use a script by multiple Dockerfiles, you'd also need a way to set the build context to copy in the script which requires https://github.com/dotnet/docker-tools/issues/1592.
  • Implement Dockerfile templates. Image Builder supports this already and is used by dotnet-docker. But there is a desire to migrate to a different templating language: https://github.com/dotnet/docker-tools/issues/1610. Templates solve the shortcomings of ARG and scripts.

mthalman avatar Mar 12 '25 21:03 mthalman