Skip to content

Commit

Permalink
feat: Add external build functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoverta committed Aug 18, 2023
1 parent 24b535d commit f050a13
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
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: Optional[str]
(alpha) The location of the build. This is only available for completed or external builds.
requires_root: Optional[bool]
(alpha) Whether the build requires root access.
scan_external: Optional[bool]
(alpha) Whether the build should be scanned by an external provider.
self_contained: Optional[bool]
(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

@message.setter
def message(self, message: str) -> None:
self._json["message"] = message
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)

@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)

2 comments on commit f050a13

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker Tag: cm_build-2023-08-18T03-02-20--f050a13

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total coverage (common): 15.14
Total coverage (server): 61.32

Changed Files coverage (common): coverage 100
Changed Files coverage (server): 100

Please sign in to comment.