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:
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
Note: The Dockerfile will be used to create a local image.
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.
Note: To access the Web preview icon, you may need to collapse the Navigation menu.
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.
Note: 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:
Navigate to the source directory:
cd ~/python-docs-samples/appengine/standard_python3/hello_world
Deploy your Hello World application.
gcloud app deploy
Note: If prompted "Do you want to continue (Y/n)?", press Y and then Enter.
This app deploy command uses the app.yaml file to identify project configuration.
Note: If you get a Gaia propagation related error message, re-run the 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.
Deploy the Hello World application to App Engine
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.
Moduły tworzą projekt Google Cloud i zasoby na określony czas.
Moduły mają ograniczenie czasowe i nie mają funkcji wstrzymywania. Jeśli zakończysz moduł, musisz go zacząć od początku.
Aby rozpocząć, w lewym górnym rogu ekranu kliknij Rozpocznij moduł.
Użyj przeglądania prywatnego
Skopiuj podaną nazwę użytkownika i hasło do modułu.
Kliknij Otwórz konsolę w trybie prywatnym.
Zaloguj się w konsoli
Zaloguj się z użyciem danych logowania do modułu. Użycie innych danych logowania może spowodować błędy lub naliczanie opłat.
Zaakceptuj warunki i pomiń stronę zasobów przywracania.
Nie klikaj Zakończ moduł, chyba że właśnie został przez Ciebie zakończony lub chcesz go uruchomić ponownie, ponieważ spowoduje to usunięcie wyników i projektu.
Ta treść jest obecnie niedostępna
Kiedy dostępność się zmieni, wyślemy Ci e-maila z powiadomieniem
Świetnie
Kiedy dostępność się zmieni, skontaktujemy się z Tobą e-mailem
Jeden moduł, a potem drugi
Potwierdź, aby zakończyć wszystkie istniejące moduły i rozpocząć ten
Aby uruchomić moduł, użyj przeglądania prywatnego
Uruchom ten moduł w oknie incognito lub przeglądania prywatnego. Dzięki temu unikniesz konfliktu między swoim kontem osobistym a kontem do nauki, co mogłoby spowodować naliczanie dodatkowych opłat na koncie osobistym.
In this lab, you create a simple App Engine application using the Cloud Shell local development environment, and then deploy it to App Engine.
Czas trwania:
Konfiguracja: 1 min
·
Dostęp na 20 min
·
Ukończono w 20 min