diff --git a/src/bentoml/_internal/cloud/deployment.py b/src/bentoml/_internal/cloud/deployment.py index f22ca290214..ae8abdd3f07 100644 --- a/src/bentoml/_internal/cloud/deployment.py +++ b/src/bentoml/_internal/cloud/deployment.py @@ -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 ( @@ -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) @@ -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) @@ -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) ): diff --git a/src/bentoml/_internal/utils/uri.py b/src/bentoml/_internal/utils/uri.py index 2318cebf296..bf0c677f3c3 100644 --- a/src/bentoml/_internal/utils/uri.py +++ b/src/bentoml/_internal/utils/uri.py @@ -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 @@ -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]) @@ -92,5 +92,5 @@ def is_safe_url(url: str) -> bool: except (ValueError, IndexError): # Skip malformed addresses continue - + return True