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

Add deploy from bytes option #847

Closed
wants to merge 6 commits into from
Closed
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
56 changes: 49 additions & 7 deletions vespa/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,33 @@ def deploy(
docker_timeout=max_wait_docker,
debug=debug,
)

def deploy_from_bytes(
self,
application_name: str,
application_bytes: bytes,
max_wait_configserver: int = 60,
max_wait_application: int = 300,
docker_timeout: int = 300,
debug: bool = False,
) -> Vespa:
"""
Deploy directly from zip bytes.
Useful when you already have the application package as bytes.

:param application_name: Application package name.
:param application_bytes: Application package as bytes.
:param debug: Add the configured debug_port to the docker port mapping.
:return: a Vespa connection instance.
"""
return self._deploy_data(
ApplicationPackage(name=application_name),
application_bytes,
debug,
max_wait_application=max_wait_application,
max_wait_configserver=max_wait_configserver,
docker_timeout=docker_timeout,
)

def deploy_from_disk(
self,
Expand Down Expand Up @@ -858,27 +885,26 @@ def wait_for_prod_deployment(
time.sleep(poll_interval)
raise TimeoutError(f"Deployment did not finish within {max_wait} seconds. ")

def deploy_from_disk(
self, instance: str, application_root: Path, max_wait: int = 300
def deploy_from_zip(
self, instance: str, zip_file: BytesIO, max_wait: int = 300
) -> Vespa:
"""
Deploy to dev from a directory tree.
Used when making changes to application package files not supported by pyvespa.
Deploy to dev from a zipped application package.
Useful when you already have the application package as bytes.

NB: Requires certificate and key to be generated with 'vespa auth cert'.

:param instance: Name of the instance where the application is to be run
:param application_root: Application package directory root
:param max_wait: Seconds to wait for the deployment.
:return: a Vespa connection instance.
"""
data = BytesIO(self.read_app_package_from_disk(application_root))

# Deploy the zipped application package
disk_folder = os.path.join(os.getcwd(), self.application)
region = self.get_dev_region()
job = "dev-" + region
run = self._start_deployment(
instance, job, disk_folder, application_zip_bytes=data
instance, job, disk_folder, application_zip_bytes=zip_file
)
self._follow_deployment(instance, job, run)
mtls_endpoint = self.get_mtls_endpoint(instance=instance, region=region)
Expand All @@ -902,6 +928,22 @@ def deploy_from_disk(
print("Finished deployment.", file=self.output)

return app

def deploy_from_disk(
self, instance: str, application_root: Path, max_wait: int = 300
) -> Vespa:
"""
Deploy to dev from a directory tree.
Used when making changes to application package files not supported by pyvespa.
NB: Requires certificate and key to be generated with 'vespa auth cert'.

:param instance: Name of the instance where the application is to be run
:param application_root: Application package directory root
:param max_wait: Seconds to wait for the deployment.
:return: a Vespa connection instance.
"""
data = BytesIO(self.read_app_package_from_disk(application_root))
return self.deploy_from_zip(instance, data, max_wait)

def close(self) -> None:
self.connection.close()
Expand Down
Loading