Overview
In this lab, you create and deploy a simple App Engine application using
a virtual environment in the Google Cloud Shell.
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.
1. In GCP console, on
the top right toolbar, click the Open Cloud Shell button.
gcloud is the
command-line tool for Google Cloud Platform. It comes pre-installed on Cloud
Shell and supports tab-completion.
2.You can list the active account name with this command:
gcloud auth list
Output:
Credentialed accounts:
- <myaccount>@<mydomain>.com
(active)
Example output:
Credentialed accounts:
-
google1623327_student@qwiklabs.net
You can list the project ID with this command:
gcloud config list project
Output:
[core]
project = <project_ID>
Example output:
[core]
project = qwiklabs-gcp-44776a13dea667a6
Full documentation of gcloud is available on Google Cloud gcloud Overview
Task 1: Initialize App Engine
1. Initialize your App
Engine app with your project and choose its region:
2. gcloud app create
--project=$DEVSHELL_PROJECT_ID
When prompted, select the region where you want your
App Engine application located.
3. Clone the source
code repository for a sample application in the hello_world directory:
4. git clone
https://github.com/GoogleCloudPlatform/python-docs-samples
5. Navigate to the
source directory:
6. cd
python-docs-samples/appengine/standard_python37/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.
1. Execute the
following command to download and update the packages list.
2. sudo apt-get update
3. Set up a virtual environment
in which you will run your application.
Python virtual environments are used
to isolate package installations from the system.
sudo apt-get install virtualenv
virtualenv -p python3 venv
If prompted [Y/n], press Y and then Enter.
4. Activate the virtual
environment.
5. source venv/bin/activate
6. Navigate to your
project directory and install dependencies.
7. pip install -r requirements.txt
8. Run the
application:
9. python main.py
10.
In Cloud Shell, click Web preview () > Preview
on port 8080 to preview the application.
To access the Web preview icon,
you may need to collapse the Navigation menu.
Result:
1. To end the test,
return to Cloud Shell and press Ctrl+C to abort the deployed
service.
2. Using the Cloud
Console, verify that the app is not deployed. In the Cloud Console, on
the Navigation menu (),
click App Engine > Dashboard.
Notice that no resources are
deployed.
Task 3: Deploy and run Hello World on App Engine
To deploy your application to the App Engine Standard environment:
1. Navigate to the source
directory:
2. cd
~/python-docs-samples/appengine/standard_python37/hello_world
3. Deploy your Hello
World application.
4. gcloud app deploy
This app deploy command
uses the app.yaml file to identify project configuration.
5. Launch your browser
to view the app at http://YOUR_PROJECT_ID.appspot.com
6. gcloud app browse
Copy and paste the URL into a new browser window
Congratulations! You created your first application using App Engine.
Click Check
my progress to verify the objective.
Deploy the Hello World application to App Engine
Check my progress
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.
1. In the Cloud
Console, on the Navigation menu (),
click App Engine > Settings.
2. Click Disable
application.
3. Read the dialog
message. Enter the App ID and click DISABLE.
If you refresh the browser window you used to view to the application
site, you'll get a 404 error.
0 comments:
Post a Comment