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 is running on cloud infrastructure.
If you want to try Waypoint on a Nomad cluster running locally, complete the get started with Nomad locally 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
You will create a Nomad cluster in this tutorial and depending on where you want to run it, you'll also need:
- An account on AWS, GCP, or Azure
- The Terraform CLI installed locally
- A free DockerHub personal account for storing and accessing images
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.
Set up DockerHub configuration
When running Waypoint on non-local infrastructure, an external image repository is necessary for storing and retrieving built images. In this tutorial, you will use DockerHub as an external image repository but other ones work as long as you properly configure authentication through the auth
configuration of the registry block in the Docker plugin.
To access DockerHub for pushing and pulling images, Waypoint requires authentication credentials. It supports credential definitions in the waypoint.hcl
file and "out of band" authentication by reading configurations set locally by a docker login
either through the Docker CLI or Docker Desktop. In this tutorial, you will be providing DockerHub token credentials through environment variables.
Navigate to DockerHub, log in, and create an access token by visiting the security settings page and clicking the New Access Token button. Give the token a description, select the Read, Write, Delete permission option from the dropdown, and click the Generate button.
Copy the token value and export it as an environment variable.
Then, export your DockerHub username.
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 nomad-cloud
directory.
Review 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.
Review the host_volume
blocks of the Nomad client configuration.
Update the Terraform configurations
Choose the cloud provider below that you want to use.
Note
Make sure that you have your AWS access credentials set as environment variables.
Navigate to the aws
folder.
Rename the example variables file to terraform.tfvars
.
Update the region
variable in terraform.tfvars
with your AWS region preference. Save the file.
Deploy the Nomad cluster
Initialize Terraform to download required plugins and set up the workspace.
Provision the resources. Respond yes
to the prompt to confirm the operation. The provisioning takes a couple of minutes.
Verify cluster availability
Once the provisioning is complete, the Nomad web UI will become available in another couple of minutes. You can get the URL in your terminal with the Terraform output variable nomad_ip
.
Open the web UI. You may see an error from your browser letting you know that the site cannot be reached or a No cluster leader
error message from the Nomad UI after refreshing the page. These are both normal during the setup and mean the cluster is not yet ready. Wait a few minutes and refresh your browser again to see the Nomad UI.
The Nomad UI will show a Not Authorized
message once cluster setup is complete. This means the ACL system has not been set up yet. You will bootstrap it in the next section.
Set up Nomad
Once the cluster is ready and the web UI is available, you can bootstrap the ACL system.
Export the cluster address as the NOMAD_ADDR
environment variable.
Bootstrap the ACLs and save the management token to a file.
Export the token as the NOMAD_TOKEN
environment variable. Your CLI is now set up to interact with the cluster.
Authenticate with the web 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.
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 you run waypoint init
, it will create a waypoint.hcl
file that you can customize for your application.
Review the waypoint.hcl
file
Change to the example-app
directory.
Open the waypoint.hcl
file.
The variable
blocks define the Docker registry username and password environment variables set earlier.
The app
block defines the name of the application in Waypoint and contains the build
, deploy
, and release
configuration blocks.
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 image contains the username for DockerHub and anauth
block with credentials for pushing to that registry. Theimage
attribute must include the fully qualified name unless you are using DockerHub.
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 full ID of the most recent job starting with the prefix nomad-nodejs
. In this example, the most recent job is nomad-nodejs-web-01gwsybfftps09nm9gd20vtzj7
.
Copy the job ID and paste it into the second line of the following command. The command gets the status for the job, searches for its allocations, extracts the allocation that has a status of running
, and passes the allocation's ID to the nomad alloc status
command to get the status of the allocation. It then searches for the allocation with the waypoint
label, and prints out the formatted address.
Open the URL from the output in your browser.
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 full ID of the most recent job starting with the prefix nomad-nodejs
. In this example, the most recent job is nomad-nodejs-web-01gwt040bta2j0364q8xhzrgxs
.
Get the URL by using the job ID in the second line of the following command. Open the URL from the output 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.