Add support for customizing the list of "default" build arguments supported by docker build #29855
Labels
area/builder
kind/feature
Functionality or other elements that the project doesn't currently have. Features are new and shiny
Based on my current understanding, it appears that any custom build arguments provided to 'docker build' (ie: using the --build-arg parameter) must have an associated 'ARG' declaration in the dockerfile for the parameter to be used, except for several specific parameters which are somehow 'whitelisted' and thus do not require an associated declaration in the dockerfile. This is fine for one or two build arguments, or when managing just a small number of dockerfiles, but it quickly becomes unmanageable at scale.
Example Use Case:
Suppose a company has a mirror of a public package repository such as Python PyPI. The URL to the internal mirror can be set using an environment variable - PIP_INDEX_URL in this case - so that all Python package operations "just work" without further customizations (ie: pip install, etc.). Now, if one wants to create a Docker container which is able to install packages from this repository it would be beneficial to pass the relevant environment variable along to the container so it can be used at build time (ie: to be able to do a "RUN pip install" within a dockerfile, for example). To facilitate this behavior we can provide the relevant URL to docker at build time using "docker build --build-arg PIP_INDEX_URL=http://my_mirror", but in order for the dockerfile to make use of this environment variable we then need to add an associated ARG command to the dockerfile indicating that the argument is to be used. Further, since this is a site-wide customization, every dockerfile created must have this ARG command within it.
Now, suppose a company has 5, 10, 15 or more parameters used by automation and development alike, all customized on a site-by-site basis. As these permutations increase, trying to keep track of which dockerfiles use which variables where and when becomes tedious at best, and fragile at worse.
As a small step towards simplifying these more complex build environments, it would be helpful if there were some way to allow arguments to be pass along to a docker build without having to make modifications to the dockerfile being built.
Drawing some information from the extensive comment thread found here, maybe we could define a command line option, config file, or some such on the host used by the docker dameon to list one or more build arguments to inherit from the --build-arg parameter regardless of whether the dockerfile contains an ARG declaration for it or not.
Alternatively, maybe there could be a way to add a single boolean parameter to the docker build command to allow all build-arg params provided on the command line to be used regardless of the existence of ARG commands in the dockerfile being built - basically a flag that says "whitelist every build argument I'm giving you". This would allow us to override the default behavior of docker build on a case-by-case basis and would avoid having to make changes to the global environment. In our particular case we have a bootstrapper script that developers and automation uses to run docker operations providing an assortment of shortcuts and checks already. With a change like this we could simply update our bootstrapper script so the appropriate parameter gets passed along to the docker command and our users could reap the benefits without further intervention on their part.
The text was updated successfully, but these errors were encountered: