Deploy with Docker

Vespa logo

This notebook explores how to build, export and deploy an application package.

See pyvespa, jupyter notebooks and Docker requirements to run this notebook.

Deploy an application package created with pyvespa

This section creates an empty ApplicationPackage instance for deployment testing:

[ ]:
from vespa.package import ApplicationPackage

app_package = ApplicationPackage(name="sampleapp")

Deploy the app_package using Docker without leaving the notebook, by creating an instance of VespaDocker:

[ ]:
import os
from vespa.deployment import VespaDocker

vespa_docker = VespaDocker()
app = vespa_docker.deploy(application_package=app_package)
Waiting for configuration server, 0/300 seconds...
Waiting for configuration server, 5/300 seconds...
Waiting for application status, 0/300 seconds...
Waiting for application status, 5/300 seconds...
Waiting for application status, 10/300 seconds...
Waiting for application status, 15/300 seconds...
Waiting for application status, 20/300 seconds...
Waiting for application status, 25/300 seconds...
Finished deployment.

app now holds a Vespa instance, to be used to interact with the application. Congratulations, the Vespa application is up and running!

Stop the docker container to clean up:

[ ]:

Learn Vespa by looking at underlying config files

pyvespa provides a convenient API to define Vespa application packages from python. Going through those files is a nice way to start learning about Vespa syntax.

Use to_files to export the application package package created with pyvespa from code to files:

[ ]:
from pathlib import Path
Path("mydir").mkdir(parents=True, exist_ok=True)

Inspect the exported files:

[ ]:
!find mydir

It is also possible to export the application package as a zipped file using to_zipfile. The zipfile can later be deployed with pyvespa or the Vespa CLI:

[ ]:

Remove the files after use:

[ ]:
from shutil import rmtree
rmtree("mydir", ignore_errors=True)
rmtree("", ignore_errors=True)

Deploy application package from config files

The pyvespa API provides a subset of the functionality available in Vespa. The reason is that pyvespa is meant to be used as an experimentation tool for Information Retrieval (IR) and not for building production-ready applications. So, the python API expands based on the needs to replicate common use cases that often require IR experimentation.

If the application requires functionality or fine-tuning not available in pyvespa, simply build it directly using Vespa configuration files as shown in many examples on Vespa docs. But even in this case, one can still get value out of pyvespa by deploying it from python based on the Vespa configuration files stored on disk.

Clone and deploy the news search app covered in this Vespa tutorial:

[ ]:
!git clone --depth 1 sample-apps
Cloning into 'sample-apps'...
remote: Enumerating objects: 1138, done.
remote: Counting objects: 100% (1138/1138), done.
remote: Compressing objects: 100% (754/754), done.
remote: Total 1138 (delta 189), reused 889 (delta 109), pack-reused 0
Receiving objects: 100% (1138/1138), 18.94 MiB | 9.38 MiB/s, done.
Resolving deltas: 100% (189/189), done.

The Vespa configuration files of the news search app are stored in sample-apps/news/app-3-searching/:

[ ]:
!tree sample-apps/news/app-3-searching/
├── schemas
│   └──
└── services.xml

1 directory, 2 files

Deploy to a Docker container from disk:

[ ]:
import os
from vespa.deployment import VespaDocker

vespa_docker_news = VespaDocker()
app = vespa_docker_news.deploy_from_disk(
Waiting for configuration server.
Waiting for configuration server.
Waiting for application status.
Waiting for application status.
Finished deployment.

app can now be used to feed and query the application just deployed. Clean up after use:

[ ]:
rmtree("sample-apps", ignore_errors=True)