Deploy an Application to Nomad
Warning
This content is part of the legacy version of Waypoint that is no longer actively maintained. For additional information on the new vision of Waypoint, check out this blog post and the HCP Waypoint documentation.
In this tutorial, you will learn how Waypoint works by deploying and running an application on a Nomad cluster that's running on your local machine.
If you want to try Waypoint on a Nomad cluster running on cloud infrastructure, complete the get started with Nomad on the cloud tutorials.
Prerequisites
For this tutorial, you will need:
- The Waypoint CLI version 0.11.1 or later installed locally
- The Nomad CLI version 1.55.5 or later installed locally
- (Optional) An HCP Account if you want to use HCP Waypoint
Create a Nomad environment
Waypoint supports Nomad both as a location for running the Waypoint server and as a target for application deployments.
Waypoint installation on Nomad supports persistent data storage with host or CSI volumes. In this tutorial, you use host volumes for persistent storage, and will set up one for both the server and client runner. While it is possible to have the server and runner share the same Nomad volume, we recommend having separate host volumes.
Create the Nomad client configuration
Host volumes are configured in the Nomad client HCL file with the host_volume
block. Waypoint uses these host volumes to write the data it needs for the server and client runner.
Note
The $HOME
environment variable used in this tutorial is automatically set to the user's home directory on most systems. If it is not already set on your system, export the path to your home directory as $HOME
.
export $HOME=/path/to/home/directory
Create a folder named nomad
in your home directory. This will contain the host volume directories, the data directory for the server, and the client configuration file.
Create the data directory for the server.
Then, create the host volume directories for the server and runner. The -p
flag will create the parent host-volumes
directory.
Change to your home directory.
Create a file named nomad-client.hcl
and add the following configuration to it. Replace the PATH_TO_HOME_DIR
placeholder text with the full path to your home directory. Save the file. Note that the data directory and host volume paths must be absolute.
Create the Nomad cluster. Note that the client configuration file is passed in with the -config
flag. Nomad will start and begin to output data.
Leave this terminal session open to keep Nomad running.
In a new terminal session, export the cluster address to an environment variable.
The Nomad UI is available at http://localhost:4646/ui.
Inspect the host volumes
The host volumes for the Waypoint runner and server can be seen in the Nomad UI when inspecting the client. Open the Nomad UI, click on the Clients link from the left navigation, click on the client from the client list, and scroll down to the Host Volumes section.
Note that there are two host volumes in the list, one for the Waypoint runner with the name wp-runner-vol
and one for the Waypoint server with the name wp-server-vol
.
Set up Waypoint
HCP Waypoint is a HashiCorp-managed service that helps you to manage your application lifecycle without maintaining a Waypoint server and associated infrastructure. It allows to you automate and simplify the process of deploying your web applications into your infrastructure.
Waypoint runs as a server and a client, whether run on HCP Waypoint or locally. For this tutorial, you can choose to use HCP Waypoint for the server and your Nomad cluster for the client or run Waypoint entirely on the cluster.
Both methods create a Waypoint context that contains information about the server and authentication for connecting to it from the Waypoint CLI. This is how the CLI knows the address of the server when you run other Waypoint commands.
Set up an HCP organization and project
Sign in to your HCP account and create an HCP organization by following the steps in the Create an organization page. Then, create an HCP project by following the steps in the Create a project page.
Enable HCP Waypoint
Click on the Waypoint option from the left navigation.
Then, click on the Activate Waypoint button in the top right of the page.
A dialog appears to confirm that Waypoint has been activated.
Set up HCP Waypoint context
Click the Manage button on the top right of the page, click on the clipboard icon to copy the waypoint context create
command, and run it in your terminal. Your Waypoint CLI can now communicate with HCP Waypoint.
HCP Waypoint works with your local installation of the Waypoint CLI and does not require any additional runners as it uses the one that is part of the CLI. Installing and connecting a static runner to HCP Waypoint allows you to automate your workflow with GitOps and use dynamic configuration sourcing without requiring interaction with your CLI.
This tutorial uses only the CLI runner and does not include runner installation. You can read more about the runner installation process on the runner install page.
Clone the example repository
The example repository contains application code and Waypoint configuration files for building, deploying, and releasing the application with Waypoint.
Clone the example repository.
Navigate to the example-app
directory.
Initialize Waypoint for the application
You must initialize and configure Waypoint for your application before beginning the build, deploy, and release workflow.
During the initialization process, Waypoint searches for a waypoint.hcl
configuration file for the application in the current directory. This configuration file gives Waypoint instructions for how to build, deploy, and release your application. If Waypoint cannot find the configuration file when waypoint init
is run, it will create a waypoint.hcl
file that you can then customize for your application.
Review the waypoint.hcl
file
Open the waypoint.hcl
file.
The use
option within the build
, deploy
, and release
blocks specifies which plugin to use during those specific phases of the workflow.
The build
block defines how Waypoint will build the application and produce an artifact.
- Since the
use "pack"
option in this example is empty, Waypoint uses the default configuration for the Cloud Native Buildpacks plugin, which selects the most relevant pack to build the application. - The
registry
option specifies image registry information. In this example, the Docker image name and tag are specified along with alocal
attribute set totrue
, which instructs Waypoint to tag the image locally only and not push to a remote repository. If you are pushing to a remote repository, theimage
attribute must include the fully qualified name.
The deploy
block defines how Waypoint will deploy the application.
- The
use "nomad"
option in this example tells Waypoint to use the Nomad plugin to deploy the application to Nomad with any configurations defined in the block. - The
service_provider
block instructs Waypoint to use Nomad's service discovery for service registration instead of Consul.
Waypoint URL service
The Waypoint URL service is a service hosted by HashiCorp that generates publically accessible URLs for your applications on Waypoint. The URLs are connected to your application and their deployment locations so the URLs will only resolve when the deployment is running.
These preview URLs are optional and can be disabled in the Waypoint server configuration when running a server manually with waypoint server run
. You can also disable preview URLs on a per-app basis with the url
block if the service is enabled on the server.
Initialize Waypoint
Initialize Waypoint for the example application.
Build and deploy
With the initialization complete, use the waypoint up
command to instruct Waypoint to build, deploy, and release your application.
Run waypoint up
Waypoint uses Cloud Native Buildpacks to automatically detect the type of application and uses the applicable buildpack to create the build artifact.
Once Waypoint completes the build, it stores the artifacts in a registry. The registry
block contains the configuration for where Waypoint should store those artifacts. By default, Waypoint stores Docker artifacts locally with Docker Desktop unless the registry
block contains additional configuration.
Start the Waypoint workflow.
Waypoint will start the process and output the following.
Waypoint shows the progress of the build, deploy, and release steps in the output but does not contain deployment URLs as the URL service is disabled when using HCP Waypoint.
View the application's URL by first finding the allocation ID of the job with the nomad job status
command. The allocation ID is at the bottom of the output under Allocations. In this example the allocation ID is b0a9be89
.
Copy the allocation ID and get the status for the allocation. This command will filter the status output and display the allocation addresses. In this example, the address is 192.168.50.210:30298
. Open this address in your browser to see the application.
Update and redeploy the app
One of the most powerful parts of Waypoint is that it allows you to quickly iterate on and redeploy changes to your application.
Open index.ejs
in your text editor and update the deployment message in the <h1>
tag. Save the file.
Navigate back to your terminal and restart the workflow.
Waypoint will start the process and output the following.
Find the allocation ID of the job with the nomad job status
command. In this example the allocation ID is b0a9be89
.
View the jobs that start with nomad-nodejs
. Each deployment with Waypoint creates a new Nomad job so there are now two available jobs.
The results are in order from oldest to newest. Copy the second job ID and get the job status for it. In this example, the job ID is nomad-nodejs-web-01gz49x96wh23hdgawna1377j5
.
Copy the allocation ID and get the status for the allocation. In this example, the address is not 192.168.50.210:29908
. Open this address in your browser.
Next steps
In this tutorial, you learned about Waypoint and the application workflow, set up a Waypoint server and client on Nomad, and built, deployed, updated, and redeployed an application.
Learn how to deploy applications to other platforms with Waypoint by checking out the Docker and Kubernetes tutorials.
Continue on to the next tutorial by clicking on the Next button below. You will learn how to interact with a running application container and browse the Waypoint web UI.
Be sure to follow the steps in the Destroy the Deployment tutorial to uninstall the Waypoint components and clean up your Nomad cluster.