We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add support for Alpine based docker image
**Is your feature request related to a problem? Please describe.**

Allow users to use `bentoml/model-server:0.7.8-alpine` as the base image, which is currently defined here:  https://github.com/bentoml/BentoML/blob/master/docker/model-server/Dockerfile-alpine

**Describe the solution you'd like**

Improve the `bentoml_init.sh` script to make sure it works on both debian and alpine based docker image.

**Describe alternatives you've considered**
n/a

**Additional context**

See https://github.com/bentoml/BentoML/issues/693


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `bentoml/saved_bundle/bundler.py`
Content:
```
1 # Copyright 2019 Atalaya Tech, Inc.
2 
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 
7 # http://www.apache.org/licenses/LICENSE-2.0
8 
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 import importlib
15 import os
16 import shutil
17 import stat
18 import logging
19 
20 from setuptools import sandbox
21 
22 from bentoml.configuration import _is_pypi_release
23 
24 from bentoml.exceptions import BentoMLException
25 from bentoml.saved_bundle.py_module_utils import copy_used_py_modules
26 from bentoml.saved_bundle.templates import (
27     BENTO_SERVICE_BUNDLE_SETUP_PY_TEMPLATE,
28     MANIFEST_IN_TEMPLATE,
29     MODEL_SERVER_DOCKERFILE_CPU,
30     INIT_PY_TEMPLATE,
31 )
32 from bentoml.utils.usage_stats import track_save
33 from bentoml.saved_bundle.config import SavedBundleConfig
34 
35 
36 DEFAULT_SAVED_BUNDLE_README = """\
37 # Generated BentoService bundle - {}:{}
38 
39 This is a ML Service bundle created with BentoML, it is not recommended to edit
40 code or files contained in this directory. Instead, edit the code that uses BentoML
41 to create this bundle, and save a new BentoService bundle.
42 """
43 
44 logger = logging.getLogger(__name__)
45 
46 
47 def save_to_dir(bento_service, path, version=None, silent=False):
48     """Save given BentoService along with all its artifacts, source code and
49     dependencies to target file path, assuming path exist and empty. If target path
50     is not empty, this call may override existing files in the given path.
51 
52     :param bento_service (bentoml.service.BentoService): a Bento Service instance
53     :param path (str): Destination of where the bento service will be saved
54     :param version (str): Override the service version with given version string
55     :param silent (boolean): whether to hide the log message showing target save path
56     """
57     track_save(bento_service)
58 
59     from bentoml.service import BentoService
60 
61     if not isinstance(bento_service, BentoService):
62         raise BentoMLException(
63             "save_to_dir only work with instance of custom BentoService class"
64         )
65 
66     if version is not None:
67         # If parameter version provided, set bento_service version
68         # Otherwise it will bet set the first time the `version` property get accessed
69         bento_service.set_version(version)
70 
71     if not os.path.exists(path):
72         raise BentoMLException("Directory '{}' not found".format(path))
73 
74     for artifact in bento_service._artifacts:
75         if artifact.name not in bento_service._packed_artifacts:
76             logger.warning(
77                 "Missing declared artifact '%s' for BentoService '%s'",
78                 artifact.name,
79                 bento_service.name,
80             )
81 
82     module_base_path = os.path.join(path, bento_service.name)
83     try:
84         os.mkdir(module_base_path)
85     except FileExistsError:
86         raise BentoMLException(
87             f"Existing module file found for BentoService {bento_service.name}"
88         )
89 
90     # write README.md with custom BentoService's docstring if presented
91     saved_bundle_readme = DEFAULT_SAVED_BUNDLE_README.format(
92         bento_service.name, bento_service.version
93     )
94     if bento_service.__class__.__doc__:
95         saved_bundle_readme += "\n"
96         saved_bundle_readme += bento_service.__class__.__doc__.strip()
97 
98     with open(os.path.join(path, "README.md"), "w") as f:
99         f.write(saved_bundle_readme)
100 
101     # save all model artifacts to 'base_path/name/artifacts/' directory
102     if bento_service.artifacts:
103         bento_service.artifacts.save(module_base_path)
104 
105     # write conda environment, requirement.txt
106     bento_service.env.save(path, bento_service)
107 
108     # TODO: add bentoml.find_packages helper for more fine grained control over this
109     # process, e.g. packages=find_packages(base, [], exclude=[], used_module_only=True)
110     # copy over all custom model code
111     module_name, module_file = copy_used_py_modules(
112         bento_service.__class__.__module__, os.path.join(path, bento_service.name)
113     )
114 
115     # create __init__.py
116     with open(os.path.join(path, bento_service.name, "__init__.py"), "w") as f:
117         f.write(
118             INIT_PY_TEMPLATE.format(
119                 service_name=bento_service.name,
120                 module_name=module_name,
121                 pypi_package_version=bento_service.version,
122             )
123         )
124 
125     # write setup.py, this make saved BentoService bundle pip installable
126     setup_py_content = BENTO_SERVICE_BUNDLE_SETUP_PY_TEMPLATE.format(
127         name=bento_service.name,
128         pypi_package_version=bento_service.version,
129         long_description=saved_bundle_readme,
130     )
131     with open(os.path.join(path, "setup.py"), "w") as f:
132         f.write(setup_py_content)
133 
134     with open(os.path.join(path, "MANIFEST.in"), "w") as f:
135         f.write(MANIFEST_IN_TEMPLATE.format(service_name=bento_service.name))
136 
137     # write Dockerfile
138     with open(os.path.join(path, "Dockerfile"), "w") as f:
139         f.write(
140             MODEL_SERVER_DOCKERFILE_CPU.format(
141                 docker_base_image=bento_service._env._docker_base_image
142             )
143         )
144 
145     # Copy docker-entrypoint.sh
146     docker_entrypoint_sh_file_src = os.path.join(
147         os.path.dirname(__file__), "docker-entrypoint.sh"
148     )
149     docker_entrypoint_sh_file_dst = os.path.join(path, "docker-entrypoint.sh")
150     shutil.copyfile(docker_entrypoint_sh_file_src, docker_entrypoint_sh_file_dst)
151     # chmod +x docker-entrypoint.sh
152     st = os.stat(docker_entrypoint_sh_file_dst)
153     os.chmod(docker_entrypoint_sh_file_dst, st.st_mode | stat.S_IEXEC)
154 
155     # copy bentoml-init.sh for install targz bundles
156     bentoml_init_sh_file_src = os.path.join(
157         os.path.dirname(__file__), "bentoml-init.sh"
158     )
159     bentoml_init_sh_file_dst = os.path.join(path, "bentoml-init.sh")
160     shutil.copyfile(bentoml_init_sh_file_src, bentoml_init_sh_file_dst)
161     # chmod +x bentoml_init_script file
162     st = os.stat(bentoml_init_sh_file_dst)
163     os.chmod(bentoml_init_sh_file_dst, st.st_mode | stat.S_IEXEC)
164 
165     # write bentoml.yml
166     config = SavedBundleConfig(bento_service)
167     config["metadata"].update({"module_name": module_name, "module_file": module_file})
168 
169     config.write_to_path(path)
170     # Also write bentoml.yml to module base path to make it accessible
171     # as package data after pip installed as a python package
172     config.write_to_path(module_base_path)
173 
174     bundled_pip_dependencies_path = os.path.join(path, 'bundled_pip_dependencies')
175     _bundle_local_bentoml_if_installed_from_source(bundled_pip_dependencies_path)
176 
177     if not silent:
178         logger.info(
179             "BentoService bundle '%s:%s' created at: %s",
180             bento_service.name,
181             bento_service.version,
182             path,
183         )
184 
185 
186 def _bundle_local_bentoml_if_installed_from_source(target_path):
187     """
188     if bentoml is installed in editor mode(pip install -e), this will build a source
189     distribution with the local bentoml fork and add it to saved BentoService bundle
190     path under bundled_pip_dependencies directory
191     """
192 
193     # Find bentoml module path
194     (module_location,) = importlib.util.find_spec('bentoml').submodule_search_locations
195 
196     bentoml_setup_py = os.path.abspath(os.path.join(module_location, '..', 'setup.py'))
197 
198     # this is for BentoML developer to create BentoService containing custom develop
199     # branches of BentoML library, it is True only when BentoML module is installed in
200     # development mode via "pip install --editable ."
201     if not _is_pypi_release() and os.path.isfile(bentoml_setup_py):
202         logger.info(
203             "Detect BentoML installed in development model, copying local BentoML "
204             "module file to target saved bundle path"
205         )
206 
207         # Create tmp directory inside bentoml module for storing the bundled
208         # targz file. Since dist-dir can only be inside of the module directory
209         bundle_dir_name = '__bentoml_tmp_sdist_build'
210         source_dir = os.path.abspath(
211             os.path.join(module_location, '..', bundle_dir_name)
212         )
213 
214         if os.path.isdir(source_dir):
215             shutil.rmtree(source_dir, ignore_errors=True)
216         os.mkdir(source_dir)
217 
218         sandbox.run_setup(
219             bentoml_setup_py,
220             ['sdist', '--format', 'gztar', '--dist-dir', bundle_dir_name],
221         )
222 
223         # copy the generated targz to saved bundle directory and remove it from
224         # bentoml module directory
225         shutil.copytree(source_dir, target_path)
226 
227         # clean up sdist build files
228         shutil.rmtree(source_dir)
229
```
--- 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/bentoml/saved_bundle/bundler.py b/bentoml/saved_bundle/bundler.py
--- a/bentoml/saved_bundle/bundler.py
+++ b/bentoml/saved_bundle/bundler.py
@@ -135,6 +135,7 @@
         f.write(MANIFEST_IN_TEMPLATE.format(service_name=bento_service.name))
 
     # write Dockerfile
