Контрольні точки
Deploy the Hello World application to App Engine
/ 10
Google Cloud Fundamentals: Getting Started with App Engine
Overview
In this lab, you create and deploy a simple App Engine application using a virtual environment in the Google Cloud Shell.
Objectives
In this lab, you learn how to perform the following tasks:
- Initialize App Engine.
- Preview an App Engine application running locally in Cloud Shell.
- Deploy an App Engine application, so that others can reach it.
- Disable an App Engine application, when you no longer want it to be visible.
Set up your lab environment
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.
Activate Google Cloud Shell
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.
- You can list the active account name with this command:
Output:
Example output:
- You can list the project ID with this command:
Output:
Example output:
Task 1. Initialize App Engine
-
Initialize your App Engine app with your project and choose its region:
gcloud app create --project=$DEVSHELL_PROJECT_ID Note: When prompted, select the region where you want your App Engine application located. -
Clone the source code repository for a sample application in the hello_world directory:
git clone https://github.com/GoogleCloudPlatform/python-docs-samples -
Navigate to the source directory:
cd python-docs-samples/appengine/standard_python3/hello_world
Task 2. Run Hello World application locally
In this task, you run the Hello World application in a local, virtual environment in Cloud Shell.
Ensure that you are at the Cloud Shell command prompt.
-
Create a Dockerfile
touch Dockerfile -
Edit the Dockerfile [hint: nano Dockerfile] to contain the following content.
FROM python:3.8 WORKDIR /app COPY . . RUN pip install gunicorn RUN pip install -r requirements.txt ENV PORT=8080 CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 main:app
-
Build a container image to run a Python virtual environment.
docker build -t test-python . -
Run the application:
docker run --rm -p 8080:8080 test-python -
In Cloud Shell, click Web preview () > Preview on port 8080 to preview the application.
Result:
-
To end the test, return to Cloud Shell and press Ctrl+C to abort the deployed service.
-
Using the Cloud Console, verify that the app is not deployed. In the Cloud Console, on the Navigation menu (), click App Engine > Dashboard.
Task 3. Deploy and run Hello World on App Engine
To deploy your application to the App Engine Standard environment:
-
Navigate to the source directory:
cd ~/python-docs-samples/appengine/standard_python3/hello_world -
Deploy your Hello World application.
gcloud app deploy
Y
and then Enter
.This app deploy command uses the app.yaml file to identify project configuration.
gcloud app deploy
command.-
Launch your browser to view the app at http://YOUR_PROJECT_ID.appspot.com
gcloud app browse
Copy and paste the URL into a new browser window.
Result:
Congratulations! You created your first application using App Engine.
Click Check my progress to verify the objective.
Task 4. Disable the application
App Engine offers no option to Undeploy an application. After an application is deployed, it remains deployed, although you could instead replace the application with a simple page that says something like "not in service."
However, you can disable the application, which causes it to no longer be accessible to users.
-
In the Cloud Console, on the Navigation menu (), click App Engine > Settings.
-
Click Disable application.
-
Read the dialog message. Enter the App ID and click DISABLE.
If you refresh the browser window you used to view the application site, you'll get a 404 error.
Congratulations!
You created your first application using App Engine!
End your lab
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
- 1 star = Very dissatisfied
- 2 stars = Dissatisfied
- 3 stars = Neutral
- 4 stars = Satisfied
- 5 stars = Very satisfied
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
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.