Skip to content

Commit

Permalink
Add possibility to define Docker volumes (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
filippo82 committed Nov 5, 2023
1 parent bd51f36 commit d6ff558
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions vespa/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
output_file: IO = sys.stdout,
container: Optional[docker.models.containers.Container] = None,
container_image: str = "vespaengine/vespa",
volumes: Optional[List[str]] = None,
cfgsrv_port: int = 19071,
debug_port: int = 5005,
) -> None:
Expand All @@ -71,6 +72,7 @@ def __init__(
:param output_file: Output file to write output messages.
:param container_memory: Docker container memory available to the application.
:param container: Used when instantiating VespaDocker from a running container.
:param volumes: A list of strings which each one of its elements specifies a mount volume. For example: `['/home/user1/:/mnt/vol2','/var/www:/mnt/vol1']`.
:param container_image: Docker container image.
"""
self.container = container
Expand All @@ -86,6 +88,7 @@ def __init__(
self.cfgsrv_port = cfgsrv_port
self.debug_port = debug_port
self.container_memory = container_memory
self.volumes = volumes
self.output = output_file
self.container_image = container_image

Expand Down Expand Up @@ -276,7 +279,10 @@ def _deploy_data(self, application: ApplicationPackage, data, debug: bool) -> Ve
:return: A Vespa connection instance
"""
self._run_vespa_engine_container(
application_name=application.name, container_memory=self.container_memory, debug=debug
application_name=application.name,
container_memory=self.container_memory,
volumes=self.volumes,
debug=debug,
)
self.wait_for_config_server_start(max_wait=CFG_SERVER_START_TIMEOUT)

Expand Down Expand Up @@ -306,6 +312,7 @@ def _run_vespa_engine_container(
self,
application_name: str,
container_memory: str,
volumes: List[str],
debug: bool,
) -> None:
client = docker.from_env(timeout=DOCKER_TIMEOUT)
Expand All @@ -324,12 +331,14 @@ def _run_vespa_engine_container(
"mem_limit: {mem_limit}, "
"name: {name}, "
"hostname: {hostname}, "
"ports: {ports}".format(
"ports: {ports}, "
"volumes: {volumes}".format(
image=self.container_image,
mem_limit=container_memory,
name=application_name,
hostname=application_name,
ports=mapped_ports,
volumes=volumes,
)
)
self.container = client.containers.run(
Expand All @@ -340,6 +349,7 @@ def _run_vespa_engine_container(
hostname=application_name,
privileged=True,
ports=mapped_ports,
volumes=volumes,
)
self.container_name = self.container.name
self.container_id = self.container.id
Expand Down Expand Up @@ -444,13 +454,13 @@ def deploy(self, instance: Optional[str]="default", disk_folder: Optional[str] =
job = "dev-" + region
run = self._start_deployment(instance, job, disk_folder, None)
self._follow_deployment(instance, job, run)

token = os.environ.get(VESPA_CLOUD_SECRET_TOKEN, None)
if token is None:
endpoint_url = self.get_mtls_endpoint(instance=instance, region=region)
else:
endpoint_url = self.get_token_endpoint(instance=instance, region=region)
endpoint_url = self.get_token_endpoint(instance=instance, region=region)

app = Vespa(
url=endpoint_url,
cert=self.data_cert_path or os.path.join(disk_folder, self.private_cert_file_name),
Expand Down Expand Up @@ -490,7 +500,7 @@ def deploy_from_disk(self, instance: str, application_root: Path) -> Vespa:
if os.environ.get(VESPA_CLOUD_SECRET_TOKEN) is None:
endpoint_url = self.get_mtls_endpoint(instance=instance, region=region)
else:
endpoint_url = self.get_token_endpoint(instance=instance, region=region)
endpoint_url = self.get_token_endpoint(instance=instance, region=region)
app = Vespa(
url=endpoint_url,
cert=self.data_cert_path,
Expand Down Expand Up @@ -684,7 +694,7 @@ def _request(
delay = min(2**retry_count, 1) + random.uniform(0, 1)
sleep(delay)



def get_mtls_endpoint(self, instance: Optional[str]="default", region: Optional[str]=None) -> str:
if region is None:
Expand Down

0 comments on commit d6ff558

Please sign in to comment.