+    logger.debug("Using Docker Base Image %s", bento_service._env._docker_base_image)
     with open(os.path.join(path, "Dockerfile"), "w") as f:
         f.write(
             MODEL_SERVER_DOCKERFILE_CPU.format(

{"golden_diff": "diff --git a/bentoml/saved_bundle/bundler.py b/bentoml/saved_bundle/bundler.py\n--- a/bentoml/saved_bundle/bundler.py\n+++ b/bentoml/saved_bundle/bundler.py\n@@ -135,6 +135,7 @@\n         f.write(MANIFEST_IN_TEMPLATE.format(service_name=bento_service.name))\n \n     # write Dockerfile\n+    logger.debug(\"Using Docker Base Image %s\", bento_service._env._docker_base_image)\n     with open(os.path.join(path, \"Dockerfile\"), \"w\") as f:\n         f.write(\n             MODEL_SERVER_DOCKERFILE_CPU.format(\n", "issue": "Add support for Alpine based docker image\n**Is your feature request related to a problem? Please describe.**\r\n\r\nAllow users to use `bentoml/model-server:0.7.8-alpine` as the base image, which is currently defined here:  https://github.com/bentoml/BentoML/blob/master/docker/model-server/Dockerfile-alpine\r\n\r\n**Describe the solution you'd like**\r\n\r\nImprove the `bentoml_init.sh` script to make sure it works on both debian and alpine based docker image.\r\n\r\n**Describe alternatives you've considered**\r\nn/a\r\n\r\n**Additional context**\r\n\r\nSee https://github.com/bentoml/BentoML/issues/693\r\n\n", "before_files": [{"content": "# Copyright 2019 Atalaya Tech, Inc.\n\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n# http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nimport importlib\nimport os\nimport shutil\nimport stat\nimport logging\n\nfrom setuptools import sandbox\n\nfrom bentoml.configuration import _is_pypi_release\n\nfrom bentoml.exceptions import BentoMLException\nfrom bentoml.saved_bundle.py_module_utils import copy_used_py_modules\nfrom bentoml.saved_bundle.templates import (\n    BENTO_SERVICE_BUNDLE_SETUP_PY_TEMPLATE,\n    MANIFEST_IN_TEMPLATE,\n    MODEL_SERVER_DOCKERFILE_CPU,\n    INIT_PY_TEMPLATE,\n)\nfrom bentoml.utils.usage_stats import track_save\nfrom bentoml.saved_bundle.config import SavedBundleConfig\n\n\nDEFAULT_SAVED_BUNDLE_README = \"\"\"\\\n# Generated BentoService bundle - {}:{}\n\nThis is a ML Service bundle created with BentoML, it is not recommended to edit\ncode or files contained in this directory. Instead, edit the code that uses BentoML\nto create this bundle, and save a new BentoService bundle.\n\"\"\"\n\nlogger = logging.getLogger(__name__)\n\n\ndef save_to_dir(bento_service, path, version=None, silent=False):\n    \"\"\"Save given BentoService along with all its artifacts, source code and\n    dependencies to target file path, assuming path exist and empty. If target path\n    is not empty, this call may override existing files in the given path.\n\n    :param bento_service (bentoml.service.BentoService): a Bento Service instance\n    :param path (str): Destination of where the bento service will be saved\n    :param version (str): Override the service version with given version string\n    :param silent (boolean): whether to hide the log message showing target save path\n    \"\"\"\n    track_save(bento_service)\n\n    from bentoml.service import BentoService\n\n    if not isinstance(bento_service, BentoService):\n        raise BentoMLException(\n            \"save_to_dir only work with instance of custom BentoService class\"\n        )\n\n    if version is not None:\n        # If parameter version provided, set bento_service version\n        # Otherwise it will bet set the first time the `version` property get accessed\n        bento_service.set_version(version)\n\n    if not os.path.exists(path):\n        raise BentoMLException(\"Directory '{}' not found\".format(path))\n\n    for artifact in bento_service._artifacts:\n        if artifact.name not in bento_service._packed_artifacts:\n            logger.warning(\n                \"Missing declared artifact '%s' for BentoService '%s'\",\n                artifact.name,\n                bento_service.name,\n            )\n\n    module_base_path = os.path.join(path, bento_service.name)\n    try:\n        os.mkdir(module_base_path)\n    except FileExistsError:\n        raise BentoMLException(\n            f\"Existing module file found for BentoService {bento_service.name}\"\n        )\n\n    # write README.md with custom BentoService's docstring if presented\n    saved_bundle_readme = DEFAULT_SAVED_BUNDLE_README.format(\n        bento_service.name, bento_service.version\n    )\n    if bento_service.__class__.__doc__:\n        saved_bundle_readme += \"\\n\"\n        saved_bundle_readme += bento_service.__class__.__doc__.strip()\n\n    with open(os.path.join(path, \"README.md\"), \"w\") as f:\n        f.write(saved_bundle_readme)\n\n    # save all model artifacts to 'base_path/name/artifacts/' directory\n    if bento_service.artifacts:\n        bento_service.artifacts.save(module_base_path)\n\n    # write conda environment, requirement.txt\n    bento_service.env.save(path, bento_service)\n\n    # TODO: add bentoml.find_packages helper for more fine grained control over this\n    # process, e.g. packages=find_packages(base, [], exclude=[], used_module_only=True)\n    # copy over all custom model code\n    module_name, module_file = copy_used_py_modules(\n        bento_service.__class__.__module__, os.path.join(path, bento_service.name)\n    )\n\n    # create __init__.py\n    with open(os.path.join(path, bento_service.name, \"__init__.py\"), \"w\") as f:\n        f.write(\n            INIT_PY_TEMPLATE.format(\n                service_name=bento_service.name,\n                module_name=module_name,\n                pypi_package_version=bento_service.version,\n            )\n        )\n\n    # write setup.py, this make saved BentoService bundle pip installable\n    setup_py_content = BENTO_SERVICE_BUNDLE_SETUP_PY_TEMPLATE.format(\n        name=bento_service.name,\n        pypi_package_version=bento_service.version,\n        long_description=saved_bundle_readme,\n    )\n    with open(os.path.join(path, \"setup.py\"), \"w\") as f:\n        f.write(setup_py_content)\n\n    with open(os.path.join(path, \"MANIFEST.in\"), \"w\") as f:\n        f.write(MANIFEST_IN_TEMPLATE.format(service_name=bento_service.name))\n\n    # write Dockerfile\n    with open(os.path.join(path, \"Dockerfile\"), \"w\") as f:\n        f.write(\n            MODEL_SERVER_DOCKERFILE_CPU.format(\n                docker_base_image=bento_service._env._docker_base_image\n            )\n        )\n\n    # Copy docker-entrypoint.sh\n    docker_entrypoint_sh_file_src = os.path.join(\n        os.path.dirname(__file__), \"docker-entrypoint.sh\"\n    )\n    docker_entrypoint_sh_file_dst = os.path.join(path, \"docker-entrypoint.sh\")\n    shutil.copyfile(docker_entrypoint_sh_file_src, docker_entrypoint_sh_file_dst)\n    # chmod +x docker-entrypoint.sh\n    st = os.stat(docker_entrypoint_sh_file_dst)\n    os.chmod(docker_entrypoint_sh_file_dst, st.st_mode | stat.S_IEXEC)\n\n    # copy bentoml-init.sh for install targz bundles\n    bentoml_init_sh_file_src = os.path.join(\n        os.path.dirname(__file__), \"bentoml-init.sh\"\n    )\n    bentoml_init_sh_file_dst = os.path.join(path, \"bentoml-init.sh\")\n    shutil.copyfile(bentoml_init_sh_file_src, bentoml_init_sh_file_dst)\n    # chmod +x bentoml_init_script file\n    st = os.stat(bentoml_init_sh_file_dst)\n    os.chmod(bentoml_init_sh_file_dst, st.st_mode | stat.S_IEXEC)\n\n    # write bentoml.yml\n    config = SavedBundleConfig(bento_service)\n    config[\"metadata\"].update({\"module_name\": module_name, \"module_file\": module_file})\n\n    config.write_to_path(path)\n    # Also write bentoml.yml to module base path to make it accessible\n    # as package data after pip installed as a python package\n    config.write_to_path(module_base_path)\n\n    bundled_pip_dependencies_path = os.path.join(path, 'bundled_pip_dependencies')\n    _bundle_local_bentoml_if_installed_from_source(bundled_pip_dependencies_path)\n\n    if not silent:\n        logger.info(\n            \"BentoService bundle '%s:%s' created at: %s\",\n            bento_service.name,\n            bento_service.version,\n            path,\n        )\n\n\ndef _bundle_local_bentoml_if_installed_from_source(target_path):\n    \"\"\"\n    if bentoml is installed in editor mode(pip install -e), this will build a source\n    distribution with the local bentoml fork and add it to saved BentoService bundle\n    path under bundled_pip_dependencies directory\n    \"\"\"\n\n    # Find bentoml module path\n    (module_location,) = importlib.util.find_spec('bentoml').submodule_search_locations\n\n    bentoml_setup_py = os.path.abspath(os.path.join(module_location, '..', 'setup.py'))\n\n    # this is for BentoML developer to create BentoService containing custom develop\n    # branches of BentoML library, it is True only when BentoML module is installed in\n    # development mode via \"pip install --editable .\"\n    if not _is_pypi_release() and os.path.isfile(bentoml_setup_py):\n        logger.info(\n            \"Detect BentoML installed in development model, copying local BentoML \"\n            \"module file to target saved bundle path\"\n        )\n\n        # Create tmp directory inside bentoml module for storing the bundled\n        # targz file. Since dist-dir can only be inside of the module directory\n        bundle_dir_name = '__bentoml_tmp_sdist_build'\n        source_dir = os.path.abspath(\n            os.path.join(module_location, '..', bundle_dir_name)\n        )\n\n        if os.path.isdir(source_dir):\n            shutil.rmtree(source_dir, ignore_errors=True)\n        os.mkdir(source_dir)\n\n        sandbox.run_setup(\n            bentoml_setup_py,\n            ['sdist', '--format', 'gztar', '--dist-dir', bundle_dir_name],\n        )\n\n        # copy the generated targz to saved bundle directory and remove it from\n        # bentoml module directory\n        shutil.copytree(source_dir, target_path)\n\n        # clean up sdist build files\n        shutil.rmtree(source_dir)\n", "path": "bentoml/saved_bundle/bundler.py"}], "after_files": [{"content": "# Copyright 2019 Atalaya Tech, Inc.\n\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n# http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nimport importlib\nimport os\nimport shutil\nimport stat\nimport logging\n\nfrom setuptools import sandbox\n\nfrom bentoml.configuration import _is_pypi_release\n\nfrom bentoml.exceptions import BentoMLException\nfrom bentoml.saved_bundle.py_module_utils import copy_used_py_modules\nfrom bentoml.saved_bundle.templates import (\n    BENTO_SERVICE_BUNDLE_SETUP_PY_TEMPLATE,\n    MANIFEST_IN_TEMPLATE,\n    MODEL_SERVER_DOCKERFILE_CPU,\n    INIT_PY_TEMPLATE,\n)\nfrom bentoml.utils.usage_stats import track_save\nfrom bentoml.saved_bundle.config import SavedBundleConfig\n\n\nDEFAULT_SAVED_BUNDLE_README = \"\"\"\\\n# Generated BentoService bundle - {}:{}\n\nThis is a ML Service bundle created with BentoML, it is not recommended to edit\ncode or files contained in this directory. Instead, edit the code that uses BentoML\nto create this bundle, and save a new BentoService bundle.\n\"\"\"\n\nlogger = logging.getLogger(__name__)\n\n\ndef save_to_dir(bento_service, path, version=None, silent=False):\n    \"\"\"Save given BentoService along with all its artifacts, source code and\n    dependencies to target file path, assuming path exist and empty. If target path\n    is not empty, this call may override existing files in the given path.\n\n    :param bento_service (bentoml.service.BentoService): a Bento Service instance\n    :param path (str): Destination of where the bento service will be saved\n    :param version (str): Override the service version with given version string\n    :param silent (boolean): whether to hide the log message showing target save path\n    \"\"\"\n    track_save(bento_service)\n\n    from bentoml.service import BentoService\n\n    if not isinstance(bento_service, BentoService):\n        raise BentoMLException(\n            \"save_to_dir only work with instance of custom BentoService class\"\n        )\n\n    if version is not None:\n        # If parameter version provided, set bento_service version\n        # Otherwise it will bet set the first time the `version` property get accessed\n        bento_service.set_version(version)\n\n    if not os.path.exists(path):\n        raise BentoMLException(\"Directory '{}' not found\".format(path))\n\n    for artifact in bento_service._artifacts:\n        if artifact.name not in bento_service._packed_artifacts:\n            logger.warning(\n                \"Missing declared artifact '%s' for BentoService '%s'\",\n                artifact.name,\n                bento_service.name,\n            )\n\n    module_base_path = os.path.join(path, bento_service.name)\n    try:\n        os.mkdir(module_base_path)\n    except FileExistsError:\n        raise BentoMLException(\n            f\"Existing module file found for BentoService {bento_service.name}\"\n        )\n\n    # write README.md with custom BentoService's docstring if presented\n    saved_bundle_readme = DEFAULT_SAVED_BUNDLE_README.format(\n        bento_service.name, bento_service.version\n    )\n    if bento_service.__class__.__doc__:\n        saved_bundle_readme += \"\\n\"\n        saved_bundle_readme += bento_service.__class__.__doc__.strip()\n\n    with open(os.path.join(path, \"README.md\"), \"w\") as f:\n        f.write(saved_bundle_readme)\n\n    # save all model artifacts to 'base_path/name/artifacts/' directory\n    if bento_service.artifacts:\n        bento_service.artifacts.save(module_base_path)\n\n    # write conda environment, requirement.txt\n    bento_service.env.save(path, bento_service)\n\n    # TODO: add bentoml.find_packages helper for more fine grained control over this\n    # process, e.g. packages=find_packages(base, [], exclude=[], used_module_only=True)\n    # copy over all custom model code\n    module_name, module_file = copy_used_py_modules(\n        bento_service.__class__.__module__, os.path.join(path, bento_service.name)\n    )\n\n    # create __init__.py\n    with open(os.path.join(path, bento_service.name, \"__init__.py\"), \"w\") as f:\n        f.write(\n            INIT_PY_TEMPLATE.format(\n                service_name=bento_service.name,\n                module_name=module_name,\n                pypi_package_version=bento_service.version,\n            )\n        )\n\n    # write setup.py, this make saved BentoService bundle pip installable\n    setup_py_content = BENTO_SERVICE_BUNDLE_SETUP_PY_TEMPLATE.format(\n        name=bento_service.name,\n        pypi_package_version=bento_service.version,\n        long_description=saved_bundle_readme,\n    )\n    with open(os.path.join(path, \"setup.py\"), \"w\") as f:\n        f.write(setup_py_content)\n\n    with open(os.path.join(path, \"MANIFEST.in\"), \"w\") as f:\n        f.write(MANIFEST_IN_TEMPLATE.format(service_name=bento_service.name))\n\n    # write Dockerfile\n    logger.debug(\"Using Docker Base Image %s\", bento_service._env._docker_base_image)\n    with open(os.path.join(path, \"Dockerfile\"), \"w\") as f:\n        f.write(\n            MODEL_SERVER_DOCKERFILE_CPU.format(\n                docker_base_image=bento_service._env._docker_base_image\n            )\n        )\n\n    # Copy docker-entrypoint.sh\n    docker_entrypoint_sh_file_src = os.path.join(\n        os.path.dirname(__file__), \"docker-entrypoint.sh\"\n    )\n    docker_entrypoint_sh_file_dst = os.path.join(path, \"docker-entrypoint.sh\")\n    shutil.copyfile(docker_entrypoint_sh_file_src, docker_entrypoint_sh_file_dst)\n    # chmod +x docker-entrypoint.sh\n    st = os.stat(docker_entrypoint_sh_file_dst)\n    os.chmod(docker_entrypoint_sh_file_dst, st.st_mode | stat.S_IEXEC)\n\n    # copy bentoml-init.sh for install targz bundles\n    bentoml_init_sh_file_src = os.path.join(\n        os.path.dirname(__file__), \"bentoml-init.sh\"\n    )\n    bentoml_init_sh_file_dst = os.path.join(path, \"bentoml-init.sh\")\n    shutil.copyfile(bentoml_init_sh_file_src, bentoml_init_sh_file_dst)\n    # chmod +x bentoml_init_script file\n    st = os.stat(bentoml_init_sh_file_dst)\n    os.chmod(bentoml_init_sh_file_dst, st.st_mode | stat.S_IEXEC)\n\n    # write bentoml.yml\n    config = SavedBundleConfig(bento_service)\n    config[\"metadata\"].update({\"module_name\": module_name, \"module_file\": module_file})\n\n    config.write_to_path(path)\n    # Also write bentoml.yml to module base path to make it accessible\n    # as package data after pip installed as a python package\n    config.write_to_path(module_base_path)\n\n    bundled_pip_dependencies_path = os.path.join(path, 'bundled_pip_dependencies')\n    _bundle_local_bentoml_if_installed_from_source(bundled_pip_dependencies_path)\n\n    if not silent:\n        logger.info(\n            \"BentoService bundle '%s:%s' created at: %s\",\n            bento_service.name,\n            bento_service.version,\n            path,\n        )\n\n\ndef _bundle_local_bentoml_if_installed_from_source(target_path):\n    \"\"\"\n    if bentoml is installed in editor mode(pip install -e), this will build a source\n    distribution with the local bentoml fork and add it to saved BentoService bundle\n    path under bundled_pip_dependencies directory\n    \"\"\"\n\n    # Find bentoml module path\n    (module_location,) = importlib.util.find_spec('bentoml').submodule_search_locations\n\n    bentoml_setup_py = os.path.abspath(os.path.join(module_location, '..', 'setup.py'))\n\n    # this is for BentoML developer to create BentoService containing custom develop\n    # branches of BentoML library, it is True only when BentoML module is installed in\n    # development mode via \"pip install --editable .\"\n    if not _is_pypi_release() and os.path.isfile(bentoml_setup_py):\n        logger.info(\n            \"Detect BentoML installed in development model, copying local BentoML \"\n            \"module file to target saved bundle path\"\n        )\n\n        # Create tmp directory inside bentoml module for storing the bundled\n        # targz file. Since dist-dir can only be inside of the module directory\n        bundle_dir_name = '__bentoml_tmp_sdist_build'\n        source_dir = os.path.abspath(\n            os.path.join(module_location, '..', bundle_dir_name)\n        )\n\n        if os.path.isdir(source_dir):\n            shutil.rmtree(source_dir, ignore_errors=True)\n        os.mkdir(source_dir)\n\n        sandbox.run_setup(\n            bentoml_setup_py,\n            ['sdist', '--format', 'gztar', '--dist-dir', bundle_dir_name],\n        )\n\n        # copy the generated targz to saved bundle directory and remove it from\n        # bentoml module directory\n        shutil.copytree(source_dir, target_path)\n\n        # clean up sdist build files\n        shutil.rmtree(source_dir)\n", "path": "bentoml/saved_bundle/bundler.py"}]}