diff --git a/changelog.d/20230313_172348_regis_docker_optimize.md b/changelog.d/20230313_172348_regis_docker_optimize.md new file mode 100644 index 0000000..811724c --- /dev/null +++ b/changelog.d/20230313_172348_regis_docker_optimize.md @@ -0,0 +1 @@ +- [Feature] Introduce the `DOCKER_BUILD_COMMAND` which makes it possible to customize the `docker build` command. (by @regisb) diff --git a/tutor/commands/k8s.py b/tutor/commands/k8s.py index d26d7cc..db601f4 100644 --- a/tutor/commands/k8s.py +++ b/tutor/commands/k8s.py @@ -1,6 +1,6 @@ from datetime import datetime from time import sleep -from typing import Any, List, Optional, Type, Iterable +from typing import Any, Iterable, List, Optional, Type import click diff --git a/tutor/hooks/catalog.py b/tutor/hooks/catalog.py index 498aebd..9db9d70 100644 --- a/tutor/hooks/catalog.py +++ b/tutor/hooks/catalog.py @@ -282,13 +282,20 @@ class Filters: "config:overrides" ) - #: Declare uniqaue configuration settings that must be saved in the user ``config.yml`` file. This is where + #: Declare unique configuration settings that must be saved in the user ``config.yml`` file. This is where #: you should declare passwords and randomly-generated values that are different from one environment to the next. #: #: :parameter list[tuple[str, ...]] items: list of (name, value) new settings. All #: names must be prefixed with the plugin name in all-caps. CONFIG_UNIQUE: Filter[list[tuple[str, Any]], []] = filters.get("config:unique") + #: Use this filter to modify the ``docker build`` command. For instance, to replace + #: the ``build`` subcommand by ``buildx build``. + #: + #: :parameter list[str] command: the full build command, including options and + #: arguments. Note that these arguments do not include the leading ``docker`` command. + DOCKER_BUILD_COMMAND: Filter[list[str], []] = filters.get("docker:build:command") + #: List of patches that should be inserted in a given location of the templates. The #: filter name must be formatted with the patch name. #: This filter is not so convenient and plugin developers will probably diff --git a/tutor/images.py b/tutor/images.py index b87b550..d0637fe 100644 --- a/tutor/images.py +++ b/tutor/images.py @@ -1,5 +1,5 @@ -from . import fmt, utils -from .types import Config, get_typed +from tutor import fmt, hooks, utils +from tutor.types import Config, get_typed def get_tag(config: Config, name: str) -> str: @@ -9,7 +9,10 @@ def get_tag(config: Config, name: str) -> str: def build(path: str, tag: str, *args: str) -> None: fmt.echo_info(f"Building image {tag}") - utils.docker("build", "-t", tag, *args, path) + command = hooks.Filters.DOCKER_BUILD_COMMAND.apply( + ["build", "-t", tag, *args, path] + ) + utils.docker(*command) def pull(tag: str) -> None: