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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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!

with:
name: Docs
path: site

build-linux-lint:
runs-on: ubuntu-24.04
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ of the file `docs/docs_utils.py` which is responsible for generating the part of
http://localhost:8000


### Use CI-generated docs

The GitHub workflows automatically generate the docs and save them as artifacts. These can be accessed from the Artifacts section of the worfklow view (as [documented here](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/downloading-workflow-artifacts)).

To view them:

1. Download the artifact labeled `Docs`.
1. Extract the contents of the resulting `Docs.zip` file.
1. Open the `index.html` file in a browser.

## Running the tests

Same as before, using `uv` means that you don't need to install anything. Just run
Expand Down
4 changes: 4 additions & 0 deletions python_on_whales/components/buildx/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def bake(
set: Dict[str, str] = {},
variables: Dict[str, str] = {},
stream_logs: bool = False,
remote_definition: Union[str, None] = None,
) -> Union[Dict[str, Dict[str, Dict[str, Any]]], Iterator[str]]:
"""Bake is similar to make, it allows you to build things declared in a file.

Expand All @@ -148,6 +149,7 @@ def bake(
set: A list of overrides in the form `"targetpattern.key=value"`.
variables: A dict containing the values of the variables defined in the
hcl file. See <https://github.com/docker/buildx#hcl-variables-and-functions>
remote_definition: Remote context in which to find bake files

# Returns
The configuration used for the bake (files merged + override with
Expand Down Expand Up @@ -197,6 +199,8 @@ def bake(
for file in to_list(files):
full_cmd.add_simple_arg("--file", file)
full_cmd.add_args_iterable_or_single("--set", format_mapping_for_cli(set))
if remote_definition is not None:
full_cmd.append(remote_definition)
targets = to_list(targets)
env = dict(variables)
if print:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,55 @@ def test_bake_with_variables_2(only_print, monkeypatch):
}


@pytest.mark.usefixtures("with_docker_driver")
@pytest.mark.usefixtures("change_cwd")
@pytest.mark.parametrize("only_print", [True, False])
def test_bake_with_remote_definition(only_print):
config = docker.buildx.bake(
print=only_print,
remote_definition="https://github.com/gabrieldemarmiesse/python-on-whales.git#v0.74.0:tests/python_on_whales/components/bake_tests",
)
assert config == {
"group": {"default": {"targets": ["my_out1", "my_out2"]}},
"target": {
"my_out1": {
"context": "https://github.com/gabrieldemarmiesse/python-on-whales.git#v0.74.0:tests/python_on_whales/components/bake_tests",
"dockerfile": "Dockerfile",
"tags": ["pretty_image1:1.0.0"],
"target": "out1",
},
"my_out2": {
"context": "https://github.com/gabrieldemarmiesse/python-on-whales.git#v0.74.0:tests/python_on_whales/components/bake_tests",
"dockerfile": "Dockerfile",
"tags": ["pretty_image2:1.0.0"],
"target": "out2",
},
},
}


@pytest.mark.usefixtures("with_docker_driver")
@pytest.mark.usefixtures("change_cwd")
@pytest.mark.parametrize("only_print", [True, False])
def test_bake_with_remote_definition_and_target(only_print):
config = docker.buildx.bake(
print=only_print,
targets=["my_out2"],
remote_definition="https://github.com/gabrieldemarmiesse/python-on-whales.git#v0.74.0:tests/python_on_whales/components/bake_tests",
)
assert config == {
"group": {"default": {"targets": ["my_out2"]}},
"target": {
"my_out2": {
"context": "https://github.com/gabrieldemarmiesse/python-on-whales.git#v0.74.0:tests/python_on_whales/components/bake_tests",
"dockerfile": "Dockerfile",
"tags": ["pretty_image2:1.0.0"],
"target": "out2",
},
},
}


@pytest.mark.usefixtures("with_docker_driver")
@pytest.mark.usefixtures("change_cwd")
def test_bake_stream_logs(monkeypatch):
Expand Down