Skip to content

Commit

Permalink
[Builder] Support extra & verbose flags (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
urihoenig committed Dec 9, 2020
1 parent 8f7e4ef commit 8d2f857
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions mlrun/builder.py
Expand Up @@ -262,6 +262,8 @@ def build_runtime(runtime, with_mlrun, interactive=False):
interactive=interactive,
name=name,
with_mlrun=with_mlrun,
extra=build.extra,
verbose=runtime.verbose,
)
runtime.status.build_pod = None
if status == "skipped":
Expand Down
2 changes: 2 additions & 0 deletions mlrun/model.py
Expand Up @@ -274,6 +274,7 @@ def __init__(
image=None,
base_image=None,
commands=None,
extra=None,
secret=None,
code_origin=None,
registry=None,
Expand All @@ -285,6 +286,7 @@ def __init__(
self.image = image #: image
self.base_image = base_image #: base_image
self.commands = commands or [] #: commands
self.extra = extra #: extra
self.secret = secret #: secret
self.registry = registry #: registry
self.build_pod = None
Expand Down
1 change: 1 addition & 0 deletions mlrun/run.py
Expand Up @@ -684,6 +684,7 @@ def resolve_nuclio_subkind(kind):
build.code_origin = code_origin
build.base_image = get_in(spec, "spec.build.baseImage")
build.commands = get_in(spec, "spec.build.commands")
build.extra = get_in(spec, "spec.build.extra")
if embed_code:
build.functionSourceCode = get_in(spec, "spec.build.functionSourceCode")
else:
Expand Down
2 changes: 1 addition & 1 deletion mlrun/runtimes/base.py
Expand Up @@ -123,7 +123,7 @@ class BaseRuntime(ModelObj):
kind = "base"
_is_nested = False
_is_remote = False
_dict_fields = ["kind", "metadata", "spec", "status"]
_dict_fields = ["kind", "metadata", "spec", "status", "verbose"]

def __init__(self, metadata=None, spec=None):
self._metadata = None
Expand Down
19 changes: 16 additions & 3 deletions mlrun/runtimes/kubejob.py
Expand Up @@ -80,7 +80,13 @@ def is_deployed(self):
return False

def build_config(
self, image="", base_image=None, commands: list = None, secret=None, source=None
self,
image="",
base_image=None,
commands: list = None,
secret=None,
source=None,
extra=None,
):
if image:
self.spec.build.image = image
Expand All @@ -89,6 +95,8 @@ def build_config(
raise ValueError("commands must be a string list")
self.spec.build.commands = self.spec.build.commands or []
self.spec.build.commands += commands
if extra:
self.spec.build.extra = extra
if secret:
self.spec.build.secret = secret
if base_image:
Expand All @@ -108,7 +116,12 @@ def deploy(self, watch=True, with_mlrun=True, skip_deployed=False, is_kfp=False)
return True

build = self.spec.build
if not build.source and not build.commands and not with_mlrun:
if (
not build.source
and not build.commands
and not build.extra
and not with_mlrun
):
if not self.spec.image:
raise ValueError(
"noting to build and image is not specified, "
Expand All @@ -118,7 +131,7 @@ def deploy(self, watch=True, with_mlrun=True, skip_deployed=False, is_kfp=False)
self.save(versioned=False)
return True

if not build.source and not build.commands and with_mlrun:
if not build.source and not build.commands and not build.extra and with_mlrun:
logger.info(
"running build to add mlrun package, set "
"with_mlrun=False to skip if its already in the image"
Expand Down
6 changes: 5 additions & 1 deletion mlrun/runtimes/sparkjob.py
Expand Up @@ -462,7 +462,11 @@ def _get_driver(self, name, namespace=None):

@property
def is_deployed(self):
if not self.spec.build.source and not self.spec.build.commands:
if (
not self.spec.build.source
and not self.spec.build.commands
and not self.spec.build.extra
):
return True
return super().is_deployed

Expand Down
3 changes: 3 additions & 0 deletions tests/runtimes/test_run.py
Expand Up @@ -29,7 +29,9 @@ def test_new_function_from_runtime():
"description": "",
"build": {"commands": []},
},
"verbose": False,
}

function = mlrun.new_function(runtime=runtime)
assert DeepDiff(runtime, function.to_dict(), ignore_order=True,) == {}

Expand Down Expand Up @@ -60,6 +62,7 @@ def test_new_function_args_without_command():
"description": "",
"build": {"commands": []},
},
"verbose": False,
}
function = mlrun.new_function(runtime=runtime)
assert DeepDiff(runtime, function.to_dict(), ignore_order=True,) == {}

0 comments on commit 8d2f857

Please sign in to comment.