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: Add external build functionality #4021

Merged
merged 3 commits into from
Aug 29, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions client/verta/verta/endpoint/build/_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ class Build:
Message or logs associated with the build.
is_complete : bool
Whether the build is finished either successfully or with an error.
location: str or None
(alpha) The location of the build. This is only available for completed or external builds.
requires_root: bool or None
(alpha) Whether the build requires root access.
scan_external: bool or None
(alpha) Whether the build should be scanned by an external provider.
self_contained: bool or None
(alpha) Whether the build is self-contained.

"""

Expand Down Expand Up @@ -77,6 +85,27 @@ def _list_model_version_builds(
for build_json in response.json().get("builds", [])
]

@classmethod
def _create_external(
cls, conn: _utils.Connection, workspace: str, model_version_id: int, location: str, requires_root: Optional[bool] = None, scan_external: Optional[bool] = None, self_contained: Optional[bool] = None
) -> "Build":
data = {
"external_location": location,
"model_version_id": model_version_id,
}
if requires_root is not None:
data["requires_root"] = requires_root
if scan_external is not None:
data["scan_external"] = scan_external
if self_contained is not None:
data["self_contained"] = self_contained

url = f"{conn.scheme}://{conn.socket}/api/v1/deployment/workspace/{workspace}/builds"
response = _utils.make_request("POST", url, conn, json=data)
_utils.raise_for_http_error(response)

return cls(conn, workspace, response.json())

@property
def id(self) -> int:
return self._json["id"]
Expand All @@ -89,10 +118,36 @@ def date_created(self) -> datetime:
def status(self) -> str:
return self._json["status"]

@property
def location(self) -> Optional[str]:
location = self._json.get("location")
if location is None:
location = self._json.get("creator_request", dict()).get("external_location")
return location

@property
def requires_root(self) -> Optional[bool]:
return self._json.get("requires_root")

@property
def scan_external(self) -> Optional[bool]:
return self._json.get("scan_external")

@property
def self_contained(self) -> Optional[bool]:
return self._json.get("self_contained")

@property
def message(self) -> str:
return self._json.get("message") or self._EMPTY_MESSAGE

def set_message(self, message: str) -> None:
url = f"{self._conn.scheme}://{self._conn.socket}/api/v1/deployment/builds/{self.id}/message"
response = _utils.make_request("PUT", url, self._conn, json=message)
_utils.raise_for_http_error(response)
self._json["message"] = message


@property
def is_complete(self) -> bool:
return self.status in ("finished", "error")
Expand Down
24 changes: 24 additions & 0 deletions client/verta/verta/registry/entities/_modelversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1761,3 +1761,27 @@ def list_builds(self) -> List[Build]:
"""
builds = Build._list_model_version_builds(self._conn, self.workspace, self.id)
return sorted(builds, key=lambda build: build.date_created, reverse=True)

def create_external_build(self, location: str, requires_root: Optional[bool] = None, scan_external: Optional[bool] = None, self_contained: Optional[bool] = None) -> Build:
"""
(alpha) Creates a new external build for this model version.

.. versionadded:: 0.24.1

Parameters
----------
location : str
The location of the build.
requires_root : bool, optional
Whether the build requires root access.
scan_external : bool, optional
Whether to scan the build for vulnerabilities using the external provider.
self_contained : bool, optional
Whether the build is self-contained.

Returns
-------
:class:`~verta.endpoint.build.Build`

"""
return Build._create_external(self._conn, self.workspace, self.id, location, requires_root, scan_external, self_contained)