Skip to content

Feature: Add generic option to docker image#23250

Open
tim-werner wants to merge 12 commits into
pantsbuild:mainfrom
tim-werner:add-generic-option-to-docker-image
Open

Feature: Add generic option to docker image#23250
tim-werner wants to merge 12 commits into
pantsbuild: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 thread src/python/pants/backend/docker/goals/package_image.py Outdated
Comment thread src/python/pants/backend/docker/goals/package_image.py Outdated
Comment thread src/python/pants/backend/docker/goals/package_image.py Outdated
Comment thread src/python/pants/backend/docker/goals/package_image_test.py Outdated
@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.

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.

Thanks! Tests and cleanup looks good.

I am a bit on the fence about whether it is actually desirable for the subsystem level extra-list to override the dedicated fields. To clarify, I still think the churn associated with maintaining the fields is real, and not parsing them as invidual fields like pants is currently doing would be better UX.

However, as the system currently looks and works, a release note callout isn't enough I dont think.

Either per target field options override global options, or a warning has to be emitted that we are ignoring target field options and hint at the correct way to override (setting the new per target extras field) is mandatory for this to land.

Comment thread docs/notes/2.33.x.md Outdated
#### Docker

The option `[docker].build_extra_options` or/and the `build_extra_options` field of `docker_image` targets can now be used to pass extra options to docker build or podman build. Make sure that the options are understood by the tool.
For example, you can now set `build_extra_options=["--no-cache"]` to do not use existing cached images for the container build.
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.

Needs a second read through

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.

Sorry that was vague. The example sentence is not parsable for me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have updated the documentation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are now warnings when fields are overwritten.

@tobni tobni added category:new feature backend: Docker Docker backend-related issues labels May 2, 2026
@tim-werner
Copy link
Copy Markdown
Contributor Author

@tobni thank you very much for the review. I have added warnings and updated the documentation. I think it is fine that the subsystem level extra-list overrides the dedicated fields with the additional warnings. This will make it much easier to deprecated the dedicated fields in future.

@tim-werner
Copy link
Copy Markdown
Contributor Author

@tobni @sureshjoshi it seems that the test was killed by the runner probably because of timeout or memory ....

@tim-werner tim-werner requested a review from tobni May 8, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend: Docker Docker backend-related issues category:new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants