Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parsing path for env #3314

Merged
merged 1 commit into from Dec 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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