Deploy an app to Google Cloud Run
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 addition to Kubernetes, Waypoint provides a plugin that works with Google Cloud Run. This is a way to run containers on Google's cloud infrastructure.
Prerequisites
You'll need to install the waypoint
binary locally,
clone the examples repository (detailed in the next section). In addition, you may need to signup for Google Cloud, create a project, install the gcloud
command, prepare your Google credentials, and enable Google Cloud Run.
You must also be running Docker Desktop locally.
Clone the examples repository
The code for this tutorial is in the hashicorp/waypoint-examples
repository. Clone the repository with git.
Navigate to the subdirectory for the Google Cloud Run project. This project uses NodeJS but the following instructions will work with any language that can be built with a cloud native buildpack.
Sign up
Visit Google Cloud and sign up for an account. You must create a project under which your service accounts and cloud resources will be organized.
In this tutorial, we will refer to waypoint-project-id
as the project ID.
Install gcloud command
Follow Google's instructions for installing the Google Cloud SDK. This will install a command on your system named gcloud
.
Enable Google Cloud Run
You must enable Google Cloud Run for your project. Visit Google Cloud Run and click "Enable" to add it to your project.
You must also enable Google Cloud Run for the user or service account you will use for this tutorial. Go to the IAM & Admin console. Find the account you want to use and click the pencil icon for "Edit Member". Add the "Cloud Run Admin" (or similar) role to the account you will use for this tutorial.
Authenticate to Google Cloud
Waypoint will use your locally configured Google Cloud credentials to deploy your application.
Login to Google Cloud from your machine.
Find your Google Cloud project ID. Use the value under PROJECT_ID
.
Set your project ID (replace waypoint-project-id
with your Google Cloud project's ID).
In order to communicate between your local Docker instance, the remote container registry, and Google Cloud Run, you must configure Docker for Google Cloud. Run the auth configure-docker
command.
Install the Waypoint server
You're now ready to configure and run Waypoint.
The Waypoint server can be run locally or on a remote server. The local installation requires fewer steps to setup. A remote installation will enable the full functionality of Waypoint, including logs
, exec
, and other commands.
Install the Waypoint server to your local Docker instance. In this scenario, Google Cloud Run does not run the Waypoint server, so you can run it locally.
If you run into any errors, see the troubleshooting page which has instructions for resetting the Waypoint server in Docker.
Note
The logs
, exec
, and other commands will not work with a local server and a remote deployment.
Configure waypoint
Edit waypoint.hcl
to specify your Google Cloud project ID instead of waypoint-project-id
. Let's examine a few relevant snippets first.
In the build
section, this configuration uses the standard docker
plugin to find the Docker repository. In this case, the URL to gcr.io
with your Google Cloud project ID and the name of this Waypoint application are all that's needed. There is no GCR-specific plugin for Waypoint since this URL is all that's needed.
In the deploy
section, you can specify the project and location. There are many other options for memory
, cpu_count
, and machine-specific configuration. See the Google Cloud Run plugin documentation for other arguments.
Here is the full configuration found in waypoint.hcl
.
Initialize waypoint
Now, let's run initialize and run Waypoint.
You'll see messages indicating that the configuration is valid and the project was correctly set up.
Run waypoint up
Deploy the application to Google Cloud Run with up
.
This may take a few minutes to run since it needs to copy the Docker image to the Google Container Registry.
Visit either URL shown in the output to see the running application.
Destroy the deployment
When you are done, destroy the deployment.
If you see an error message, it may be that the container is completing another task. To solve this, wait a minute or two and run destroy
again.
Next steps
Read the plugin API documentation for more details.
Learn more about Waypoint by following along with the other tutorials for AWS, Azure, and others, or read the documentation for other Waypoint plugins.