6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-12-12 14:17:46 +00:00

improvement: customisable docker build command

This paves the way for `docker buildx build` and better caching.

For instance, with this change you can try out the following plugin,
which should make image building much faster in CI:
https://gist.github.com/regisb/4049622ec4b48cbd48c89ec708dc5252
(not ready for production just yet, we still need to build and push the
images)
This commit is contained in:
Régis Behmo 2023-03-13 18:03:47 +01:00 committed by Régis Behmo
parent ff5357cdc0
commit 28dce8c51a
4 changed files with 16 additions and 5 deletions

View File

@ -0,0 +1 @@
- [Feature] Introduce the `DOCKER_BUILD_COMMAND` which makes it possible to customize the `docker build` command. (by @regisb)

View File

@ -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

View File

@ -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

View File

@ -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: