diff --git a/kubeflow/fairing/builders/cluster/cluster.py b/kubeflow/fairing/builders/cluster/cluster.py index 37e36b30..36a7b08e 100644 --- a/kubeflow/fairing/builders/cluster/cluster.py +++ b/kubeflow/fairing/builders/cluster/cluster.py @@ -27,7 +27,9 @@ def __init__(self, namespace=None, dockerfile_path=None, cleanup=False, - executable_path_prefix=None): + executable_path_prefix=None, + cache=False, + single_snapshot=True): super().__init__( registry=registry, image_name=image_name, @@ -43,6 +45,8 @@ def __init__(self, self.namespace = namespace or utils.get_default_target_namespace() self.cleanup = cleanup self.executable_path_prefix = executable_path_prefix + self.cache = cache + self.single_snapshot = single_snapshot def build(self): logging.info("Building image using cluster builder.") @@ -68,7 +72,7 @@ def build(self): labels = {'fairing-builder': 'kaniko'} labels['fairing-build-id'] = str(uuid.uuid1()) pod_spec = self.context_source.generate_pod_spec( - self.image_tag, self.push) + self.image_tag, self.push, self.cache, self.single_snapshot) for fn in self.pod_spec_mutators: fn(self.manager, pod_spec, self.namespace) diff --git a/kubeflow/fairing/builders/cluster/minio_context.py b/kubeflow/fairing/builders/cluster/minio_context.py index efa87997..1284c488 100644 --- a/kubeflow/fairing/builders/cluster/minio_context.py +++ b/kubeflow/fairing/builders/cluster/minio_context.py @@ -32,7 +32,7 @@ def upload_context(self, context_filename): bucket_name=bucket_name, file_to_upload=context_filename) - def generate_pod_spec(self, image_name, push): # pylint: disable=arguments-differ + def generate_pod_spec(self, image_name, push, cache=False, single_snapshot=True): # pylint: disable=arguments-differ """ :param image_name: name of image to be built :param push: whether to push image to given registry or not @@ -40,12 +40,17 @@ def generate_pod_spec(self, image_name, push): # pylint: disable=arguments-diff args = [ "--dockerfile=Dockerfile", "--destination=" + image_name, - "--context=" + self.uploaded_context_url, - "--single-snapshot" + "--context=" + self.uploaded_context_url ] + if single_snapshot: + args.append("--single-snapshot") + if not push: args.append("--no-push") + if cache: + args.append("--cache=true") + return client.V1PodSpec( containers=[ client.V1Container(