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

Support bake remote definitions #656

Conversation

rcwbr
Copy link
Contributor

@rcwbr rcwbr commented Dec 3, 2024

Docker buildx bake supports remote Bake file definitions, but this functionality seems to be missing from the existing API. This change intends to add support for this.

I was lazy about rendering the docs, so also threw in a change to save the rendered files from the CI pipeline as an artifact -- not sure if this would have too much impact on GitHub storage, but figured I'd propose the change.

A couple notes on the implementation:

  1. The arg name I selected is "context" -- "definition" or "target" might align better to upstream docs, though neither is clearly specified in docs and all are overloaded 😬 Very happy to change to a better name if there is one!
  2. The context arg is directly appended to the full_cmd, meaning the content of the arg could technically be any valid bake CLI arg. Validation could prevent this, but didn't seem too important.
  3. In the test, I locked the remote ref to the v0.74.0 tag. This seems slightly awkward, but should at least be safe since its immutable.

Please let me know if I'm missing anything, or if anything needs to be changed!

@gabrieldemarmiesse
Copy link
Owner

Many thanks for the PR! I'll take a look when I have the time :)

Copy link
Owner

@gabrieldemarmiesse gabrieldemarmiesse left a comment

Choose a reason for hiding this comment

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

Very very nice PR, easy to read, straight to the point. ❤️ A few changes and we can merge this.

Comment on lines 661 to 664
config = docker.buildx.bake(
print=only_print,
context="https://github.com/gabrieldemarmiesse/python-on-whales.git#v0.74.0:tests/python_on_whales/components/bake_tests",
)

Choose a reason for hiding this comment

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

Can you also add a test where you specify a target to make sure the arguments are passed in the right order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, added

@@ -126,6 +126,7 @@ def bake(
set: Dict[str, str] = {},
variables: Dict[str, str] = {},
stream_logs: bool = False,
context: Union[str, None] = None,

Choose a reason for hiding this comment

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

The issue I have with context is that context already exists: https://docs.docker.com/build/bake/contexts/ and it's slight different.

What about being explicit? Unless I'm missing something, we can just use "remote_definition", it's the term used in the docker documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah remote_definition seems good, changed to that.

The interesting behavior with context is that by default, the contents of the remote_context become the value of Bake target contexts (not contexts), for example in the test definition. However, this is only the default; if the Bake file defines a context, it may be unrelated to this value.

TBH I think the whole idea of this Bake functionality needs some clarification/cleanup from Docker folks, but until that happens I think this is the best we can do!

@@ -22,6 +22,10 @@ jobs:
cp docs/mkdocs.yml ./
- name: Render
run: uv run mkdocs build
- uses: actions/upload-artifact@v4

Choose a reason for hiding this comment

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

Not mandatory, but since this is an awesome feature, you can add it to the CONTRIBUTING.md :) so contributors don't have to build the docs themselves. Just say

  • where to click to get the files
  • unzip it
  • open index.html with the browser

Again it's optional since you contributed this feature and it's a net improvement, but if you want to go the extra mile, I'd appreciate a note in the contributing guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, added!

@rcwbr rcwbr force-pushed the support-bake-remote-definitions branch from c750635 to 2e51334 Compare December 7, 2024 04:15
@rcwbr
Copy link
Contributor Author

rcwbr commented Dec 7, 2024

Very very nice PR, easy to read, straight to the point. ❤️ A few changes and we can merge this.

Thank you, and thanks for the awesome library!!! Should be ready for re-review now if you'd like

Copy link
Owner

@gabrieldemarmiesse gabrieldemarmiesse left a comment

Choose a reason for hiding this comment

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

Very nice!

@gabrieldemarmiesse gabrieldemarmiesse merged commit b2ff865 into gabrieldemarmiesse:master Dec 9, 2024
21 checks passed
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.

2 participants