Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add docker build custom options #5838

Open
wants to merge 1 commit into
base: mainline
Choose a base branch
from

Conversation

mRoca
Copy link
Contributor

@mRoca mRoca commented Jun 10, 2024

This PR allows providing any command line options to docker build by accepting them from an array of string instead of trying to define them all one by one.

For now, only --target & --cache-from are supported since #1555, but we cannot anticipate every single new options (as those used by buildx, or secret files, for instance).

Example:

image:
    dockerfile: path/to/dockerfile
    options: [ --target, my-target ]

image:
  build:
    dockerfile: path/to/dockerfile
    options:
      - --pull
      - --builder
      - my-buildx-builder
      - --cache-from
      - type=registry,mode=max,compression-level=1,ref=${CI_REGISTRY_IMAGE}/web:latest-cache
      - --cache-to
      - type=registry,mode=max,compression-level=1,ref=${CI_REGISTRY_IMAGE}/web:latest-cache
      - --secret
      - id=npmrc,src=.npmrc

Using an array of strings is not really readable when declaring options prefixed with a --. The alternative would be passing the options as a single or multilines string, but this would be a lot less flexible. What do you think about it ?

Fixes #2090, fixes #3466


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.

@mRoca mRoca requested review from hkford and a team as code owners June 10, 2024 15:39
@mRoca mRoca requested review from huanjani and removed request for a team June 10, 2024 15:39
Copy link

github-actions bot commented Jun 10, 2024

🍕 Here are the new binary sizes!

Name New size (kiB) size (kiB) Delta (%)
macOS (amd) 58088 58072 +0.03
macOS (arm) 59136 59136 ❤️ 0.00
linux (amd) 50936 50924 +0.02
linux (arm) 50176 50180 ❤️ -0.01
windows (amd) 47972 47968 +0.01

@huanjani
Copy link
Contributor

Hello, @mRoca!

Thanks so much for your contribution! You're absolutely right that your proposed changes would make our manifests more nimble for Docker options; unfortunately, any manifest changes need to be backwards-compatible so existing workloads don't break. We can't consolidate our existing build options into a more general options field at this point.

We could theoretically add the options field and hide the existing --target and --cache-from fields but still handle them exactly as we have, combining them with any options in the options field. But your questions correctly suggest that the input and parsing of the list of options would require some amount of thought, guidance, and tons of validation.

Thanks again!

@mRoca
Copy link
Contributor Author

mRoca commented Jun 17, 2024

Hi @huanjani , I don't get your point :-/ I've indeed added the options yaml field, while still handling old --target and --cache-from fields (even if they are not documented anymore), in order to avoid any bc break. What do you suggest I should add to the PR ?

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.

allow more/all Docker build options Support --secret and --ssh flags in docker build args for buildkit
2 participants