Using HCP Waypoint with Your Infrastructure
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.
HashiCorp Cloud Platform (HCP) is a fully managed platform for Terraform, Vault, Consul and now, Waypoint. HCP Waypoint improves your experience as a developer by making the workflow more easily consumable and enabling faster onboarding and deployments. It abstracts away the server components and reduces the overall operational effort of running Waypoint.
Until now, Waypoint promised easy application deployment with minimal devops, but required you to do quite a bit of devops in order to get there. HCP Waypoint eliminates most of that work so you can get straight to writing and deploying your applications.
HCP Waypoint allows you to create, connect, and use runners on your own infrastructure to execute operations. By managing these runners on your own, you have the flexibility to control dependency libraries and other configurations while still getting the benefits of HCP Waypoint.
Runners
Runners are the Waypoint components that execute each operation defined in a waypoint.hcl
file and come in one of three types: CLI runners, remote runners, and on-demand runners.
A CLI runner operates alongside the CLI and acts as the default runner to use.
A remote runner is a persistent runner installed on a platform with its associated plugin and can be targeted with a runner profile for task execution. Officially supported platforms include Docker, Kubernetes, AWS ECS, and Nomad. It is also referred to as a static runner.
An on-demand runner is a single-use ephemeral runner that is created by a remote runner on the platform that the remote runner is installed on to perform one job.
In this tutorial, you will be using a CLI runner to execute the local Docker build and deployment, then install a remote runner on AWS ECS, and use it to create on-demand runners also on ECS.
Runner labels
Runner labels are tags that can be assigned to a runner during the installation process. These tags can be identifiers for configurations like platform, environment, and other capabilities.
Runner profiles
Runner profiles are used to target runners via labels, set environment configurations for them, and as a template for creating new on-demand runners.
A waypoint.hcl
file can then be configured to use a runner profile for tasks defined at the project or app level.
Prerequisites
For this tutorial, you will need:
- Waypoint 0.10.0 or later installed locally (follow along with the Install Waypoint guide)
- An HCP Account
- A free DockerHub personal account
- An account on a hosted Git provider site (GitHub, GitLab, Bitbucket, etc.) and Git installed locally
- An AWS account and the AWS CLI tool installed locally
docker
andterraform
CLI tools installed locally
Set up the environment
The Waypoint context is what your local Waypoint CLI uses to communicate with HCP Waypoint. DockerHub is the service you will be using in this tutorial to store the application images. You will set up both of these in the next section.
Set up HCP Waypoint context
Sign in to your account on HCP and click on the Waypoint option from the left navigation.
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.
Set up DockerHub configuration
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.
Then the image name.
Finally, export your preferred AWS region.
Fork the example repository
The example repository contains an example application and Dockerfile, a Terraform configuration to deploy an ECS cluster, and a waypoint.hcl
file for building and deploying the application to each environment.
Fork the example repository and set your forked repository as an environment variable. Creating a fork allows you to connect a repository you have control over to your HCP Waypoint project and is required for making changes to the code.
Note
Be sure to make your forked repository public or you will need to add authentication credentials to the project's settings in HCP Waypoint.
Clone the repository to your local machine.
Change into the hcp-runners-tutorial
directory.
Build and deploy dev
Open the example repository directory in your terminal and inspect the app "dev"
block in the waypoint.hcl
file. This is for building and deploying the application to your local Docker environment.
Notice that the two registry variables for accessing DockerHub get their values from the environment variables you just set. They are used for authentication in the use
block when pushing the image to DockerHub.
Initialize the project.
Then build and deploy the image to your local Docker environment. The -local=true
option instructs Waypoint to execute the tasks on a local runner instead of on a remote runner.
List the running Docker containers on your system and filter for the one that is running the image that Waypoint just built.
Visit the application in your browser on localhost
using the mapped port in the Docker output. Waypoint randomizes this port so it will be different each time a deployment happens. In this case, the application is running on localhost:65201
.
Update project for remote runners
Installing remote runners allows you to build and deploy your application on infrastructure separate and different from your local machine. Since the runners are external from your local machine, they require that the waypoint.hcl
file and any associated code be accessible from a hosted Git repository.
Configure the Waypoint project to use your forked repository.
Tip
You can provide repository information such as branch, path to the Waypoint configuration file, authentication, and more with the waypoint project apply
flags.
Verify that the project's settings contain the repository URL and that the Remote Enabled
setting is true
.
Remote runners do not access environment variables in your local environment so the DockerHub variables defined earlier must be set for the runners in the project.
Set the environment variables for the project runners by using the local variables you have already set.
Then set the AWS region variable.
Finally, verify that the project's runner settings contain the correct values.
Set up AWS ECS cluster setup
Waypoint requires an existing ECS cluster to install the runner into. Open the repository directory in your terminal and use Terraform to create a cluster.
Tip
Waypoint looks for a cluster named waypoint-server
by default but you can choose a different name and provide it to the waypoint runner install
command with the -ecs-cluster
flag.
Initialize Terraform to download required plugins and set up the workspace.
Then, create the cluster with Terraform. Remember to confirm the run by entering yes
.
Install the ECS runner
Create and connect a new runner to HCP Waypoint. Waypoint will automatically register the runner with HCP Waypoint and create a runner profile for it as part of the installation process. This process will take a couple of minutes to complete.
Verify that the list of runners contains the ECS runner.
Tip
You may see additional runners in the list such as a local runner - this is okay and won't impact the deployment to ECS.
Check that the list of runner profiles contains a profile for the ECS runner. Notice that it has the label cluster: ecs
from the waypoint runner install
command you ran earlier.
Build and deploy to ECS
Remember that the project is configured with the Git repository that contains the application code and the waypoint.hcl
file. Start the build and deploy process for ECS by targeting the ecs
app defined in waypoint.hcl
. The -local=false
flag instructs Waypoint to run this process on the remote runner specified in the waypoint.hcl
file.
Tip
Even though you are running the command locally, the runner will not read the waypoint.hcl
file present in the local directory but instead the one in the remote repository.
Note
If you encounter an error where Waypoint can't get a runner (! Failed to inspect the runner ... desc = failed to get runner
) and that the git clone has failed (! Git clone failed: authentication required
), it is because your repository is private. You need to either make the repository public or add authentication to the project in HCP Waypoint by clicking on the project from the main page, Settings from the left navigation, the Edit settings button in the top right, selecting the Username & password radio button, typing in your credentials, and saving with the Apply changes button.
A release URL is created as part of the ECS deployment and printed in the output. In this case, the application is running on http://waypoint-ecs-ecs-2033600519.ca-central-1.elb.amazonaws.com
. Visit the application in your browser. Note that the application may take a minute to load.
Tip
You can make changes, push them to the repository, and run the waypoint up
command again to have Waypoint rebuild and redeploy to ECS.
You can inspect the different builds, deployments, releases, and more in the HCP Waypoint UI after clicking on an application in the project. When you are ready, proceed to the cleanup section below.
Cleanup
Destroy the Waypoint deployments and releases. The waypoint project destroy
command deletes all resources of the applications in the project including deployments and releases. The -auto-approve
flag tells Waypoint to destroy the project resources without prompting for approval.
Uninstall the ECS runner.
Delete the ECS runner profile.
Delete the ECS cluster with Terraform. Remember to confirm the run by entering yes
.
Note
In some rare cases, the cluster will still exist despite Terraform reporting that it has been destroyed. If this is the case, manually destroy the cluster with aws ecs delete-cluster --cluster=waypoint
.
Verify that the cluster has been destroyed.
Next steps
In this tutorial you installed a Waypoint runner on your own infrastructure, connected it to HCP Waypoint, and deployed an application to it.
Check out the following resources for more information about Waypoint runners.
- Discover more about runners, the different types, targeting and more
- Read more about runner profiles
- Learn about on-demand runners and how to use them