Skip to content

Feature: Add generic option to docker image#23250

Open
tim-werner wants to merge 8 commits intopantsbuild:mainfrom
tim-werner:add-generic-option-to-docker-image
Open

Feature: Add generic option to docker image#23250
tim-werner wants to merge 8 commits intopantsbuild:mainfrom
tim-werner:add-generic-option-to-docker-image

Conversation

@tim-werner
Copy link
Copy Markdown
Contributor

This pull request allows it now to add generic build options to docker/podman build. It will also work as a workaround for issue: #21450

It is now possible to use pass generic build options to docker and podman. The old arguments such as pull on docker_image target level or no-cache on global level will still work, however the new build_extra_option will have precedence.

AI was used to find the right locations in the code base for the changes and to write the tests faster. However, most of the code was written by human.

This is an improvement of pull request: #23032

@tim-werner tim-werner force-pushed the add-generic-option-to-docker-image branch from 124c44c to 99f5e5d Compare April 14, 2026 14:15
@tobni tobni self-assigned this Apr 17, 2026
@tobni tobni self-requested a review April 17, 2026 16:46
Copy link
Copy Markdown
Contributor

@tobni tobni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for the contribution!

The feature looks well thought out w.r.t how options should be propagated, and I agree with the general direction of providing a list of args instead of adding a new option for each arg.

I am however not going to review the test cases before you do. Happy to once they at least conform to the style of the test file where they were introduced.

Comment on lines +328 to +332
"""Return the set of flag names (e.g. ``--pull``) present in *extra_options*.

Handles both ``--flag=value`` and ``--flag value`` styles so that any structured field whose
``docker_build_option`` class variable matches one of these names will be suppressed in favour
of the caller-supplied value, avoiding duplicate or conflicting flags on the command line.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads like LLM output. The function name and readable python code serves the same purpose as this very verbose docstring. There is also no logic here that enforces the caller-supplied override.

filtered_global = tuple(
opt
for opt in global_extra_options
if opt.startswith("-") and opt.split("=")[0] not in target_flag_names
Copy link
Copy Markdown
Contributor

@tobni tobni Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic of extracting a flag name repeats for the per-target set. I also suggest extract a function for the option name collision logic to spare us the continous growth of get_build_options.

Comment on lines +390 to +394
flag = getattr(
field_type, "docker_build_option", None
) # get the flag name if it exists such as --pull or --network, etc.
if flag and flag in overridden_flags:
continue # skip this field since its flag is already covered by extra_options
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary comments.



def test_global_build_extra_options(rule_runner: RuleRunner) -> None:
"""Global build_extra_options from [docker] should be passed to the docker build command."""
Copy link
Copy Markdown
Contributor

@tobni tobni Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLM docstrings that you have not vetted (the example I am commenting is obviously redundant considering the test name and assertion).

Please re-review and cleanup your test cases and LMK when you have and I'll continue review! 👍

@tim-werner
Copy link
Copy Markdown
Contributor Author

Hi @tobni ,
thank you very much for your time to review the pull request. I have updated the pull request to consider your suggestions. The tests are now condensed into two tests with parametrize options. I have not created a single test in order to keep it simple and in future we should conisder to drop the support of setting options such as pull, no-cache , target etc. in the docker_image directly and only allow to use the more general option that is proposed in this pull request.

@tim-werner tim-werner requested a review from tobni April 20, 2026 08:37
Copy link
Copy Markdown
Member

@sureshjoshi sureshjoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. We've just branched for 2.32.x, so merging this pull request now will come out in 2.33.x, please move the release notes updates to docs/notes/2.33.x.md if that's appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants