
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Enable Relevant APIs
/ 20
Build a container image with Cloud Build
/ 30
Deploy the container to Cloud Run
/ 30
Test the application on Cloud Run
/ 20
Cloud Run is a fully managed compute platform that allows you to run stateless containers that are invocable with HTTP requests. You can deploy code written in any programming language on Cloud Run if you can build a container image from it. You can use the source-based deployment option that builds the container for you when developing your application in Go, Node.js, Python, Java, .NET Core, or Ruby.
Cloud Run is serverless, and runs your containers on Google's scalable infrastructure. It's built on Knative, and lets you choose to run your containers either fully managed with Cloud Run, or in your Google Kubernetes Engine cluster with Cloud Run on GKE.
Cloud Run works well with other services on Google Cloud, so you can build full-featured applications without spending too much time operating, configuring, and scaling your Cloud Run service.
In this lab, you:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
In this task, you set environment variables for your Cloud Shell environment, and enable the relevant Google APIs for use in this lab.
Sign in to the Google Cloud console with your lab credentials, and open the Cloud Shell terminal window.
To set your project ID and region environment variables, in Cloud Shell, run the following commands:
To enable relevant APIs, run the following command:
To verify the objective, click Check my progress.
In this task, you copy a sample Node.js application. Then, you build and run it locally in your Cloud Shell environment.
Create an app
directory, and make it the current working directory:
To copy the app from Cloud Storage, and extract it's files, execute the following command:
Change to the app directory:
To view the application source code, view the contents of the server.js
file in the top-level directory:
To install the app's dependency modules locally, execute the following command:
To run the app locally, execute the following command:
You should see the following output:
To open a second Cloud Shell terminal window, in the Cloud Shell navigation bar, click ().
Test the sample API by making a few HTTP requests to the application:
The application should respond with a list of products:
Make a second API request to fetch a specific product by ID:
The application should respond with details about the specific product:
To exit the application, in the first Cloud Shell terminal window, type Ctrl+C.
Cloud Build is a service that executes your builds on Google Cloud. With Cloud Build, you can continuously build, test, and deploy your application by using a continuous integration and delivery (CI/CD) pipeline.
To provide instructions to Cloud Build, you create a build configuration file that contains a set of tasks. These instructions can configure builds to fetch dependencies, run unit and integration tests, perform static analysis, and create artifacts with build tools like docker, gradle, maven, and others.
In this task, you use Cloud Build to build a Docker container for your application, and push the resulting container image to a repository in Artifact Registry.
On the Google Cloud console title bar, in the Search field, type Artifact Registry, click Search, and then click Artifact Registry.
Click the ( Pin) next to Artifact Registry.
Click Create Repository.
In the Create repository page, provide the following information, and leave the remaining settings as their defaults:
Name |
my-repo |
Format |
Docker |
Location type |
Region |
Region |
|
Click Create, and wait for the repository to be created.
Before you can push images to the repository, you must configure Docker to authenticate requests to the repository in Artifact Registry.
To set up authentication to Docker repositories in the region
When prompted, type Y.
To provide instructions to Cloud Build, you create a build configuration file that contains a set of tasks. These instructions can configure builds to fetch dependencies, run unit and integration tests, perform static analysis, and create artifacts with builders like docker, gradle, maven, and others.
Set an environment variable for the repository name:
Create the build configuration file:
View the cloudbuild.yaml
file:
To build the container with Cloud Build, execute the following command:
Here's similar (partial) output from the command:
Cloud Build first uploads your application source code and other files from the specified directory to Cloud Storage. It then builds the container image that contains your application from the instructions specified in the build configuration and Dockerfile, tags the image with the specified image name, and pushes the image to the repository in Artifact Registry.
On the Google Cloud console title bar, in the Search field, type Cloud Build, click Search, and then click Cloud Build.
For Region, select
Click the build ID for the build at the top of the list.
The details of the build, including the build log, are displayed.
After the build command completes, in the Google Cloud console, in the navigation menu (), click Artifact Registry > Repositories.
Click the my-repo repository to display the sample-node-app-image container image.
To verify the objective, click Check my progress.
With the container image built, you can now deploy it to Cloud Run. There are two approaches for deploying to Cloud Run:
Managed Cloud Run: A fully managed service model where the entire container lifecycle is managed by Cloud Run. You use this approach in this lab.
Cloud Run on Anthos: Cloud Run with an extra layer of control, which lets you bring your own clusters and pods from GKE.
In this task, you deploy your container image to the fully managed Cloud Run service on Google Cloud.
To deploy the container image, in Cloud Shell, execute the following command:
After the command completes, in the Google Cloud console, in the navigation menu () click Cloud Run.
To display the details of the Cloud Run service, click the sample-node-app service name.
To verify the objective, Click Check my progress.
To verify that the service is running, and available to accept requests, in Cloud Shell, execute the following command:
The output of the command is similar to:
From the command output, copy the value of the URL, and paste it in the curl command appending service/products
to the end of the URL as shown. Pipe the output to the jq
command, and press ENTER:
The output should be similar to that received from the application when you run it locally in an earlier task.
To verify the objective, click Check my progress.
In this lab, you:
For more information, view the documentation on:
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one