We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Support pushing docker image built by elasticdl client.
to run docker images in cloud environment, we need add step for pushing docker image to registry provided by cloud.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `elasticdl/client/client.py`
Content:
```
1 import argparse
2 import os
3 import inspect
4 import tempfile
5 import time
6 import getpass
7 import sys
8 from string import Template
9 import docker
10 import yaml
11 from kubernetes.client.apis import core_v1_api
12 from kubernetes import config
13 
14 
15 def _m_file_in_docker(model_file):
16     return "/model/" + os.path.basename(model_file)
17 
18 def _build_docker_image(
19     m_file, timestamp, image_base="elasticdl:dev"
20 ):
21     DOCKER_TEMPLATE = """
22 FROM {}
23 COPY {} {}
24 """
25 
26     with tempfile.NamedTemporaryFile(mode="w+", delete=False) as df:
27         df.write(DOCKER_TEMPLATE.format(image_base, m_file, _m_file_in_docker(m_file)))
28 
29     client = docker.APIClient(base_url="unix://var/run/docker.sock")
30     for line in client.build(
31         dockerfile=df.name, path=".", rm=True, tag="elasticdl:dev_" + str(timestamp)
32     ):
33         print(str(line, encoding="utf-8"))
34 
35     # TODO: upload docker image to docker hub.
36 
37 def _gen_master_def(model_file, argv, timestamp):
38     master_yaml = """
39 apiVersion: v1
40 kind: Pod
41 metadata:
42   name: elasticdl-master-{timestamp}
43   labels:
44     purpose: test-command
45 spec:
46   containers:
47   - name: elasticdl-master-{timestamp}
48     image: elasticdl:dev_{timestamp}
49     command: ["python"]
50     args: [
51         "-m", "elasticdl.master.main",
52         "--worker_image", "elasticdl:dev_{timestamp}",
53         "--model_file", "{m_file}"
54     ]
55     imagePullPolicy: Never
56     env:
57     - name: MY_POD_IP
58       valueFrom:
59         fieldRef:
60           fieldPath: status.podIP
61   restartPolicy: Never
62 """ .format(m_file=_m_file_in_docker(model_file), timestamp=timestamp)
63 
64     master_def = yaml.safe_load(master_yaml)
65 
66     # Build master arguments
67     master_def['spec']['containers'][0]['args'].extend(argv)
68     return master_def
69 
70 def _submit(model_file, argv, timestamp):
71     master_def = _gen_master_def(model_file, argv, timestamp)
72     config.load_kube_config()
73     api = core_v1_api.CoreV1Api()
74     resp = api.create_namespaced_pod(body=master_def, namespace="default")
75     print("Master launched. status='%s'" % str(resp.status))
76 
77 def main():
78     parser = argparse.ArgumentParser(description="ElasticDL Client")
79     # Rewrite model_file argument and pass all other arguments to master.
80     parser.add_argument("--model_file", help="Path to Model file", required=True)
81     args, argv = parser.parse_known_args()
82 
83     timestamp = int(round(time.time() * 1000))
84     _build_docker_image(args.model_file, timestamp)
85     _submit(args.model_file, argv, timestamp)    
86 
87 
88 if __name__ == "__main__":
89     main()
90
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/elasticdl/client/client.py b/elasticdl/client/client.py
--- a/elasticdl/client/client.py
+++ b/elasticdl/client/client.py
@@ -16,7 +16,8 @@
     return "/model/" + os.path.basename(model_file)
 
 def _build_docker_image(
-    m_file, timestamp, image_base="elasticdl:dev"
+    m_file, image_name, image_base="elasticdl:dev",
+    repository=None
 ):
     DOCKER_TEMPLATE = """
 FROM {}
@@ -28,13 +29,15 @@
 
     client = docker.APIClient(base_url="unix://var/run/docker.sock")
     for line in client.build(
-        dockerfile=df.name, path=".", rm=True, tag="elasticdl:dev_" + str(timestamp)
+        dockerfile=df.name, path=".", rm=True, tag=image_name
     ):
         print(str(line, encoding="utf-8"))
 
-    # TODO: upload docker image to docker hub.
+    if repository != None:
+        for line in client.push(image_name, stream=True, decode=True):
+            print(line)
 
-def _gen_master_def(model_file, argv, timestamp):
+def _gen_master_def(image_name, model_file, argv, timestamp):
     master_yaml = """
 apiVersion: v1
 kind: Pod
@@ -45,21 +48,21 @@
 spec:
   containers:
   - name: elasticdl-master-{timestamp}
-    image: elasticdl:dev_{timestamp}
+    image: {image_name}
     command: ["python"]
     args: [
         "-m", "elasticdl.master.main",
-        "--worker_image", "elasticdl:dev_{timestamp}",
+        "--worker_image", {image_name},
         "--model_file", "{m_file}"
     ]
-    imagePullPolicy: Never
+    imagePullPolicy: IfNotPresent 
     env:
     - name: MY_POD_IP
       valueFrom:
         fieldRef:
           fieldPath: status.podIP
   restartPolicy: Never
-""" .format(m_file=_m_file_in_docker(model_file), timestamp=timestamp)
+""" .format(m_file=_m_file_in_docker(model_file), image_name=image_name, timestamp=timestamp)
 
     master_def = yaml.safe_load(master_yaml)
 
@@ -67,8 +70,8 @@
     master_def['spec']['containers'][0]['args'].extend(argv)
     return master_def
 
-def _submit(model_file, argv, timestamp):
-    master_def = _gen_master_def(model_file, argv, timestamp)
+def _submit(image_name, model_file, argv, timestamp):
+    master_def = _gen_master_def(image_name, model_file, argv, timestamp)
     config.load_kube_config()
     api = core_v1_api.CoreV1Api()
     resp = api.create_namespaced_pod(body=master_def, namespace="default")
@@ -78,11 +81,15 @@
     parser = argparse.ArgumentParser(description="ElasticDL Client")
     # Rewrite model_file argument and pass all other arguments to master.
     parser.add_argument("--model_file", help="Path to Model file", required=True)
+    parser.add_argument("--image-base", help="Base image containing elasticdl runtime environment.")
+    parser.add_argument("--repository", help="The repository to push docker image to.")
     args, argv = parser.parse_known_args()
 
-    timestamp = int(round(time.time() * 1000))
-    _build_docker_image(args.model_file, timestamp)
-    _submit(args.model_file, argv, timestamp)    
+    timestamp = str(int(round(time.time() * 1000)))
+    image_name = args.image_base + '_' + timestamp 
+    _build_docker_image(args.model_file, image_name, image_base=args.image_base,
+        repository=args.repository)
+    _submit(image_name, args.model_file, argv, timestamp)
 
 
 if __name__ == "__main__":

{"golden_diff": "diff --git a/elasticdl/client/client.py b/elasticdl/client/client.py\n--- a/elasticdl/client/client.py\n+++ b/elasticdl/client/client.py\n@@ -16,7 +16,8 @@\n     return \"/model/\" + os.path.basename(model_file)\n \n def _build_docker_image(\n-    m_file, timestamp, image_base=\"elasticdl:dev\"\n+    m_file, image_name, image_base=\"elasticdl:dev\",\n+    repository=None\n ):\n     DOCKER_TEMPLATE = \"\"\"\n FROM {}\n@@ -28,13 +29,15 @@\n \n     client = docker.APIClient(base_url=\"unix://var/run/docker.sock\")\n     for line in client.build(\n-        dockerfile=df.name, path=\".\", rm=True, tag=\"elasticdl:dev_\" + str(timestamp)\n+        dockerfile=df.name, path=\".\", rm=True, tag=image_name\n     ):\n         print(str(line, encoding=\"utf-8\"))\n \n-    # TODO: upload docker image to docker hub.\n+    if repository != None:\n+        for line in client.push(image_name, stream=True, decode=True):\n+            print(line)\n \n-def _gen_master_def(model_file, argv, timestamp):\n+def _gen_master_def(image_name, model_file, argv, timestamp):\n     master_yaml = \"\"\"\n apiVersion: v1\n kind: Pod\n@@ -45,21 +48,21 @@\n spec:\n   containers:\n   - name: elasticdl-master-{timestamp}\n-    image: elasticdl:dev_{timestamp}\n+    image: {image_name}\n     command: [\"python\"]\n     args: [\n         \"-m\", \"elasticdl.master.main\",\n-        \"--worker_image\", \"elasticdl:dev_{timestamp}\",\n+        \"--worker_image\", {image_name},\n         \"--model_file\", \"{m_file}\"\n     ]\n-    imagePullPolicy: Never\n+    imagePullPolicy: IfNotPresent \n     env:\n     - name: MY_POD_IP\n       valueFrom:\n         fieldRef:\n           fieldPath: status.podIP\n   restartPolicy: Never\n-\"\"\" .format(m_file=_m_file_in_docker(model_file), timestamp=timestamp)\n+\"\"\" .format(m_file=_m_file_in_docker(model_file), image_name=image_name, timestamp=timestamp)\n \n     master_def = yaml.safe_load(master_yaml)\n \n@@ -67,8 +70,8 @@\n     master_def['spec']['containers'][0]['args'].extend(argv)\n     return master_def\n \n-def _submit(model_file, argv, timestamp):\n-    master_def = _gen_master_def(model_file, argv, timestamp)\n+def _submit(image_name, model_file, argv, timestamp):\n+    master_def = _gen_master_def(image_name, model_file, argv, timestamp)\n     config.load_kube_config()\n     api = core_v1_api.CoreV1Api()\n     resp = api.create_namespaced_pod(body=master_def, namespace=\"default\")\n@@ -78,11 +81,15 @@\n     parser = argparse.ArgumentParser(description=\"ElasticDL Client\")\n     # Rewrite model_file argument and pass all other arguments to master.\n     parser.add_argument(\"--model_file\", help=\"Path to Model file\", required=True)\n+    parser.add_argument(\"--image-base\", help=\"Base image containing elasticdl runtime environment.\")\n+    parser.add_argument(\"--repository\", help=\"The repository to push docker image to.\")\n     args, argv = parser.parse_known_args()\n \n-    timestamp = int(round(time.time() * 1000))\n-    _build_docker_image(args.model_file, timestamp)\n-    _submit(args.model_file, argv, timestamp)    \n+    timestamp = str(int(round(time.time() * 1000)))\n+    image_name = args.image_base + '_' + timestamp \n+    _build_docker_image(args.model_file, image_name, image_base=args.image_base,\n+        repository=args.repository)\n+    _submit(image_name, args.model_file, argv, timestamp)\n \n \n if __name__ == \"__main__\":\n", "issue": "Support pushing docker image built by elasticdl client.\nto run docker images in cloud environment, we need add step for pushing docker image to registry provided by cloud.\n", "before_files": [{"content": "import argparse\nimport os\nimport inspect\nimport tempfile\nimport time\nimport getpass\nimport sys\nfrom string import Template\nimport docker\nimport yaml\nfrom kubernetes.client.apis import core_v1_api\nfrom kubernetes import config\n\n\ndef _m_file_in_docker(model_file):\n    return \"/model/\" + os.path.basename(model_file)\n\ndef _build_docker_image(\n    m_file, timestamp, image_base=\"elasticdl:dev\"\n):\n    DOCKER_TEMPLATE = \"\"\"\nFROM {}\nCOPY {} {}\n\"\"\"\n\n    with tempfile.NamedTemporaryFile(mode=\"w+\", delete=False) as df:\n        df.write(DOCKER_TEMPLATE.format(image_base, m_file, _m_file_in_docker(m_file)))\n\n    client = docker.APIClient(base_url=\"unix://var/run/docker.sock\")\n    for line in client.build(\n        dockerfile=df.name, path=\".\", rm=True, tag=\"elasticdl:dev_\" + str(timestamp)\n    ):\n        print(str(line, encoding=\"utf-8\"))\n\n    # TODO: upload docker image to docker hub.\n\ndef _gen_master_def(model_file, argv, timestamp):\n    master_yaml = \"\"\"\napiVersion: v1\nkind: Pod\nmetadata:\n  name: elasticdl-master-{timestamp}\n  labels:\n    purpose: test-command\nspec:\n  containers:\n  - name: elasticdl-master-{timestamp}\n    image: elasticdl:dev_{timestamp}\n    command: [\"python\"]\n    args: [\n        \"-m\", \"elasticdl.master.main\",\n        \"--worker_image\", \"elasticdl:dev_{timestamp}\",\n        \"--model_file\", \"{m_file}\"\n    ]\n    imagePullPolicy: Never\n    env:\n    - name: MY_POD_IP\n      valueFrom:\n        fieldRef:\n          fieldPath: status.podIP\n  restartPolicy: Never\n\"\"\" .format(m_file=_m_file_in_docker(model_file), timestamp=timestamp)\n\n    master_def = yaml.safe_load(master_yaml)\n\n    # Build master arguments\n    master_def['spec']['containers'][0]['args'].extend(argv)\n    return master_def\n\ndef _submit(model_file, argv, timestamp):\n    master_def = _gen_master_def(model_file, argv, timestamp)\n    config.load_kube_config()\n    api = core_v1_api.CoreV1Api()\n    resp = api.create_namespaced_pod(body=master_def, namespace=\"default\")\n    print(\"Master launched. status='%s'\" % str(resp.status))\n\ndef main():\n    parser = argparse.ArgumentParser(description=\"ElasticDL Client\")\n    # Rewrite model_file argument and pass all other arguments to master.\n    parser.add_argument(\"--model_file\", help=\"Path to Model file\", required=True)\n    args, argv = parser.parse_known_args()\n\n    timestamp = int(round(time.time() * 1000))\n    _build_docker_image(args.model_file, timestamp)\n    _submit(args.model_file, argv, timestamp)    \n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "elasticdl/client/client.py"}], "after_files": [{"content": "import argparse\nimport os\nimport inspect\nimport tempfile\nimport time\nimport getpass\nimport sys\nfrom string import Template\nimport docker\nimport yaml\nfrom kubernetes.client.apis import core_v1_api\nfrom kubernetes import config\n\n\ndef _m_file_in_docker(model_file):\n    return \"/model/\" + os.path.basename(model_file)\n\ndef _build_docker_image(\n    m_file, image_name, image_base=\"elasticdl:dev\",\n    repository=None\n):\n    DOCKER_TEMPLATE = \"\"\"\nFROM {}\nCOPY {} {}\n\"\"\"\n\n    with tempfile.NamedTemporaryFile(mode=\"w+\", delete=False) as df:\n        df.write(DOCKER_TEMPLATE.format(image_base, m_file, _m_file_in_docker(m_file)))\n\n    client = docker.APIClient(base_url=\"unix://var/run/docker.sock\")\n    for line in client.build(\n        dockerfile=df.name, path=\".\", rm=True, tag=image_name\n    ):\n        print(str(line, encoding=\"utf-8\"))\n\n    if repository != None:\n        for line in client.push(image_name, stream=True, decode=True):\n            print(line)\n\ndef _gen_master_def(image_name, model_file, argv, timestamp):\n    master_yaml = \"\"\"\napiVersion: v1\nkind: Pod\nmetadata:\n  name: elasticdl-master-{timestamp}\n  labels:\n    purpose: test-command\nspec:\n  containers:\n  - name: elasticdl-master-{timestamp}\n    image: {image_name}\n    command: [\"python\"]\n    args: [\n        \"-m\", \"elasticdl.master.main\",\n        \"--worker_image\", {image_name},\n        \"--model_file\", \"{m_file}\"\n    ]\n    imagePullPolicy: IfNotPresent \n    env:\n    - name: MY_POD_IP\n      valueFrom:\n        fieldRef:\n          fieldPath: status.podIP\n  restartPolicy: Never\n\"\"\" .format(m_file=_m_file_in_docker(model_file), image_name=image_name, timestamp=timestamp)\n\n    master_def = yaml.safe_load(master_yaml)\n\n    # Build master arguments\n    master_def['spec']['containers'][0]['args'].extend(argv)\n    return master_def\n\ndef _submit(image_name, model_file, argv, timestamp):\n    master_def = _gen_master_def(image_name, model_file, argv, timestamp)\n    config.load_kube_config()\n    api = core_v1_api.CoreV1Api()\n    resp = api.create_namespaced_pod(body=master_def, namespace=\"default\")\n    print(\"Master launched. status='%s'\" % str(resp.status))\n\ndef main():\n    parser = argparse.ArgumentParser(description=\"ElasticDL Client\")\n    # Rewrite model_file argument and pass all other arguments to master.\n    parser.add_argument(\"--model_file\", help=\"Path to Model file\", required=True)\n    parser.add_argument(\"--image-base\", help=\"Base image containing elasticdl runtime environment.\")\n    parser.add_argument(\"--repository\", help=\"The repository to push docker image to.\")\n    args, argv = parser.parse_known_args()\n\n    timestamp = str(int(round(time.time() * 1000)))\n    image_name = args.image_base + '_' + timestamp \n    _build_docker_image(args.model_file, image_name, image_base=args.image_base,\n        repository=args.repository)\n    _submit(image_name, args.model_file, argv, timestamp)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "elasticdl/client/client.py"}]}