Skip to content

Commit

Permalink
Merge pull request #292 from vespa-engine/kkraune/container-image
Browse files Browse the repository at this point in the history
Kkraune/container image
  • Loading branch information
thigm85 authored Apr 4, 2022
2 parents 170a68d + cdc0d25 commit 4aa564e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
13 changes: 11 additions & 2 deletions vespa/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(
container_memory: Union[str, int] = 4 * (1024 ** 3),
output_file: IO = sys.stdout,
container: Optional[docker.models.containers.Container] = None,
container_image: str = "vespaengine/vespa"
) -> None:
"""
Manage Docker deployments.
Expand All @@ -41,6 +42,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 container_image: Docker container image.
"""
self.container = container
container_id = None
Expand All @@ -55,6 +57,7 @@ def __init__(
self.disk_folder = disk_folder
self.container_memory = container_memory
self.output = output_file
self.container_image = container_image

@staticmethod
def from_container_name_or_id(
Expand All @@ -77,13 +80,15 @@ def from_container_name_or_id(
container.attrs["HostConfig"]["PortBindings"]["8080/tcp"][0]["HostPort"]
)
container_memory = container.attrs["HostConfig"]["Memory"]
container_image = container.image.tags[0] # vespaengine/vespa:latest

return VespaDocker(
disk_folder=disk_folder,
port=port,
container_memory=container_memory,
output_file=output_file,
container=container,
container_image=container_image,
)

def _run_vespa_engine_container(
Expand All @@ -99,7 +104,7 @@ def _run_vespa_engine_container(
self.container.restart()
except docker.errors.NotFound:
self.container = client.containers.run(
"vespaengine/vespa",
self.container_image,
detach=True,
mem_limit=container_memory,
name=application_name,
Expand Down Expand Up @@ -381,6 +386,7 @@ def from_dict(mapping: Mapping) -> "VespaDocker":
disk_folder=mapping["disk_folder"],
port=mapping["port"],
container_memory=mapping["container_memory"],
container_image=mapping["container_image"],
)
return vespa_docker

Expand All @@ -393,6 +399,7 @@ def to_dict(self) -> Mapping:
"port": self.local_port,
"disk_folder": self.disk_folder,
"container_memory": self.container_memory,
"container_image": self.container_image,
}
return map

Expand All @@ -406,17 +413,19 @@ def __eq__(self, other):
and self.local_port == other.local_port
and self.disk_folder == other.disk_folder
and self.container_memory == other.container_memory
and self.container_image.split(":")[0] == other.container_image.split(":")[0]
)

def __repr__(self):
return "{0}({1}, {2}, {3}, {4}, {5}, {6})".format(
return "{0}({1}, {2}, {3}, {4}, {5}, {6}, {7})".format(
self.__class__.__name__,
repr(self.disk_folder),
repr(self.url),
repr(self.local_port),
repr(self.container_name),
repr(self.container_id),
repr(self.container_memory),
repr(self.container_image.split(":")[0]),
)


Expand Down
22 changes: 17 additions & 5 deletions vespa/test_integration_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ def create_sequence_classification_task():


class TestDockerCommon(unittest.TestCase):
def deploy(self, application_package, disk_folder):
self.vespa_docker = VespaDocker(port=8089, disk_folder=disk_folder)
def deploy(self, application_package, disk_folder, container_image=None):
if container_image:
self.vespa_docker = VespaDocker(port=8089, disk_folder=disk_folder, container_image=container_image)
else:
self.vespa_docker = VespaDocker(port=8089, disk_folder=disk_folder)

app = self.vespa_docker.deploy(application_package=application_package)
#
# Test deployment
Expand All @@ -146,9 +150,10 @@ def deploy(self, application_package, disk_folder):
# Test VespaDocker serialization
#
self.assertEqual(
self.vespa_docker, VespaDocker.from_dict(self.vespa_docker.to_dict)
repr(self.vespa_docker), repr(VespaDocker.from_dict(self.vespa_docker.to_dict))
)


def deploy_from_disk_with_disk_folder(self, application_package, disk_folder):
self.vespa_docker = VespaDocker(port=8089, disk_folder=disk_folder)
self.vespa_docker.export_application_package(
Expand Down Expand Up @@ -1082,12 +1087,19 @@ def setUp(self) -> None:

def test_deploy(self):
self.deploy(application_package=self.app_package, disk_folder=self.disk_folder)
self.vespa_docker.container.stop()
self.vespa_docker.container.remove()

def tearDown(self) -> None:
shutil.rmtree(self.disk_folder, ignore_errors=True)
def test_deploy_image(self):
self.deploy(application_package=self.app_package,
disk_folder=self.disk_folder,
container_image="vespaengine/vespa:7.566.21")
self.vespa_docker.container.stop()
self.vespa_docker.container.remove()

def tearDown(self) -> None:
shutil.rmtree(self.disk_folder, ignore_errors=True)


class TestMsmarcoApplication(TestApplicationCommon):
def setUp(self) -> None:
Expand Down

0 comments on commit 4aa564e

Please sign in to comment.