
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
Configure your environment and project
/ 30
Build and run an application on Cloud Run
/ 70
Buildpacks are another approach for building container images and provide an alternate approach to turn your source code into a container image. Buildpacks are distributed and executed in images called builders. Each builder can have one or more buildpacks. A builder turns your source code into a container image. The buildpacks do the actual work to build and package the container image that you can deploy to Cloud Run or run with Docker locally.
You can create your own buildpacks, or use those provided by multiple vendors. Google Cloud's buildpacks allow developers to create and deploy containerized applications without the need to install Docker locally, or create a Dockerfile. Buildpacks are also built into Cloud Run to enable a source-based deployment workflow.
In this lab, you:
pack
, a command-line tool that is used with builders to create container images from source code.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, and configure your Cloud Shell environment.
To set your project ID and region environment variables, in Cloud Shell, run the following commands:
Set the compute region in Cloud Shell:
To use Cloud Run, and the Google Translate API later in this lab, enable relevant APIs for your project:
Click Check my progress to verify the objective.
In this task, you build a sample application with the pack
command line tool and the Google Cloud's buildpacks builder.
Create an app
directory and change to it:
Copy the sample python
application for this lab from Cloud Storage, and extract the contents from the archive:
View the sample application files and source code:
The application is written in Python and returns a sample welcome message in response to a request made to the application.
Change to the sample application directory:
To build the container, run pack
:
A partial output is similar to:
To view the images downloaded and built in your Cloud Shell host, run:
Run the container locally in Docker by passing in the PORT environment variable to the application and binding the host's port 8080 to the container port:
Test the containerized application with the curl
command:
You should see the following message as a response:
Typically, as a next step in your development and deployment lifecycle, you should push the container image that you built in the previous task to Artifact Registry, and then deploy the image to a container-based environment like Google Kubernetes Engine or Cloud Run.
In this task, you modify the sample application code, then build and deploy the containerized application directly from source with Cloud Run.
You modify the sample application code to use the Google Translation API that translates a piece of text from English to Spanish.
Edit the main.py
file with an editor of your choice, for example, vi or nano. You can also click Open Editor from the Cloud Shell menu to edit the file.
Replace the entire contents of the main.py
file with the code below:
To build and deploy the container on Cloud Run, execute the following command:
When prompted, type Y to accept the default repository that is created in Artifact Registry to store the container image.
When the command completes, a Cloud Run service named sample-py-app
is created.
The command output is similar to:
Set an environment variable for the Cloud Run service that was created in the previous step:
To test the service, , and execute the curl
command:
Click Check my progress to verify the objective.
In this lab, you built an application with the pack
command, and the Google Cloud's buildpacks builder to build a container image for a sample python application. You first ran and tested the container locally with Docker before rebuilding and deploying the container to Cloud Run.
For more information, view the documentation:
Learn about Google Cloud's buildpacks for different container platforms such as GKE, Anthos, and Container-Optimized OS:
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