Skip to content

Commit

Permalink
fix: parsing path for env
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
aarnphm committed Dec 5, 2022
1 parent c91f83f commit 77c2d64
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/bentoml/_internal/bento/build_config.py
Expand Up @@ -26,6 +26,7 @@
from ...exceptions import BentoMLException
from ..utils.dotenv import parse_dotenv
from ..configuration import CLEAN_BENTOML_VERSION
from ..container.generate import BENTO_PATH
from .build_dev_bentoml_whl import build_bentoml_editable_wheel
from ..container.frontend.dockerfile import DistroSpec
from ..container.frontend.dockerfile import get_supported_spec
Expand Down Expand Up @@ -111,12 +112,23 @@ def _convert_env(
if isinstance(env, list):
env_dict: dict[str, str | None] = {}
for envvar in env:
match = re.match(r"^(\w+)=([\w\-,]+)$", envvar)
if not match:
if not re.match(r"^(\w+)=(?:[\.\w\-,\/]+)$", envvar):
raise BentoMLException(
"All value in `env` list must follow format ENV=VALUE"
)
env_key, env_value = match.groups()
env_key, _, env_value = envvar.partition("=")
if os.path.isfile(env_value):
bento_env_path = BENTO_PATH + os.path.abspath(
os.path.expanduser(os.path.expandvars(env_value))
)
logger.info(
"'%s' sets to '%s', which is a file. Make sure to mount this file as a persistent volume to the container when using 'run' command: 'docker run -v %s:%s ...'",
env_key,
env_value,
env_value,
bento_env_path,
)
env_value = bento_env_path
env_dict[env_key] = env_value
return env_dict

Expand Down

0 comments on commit 77c2d64

Please sign in to comment.