Skip to content

fix: run post setup commands for codespace #5414

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

Merged
merged 1 commit into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/bentoml/_internal/cloud/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def _init_deployment_files(
and rel_path not in DEFAULT_BENTO_BUILD_FILES
):
continue
if rel_path in (REQUIREMENTS_TXT, "setup.sh"):
if rel_path in (REQUIREMENTS_TXT, "setup.sh", "post_setup.sh"):
continue
file_content = open(full_path, "rb").read()
if (
Expand Down Expand Up @@ -852,6 +852,11 @@ def _init_deployment_files(
setup_md5 = hashlib.md5(setup_script).hexdigest()
if setup_md5 != pod_files.get("setup.sh", ""):
upload_files.append(("setup.sh", setup_script))
post_setup_script = _build_post_setup_script(bento_dir, svc.image)
if post_setup_script:
post_setup_md5 = hashlib.md5(post_setup_script).hexdigest()
if post_setup_md5 != pod_files.get("post_setup.sh", ""):
upload_files.append(("post_setup.sh", post_setup_script))
self.upload_files(upload_files, console=console)
# Upload a ready flag file after all files are uploaded
self.upload_files([(".project_ready", b"")], console=console)
Expand Down Expand Up @@ -892,6 +897,7 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
*DEFAULT_BENTO_BUILD_FILES,
REQUIREMENTS_TXT,
"setup.sh",
"post_setup.sh",
) or bento_spec.includes(rel_path)

console = Console(highlight=False)
Expand Down Expand Up @@ -1582,6 +1588,14 @@ def _build_setup_script(bento_dir: str, image: Image | None) -> bytes:
content += f"apt-get update && apt-get install -y {' '.join(config.docker.system_packages)} || exit 1\n".encode()
if image and image.commands:
content += "\n".join(image.commands).encode() + b"\n"
return content


def _build_post_setup_script(bento_dir: str, image: Image | None) -> bytes:
content = b""
config = BentoBuildConfig.from_bento_dir(bento_dir)
if image and image.post_commands:
content += "\n".join(image.post_commands).encode() + b"\n"
if config.docker.setup_script and os.path.exists(
fullpath := os.path.join(bento_dir, config.docker.setup_script)
):
Expand Down
6 changes: 3 additions & 3 deletions src/bentoml/_internal/utils/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def is_safe_url(url: str) -> bool:
parsed = urlparse(url)
except (ValueError, TypeError):
return False

if parsed.scheme not in {"http", "https"}:
return False

Expand All @@ -83,7 +83,7 @@ def is_safe_url(url: str) -> bool:
except socket.gaierror:
# DNS resolution failed
return False

for info in addr_info:
try:
ip = ipaddress.ip_address(info[4][0])
Expand All @@ -92,5 +92,5 @@ def is_safe_url(url: str) -> bool:
except (ValueError, IndexError):
# Skip malformed addresses
continue

return True