Automating Vespa Deployment

A Step-by-Step Guide

Deploying applications on Vespa can be a seamless process when automated correctly. This blog post will guide you through setting up a script to automate the deployment of a Vespa application and explain the associated configuration files.

Automating the Deployment with a Bash Script

To ensure that Vespa is ready to accept deployments, we use a Bash script to wait for Vespa to be fully operational before deploying the application. Here’s the script:

bashCopy

#!/bin/bash

echo "Waiting for Vespa to be ready..."
# Wait for Vespa to be ready (checking the health endpoint)
while ! curl -s "http://localhost:19071/state/v1/health" > /dev/null; do
    sleep 5
    echo "Waiting for Vespa..."
done

echo "Vespa is ready! Deploying application..."

# Deploy the application
docker exec vespa bash -c '/opt/vespa/bin/vespa-deploy prepare /app/application-package && \
/opt/vespa/bin/vespa-deploy activate'

echo "Deployment complete!"

Explanation:

  • Health Check Loop: The script repeatedly checks Vespa's health endpoint (http://localhost:19071/state/v1/health) to ensure Vespa is up and running. This loop pauses the script until Vespa is ready.

  • Deployment Commands: Once Vespa is ready, the script uses Docker to execute commands within the Vespa container. It prepares and activates the application package, ensuring that your application is deployed correctly.

Configuration Files for Vespa

For Vespa to function correctly, you need to define your application’s configuration. Below are sample XML configuration files and their explanations.

  1. Hosts Configuration (hosts.xml)

xmlCopy

<?xml version="1.0" encoding="utf-8" ?>
<hosts>
    <host name="vespa-container">
        <alias>vespa-container</alias>
    </host>
</hosts>

Explanation: This file defines the host where your Vespa services will run. Here, vespa-container is both the name and alias for the host, making it easy to reference in other configuration files.

  1. Services Configuration (services.xml)

xmlCopy

<?xml version="1.0" encoding="utf-8" ?>
<services version="1.0">
    <admin version="2.0">
        <adminserver hostalias="vespa-container"/>
    </admin>

    <container id="default" version="1.0">
        <search/>
        <document-api/>
        <nodes>
            <node hostalias="vespa-container"/>
        </nodes>
    </container>

    <content id="content" version="1.0">
        <redundancy>1</redundancy>
        <documents>
            <document type="mydocument" mode="index"/>
        </documents>
        <nodes>
            <node hostalias="vespa-container" distribution-key="0"/>
        </nodes>
        <tuning>
            <resource-limits>
                <disk>0.95</disk>
            </resource-limits>
        </tuning>
    </content>
</services>

Explanation: This file defines the services that Vespa will run. It includes:

  • Admin Server: Configures the administrative server on vespa-container.

  • Container: Specifies a container for search and document APIs.

  • Content: Manages the storage of documents with specified redundancy and resource limits.

  1. Validation Overrides (validation-overrides.xml)

xmlCopy

<?xml version="1.0" encoding="utf-8" ?>
<validation-overrides>
    <allow until="2024-04-15">schema-removal</allow>
</validation-overrides>

Explanation: This file allows certain changes to the schema, like removal, to occur without triggering validation errors, up until a specified date.

  1. Schema Definition (mydocument.sd)

plaintextCopy

schema mydocument {
    document mydocument {
        field title type string {
            indexing: summary | index
        }
        field content type string {
            indexing: summary | index
        }
    }
}

Explanation: This schema file defines the structure of the documents Vespa will handle. It includes fields like title and content, specifying how they should be indexed and stored.

Conclusion

By automating the deployment process with a Bash script and carefully configuring the necessary XML files, you can efficiently manage your Vespa applications. This setup not only simplifies deployment but also ensures that your application is deployed consistently and reliably. As you become more familiar with Vespa, these configurations can be expanded to accommodate more complex application requirements.

Last updated