Repository: sql-machine-learning/elasticdl

Issue:
How to use  `--cluser_spec`
Need to push spec.py in docker image when using elasticdl client, but also need it when submitting a job.


Discussion:

Resolving patch:
diff --git a/elasticdl/python/master/master.py b/elasticdl/python/master/master.py
--- a/elasticdl/python/master/master.py
+++ b/elasticdl/python/master/master.py
@@ -52,6 +52,7 @@
 )
 from elasticdl_client.common.constants import (
     BashCommandTemplate,
+    ClusterSpecConfig,
     DistributionStrategy,
 )
 
@@ -502,6 +503,7 @@ def _create_instance_manager(self, args):
 
             kwargs = get_dict_from_params_str(args.aux_params)
             disable_relaunch = kwargs.get("disable_relaunch", False)
+            cluster_spec = self._get_image_cluster_spec(args.cluster_spec)
 
             instance_manager = InstanceManager(
                 self.task_d,
@@ -523,7 +525,7 @@ def _create_instance_manager(self, args):
                 volume=args.volume,
                 image_pull_policy=args.image_pull_policy,
                 restart_policy=args.restart_policy,
-                cluster_spec=args.cluster_spec,
+                cluster_spec=cluster_spec,
                 envs=env,
                 expose_ports=self.distribution_strategy
                 == DistributionStrategy.ALLREDUCE,
@@ -533,6 +535,15 @@ def _create_instance_manager(self, args):
 
         return instance_manager
 
+    def _get_image_cluster_spec(self, cluster_spec):
+        if cluster_spec:
+            filename = os.path.basename(cluster_spec)
+            image_cluster_spec = os.path.join(
+                ClusterSpecConfig.CLUSTER_SPEC_DIR, filename
+            )
+            return image_cluster_spec
+        return cluster_spec
+
     def _check_timeout_tasks(self):
         while True:
             doing_tasks = self.task_d._doing.copy()
diff --git a/elasticdl_client/api.py b/elasticdl_client/api.py
--- a/elasticdl_client/api.py
+++ b/elasticdl_client/api.py
@@ -23,7 +23,10 @@
     parse_envs,
     wrap_python_args_with_string,
 )
-from elasticdl_client.common.constants import BashCommandTemplate
+from elasticdl_client.common.constants import (
+    BashCommandTemplate,
+    ClusterSpecConfig,
+)
 from elasticdl_client.common.log_utils import default_logger as logger
 
 
@@ -62,7 +65,7 @@ def init_zoo(args):
  --extra-index-url={{ EXTRA_PYPI_INDEX }}
 
 {% if CLUSTER_SPEC_NAME  %}\
-COPY ./{{ CLUSTER_SPEC_NAME }} /cluster_spec/{{ CLUSTER_SPEC_NAME }}\
+COPY ./{{ CLUSTER_SPEC_NAME }} {{CLUSTER_SPEC_DIR}}/{{ CLUSTER_SPEC_NAME }}\
 {% endif %}
 """
     template = Template(tmpl_str)
@@ -70,6 +73,7 @@ def init_zoo(args):
         BASE_IMAGE=args.base_image,
         EXTRA_PYPI_INDEX=args.extra_pypi_index,
         CLUSTER_SPEC_NAME=cluster_spec_name,
+        CLUSTER_SPEC_DIR=ClusterSpecConfig.CLUSTER_SPEC_DIR,
         MODEL_ZOO_PATH=args.model_zoo,
     )
 
diff --git a/elasticdl_client/common/constants.py b/elasticdl_client/common/constants.py
--- a/elasticdl_client/common/constants.py
+++ b/elasticdl_client/common/constants.py
@@ -21,3 +21,7 @@ class DistributionStrategy(object):
 class BashCommandTemplate(object):
     REDIRECTION = " 2>&1 | tee {}"
     SET_PIPEFAIL = "set -o pipefail;"
+
+
+class ClusterSpecConfig(object):
+    CLUSTER_SPEC_DIR = "/cluster_spec"


Test patch: