Skip to content

Commit

Permalink
feat(sdk): add --build-image option to 'kfp components build' to allo…
Browse files Browse the repository at this point in the history
…w users to skip docker build. Fixes #8382 for 1.8 (#8383)
  • Loading branch information
Jonny Browning (Datatonic) authored Oct 24, 2022
1 parent 5abc7c3 commit 8901ba8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sdk/python/kfp/cli/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ def build(components_directory: pathlib.Path = typer.Argument(
False,
help="Set this to true to always generate a Dockerfile"
" as part of the build process"),
build_image: bool = typer.Option(
True, help="Build the container image."
),
push_image: bool = typer.Option(
True, help="Push the built image to its remote repository.")):
"""
Expand All @@ -380,11 +383,11 @@ def build(components_directory: pathlib.Path = typer.Argument(
components_directory))
raise typer.Exit(1)

if engine != _Engine.DOCKER:
if build_image and (engine != _Engine.DOCKER):
_error('Currently, only `docker` is supported for --engine.')
raise typer.Exit(1)

if engine == _Engine.DOCKER:
if build_image and (engine == _Engine.DOCKER):
if not _DOCKER_IS_PRESENT:
_error(
'The `docker` Python package was not found in the current'
Expand All @@ -404,7 +407,9 @@ def build(components_directory: pathlib.Path = typer.Argument(
builder.maybe_generate_requirements_txt()
builder.maybe_generate_dockerignore()
builder.maybe_generate_dockerfile(overwrite_dockerfile=overwrite_dockerfile)
builder.build_image(push_image=push_image)

if build_image:
builder.build_image(push_image=push_image)


if __name__ == '__main__':
Expand Down
14 changes: 14 additions & 0 deletions sdk/python/kfp/cli/components_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,20 @@ def testDockerClientIsCalledToBuildButSkipsPushing(self):
self._docker_client.api.build.assert_called_once()
self._docker_client.images.push.assert_not_called()

def testDockerClientIsNotCalledToBuild(self):
component = _make_component(
func_name='train', target_image='custom-image')
_write_components('components.py', component)

result = self._runner.invoke(
self._app,
['build', str(self._working_dir), '--no-build-image'],
)
self.assertEqual(result.exit_code, 0)

self._docker_client.api.build.assert_not_called()
self._docker_client.images.push.assert_not_called()

@mock.patch('kfp.__version__', '1.2.3')
def testDockerfileIsCreatedCorrectly(self):
component = _make_component(
Expand Down

0 comments on commit 8901ba8

Please sign in to comment.