Skip to content

Commit

Permalink
Support bake remote definitions (#656)
Browse files Browse the repository at this point in the history
As seen in https://docs.docker.com/build/bake/remote-definition/
Note that this is experimental (like `buildx.bake`)
  • Loading branch information
rcwbr authored Dec 9, 2024
1 parent a2f95b0 commit b2ff865
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
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
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

0 comments on commit b2ff865

Please sign in to comment.