Skip to content

Commit 86ee5dd

Browse files
authored
fix: run post setup commands for codespace (#5414)
* fix: run post setup commands for codespace Signed-off-by: Frost Ming <[email protected]>
1 parent 534c358 commit 86ee5dd

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/bentoml/_internal/cloud/deployment.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def _init_deployment_files(
821821
and rel_path not in DEFAULT_BENTO_BUILD_FILES
822822
):
823823
continue
824-
if rel_path in (REQUIREMENTS_TXT, "setup.sh"):
824+
if rel_path in (REQUIREMENTS_TXT, "setup.sh", "post_setup.sh"):
825825
continue
826826
file_content = open(full_path, "rb").read()
827827
if (
@@ -852,6 +852,11 @@ def _init_deployment_files(
852852
setup_md5 = hashlib.md5(setup_script).hexdigest()
853853
if setup_md5 != pod_files.get("setup.sh", ""):
854854
upload_files.append(("setup.sh", setup_script))
855+
post_setup_script = _build_post_setup_script(bento_dir, svc.image)
856+
if post_setup_script:
857+
post_setup_md5 = hashlib.md5(post_setup_script).hexdigest()
858+
if post_setup_md5 != pod_files.get("post_setup.sh", ""):
859+
upload_files.append(("post_setup.sh", post_setup_script))
855860
self.upload_files(upload_files, console=console)
856861
# Upload a ready flag file after all files are uploaded
857862
self.upload_files([(".project_ready", b"")], console=console)
@@ -892,6 +897,7 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
892897
*DEFAULT_BENTO_BUILD_FILES,
893898
REQUIREMENTS_TXT,
894899
"setup.sh",
900+
"post_setup.sh",
895901
) or bento_spec.includes(rel_path)
896902

897903
console = Console(highlight=False)
@@ -1582,6 +1588,14 @@ def _build_setup_script(bento_dir: str, image: Image | None) -> bytes:
15821588
content += f"apt-get update && apt-get install -y {' '.join(config.docker.system_packages)} || exit 1\n".encode()
15831589
if image and image.commands:
15841590
content += "\n".join(image.commands).encode() + b"\n"
1591+
return content
1592+
1593+
1594+
def _build_post_setup_script(bento_dir: str, image: Image | None) -> bytes:
1595+
content = b""
1596+
config = BentoBuildConfig.from_bento_dir(bento_dir)
1597+
if image and image.post_commands:
1598+
content += "\n".join(image.post_commands).encode() + b"\n"
15851599
if config.docker.setup_script and os.path.exists(
15861600
fullpath := os.path.join(bento_dir, config.docker.setup_script)
15871601
):

src/bentoml/_internal/utils/uri.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def is_safe_url(url: str) -> bool:
6060
parsed = urlparse(url)
6161
except (ValueError, TypeError):
6262
return False
63-
63+
6464
if parsed.scheme not in {"http", "https"}:
6565
return False
6666

@@ -83,7 +83,7 @@ def is_safe_url(url: str) -> bool:
8383
except socket.gaierror:
8484
# DNS resolution failed
8585
return False
86-
86+
8787
for info in addr_info:
8888
try:
8989
ip = ipaddress.ip_address(info[4][0])
@@ -92,5 +92,5 @@ def is_safe_url(url: str) -> bool:
9292
except (ValueError, IndexError):
9393
# Skip malformed addresses
9494
continue
95-
95+
9696
return True

0 commit comments

Comments
 (0)