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.
Les ateliers créent un projet Google Cloud et des ressources pour une durée déterminée.
Les ateliers doivent être effectués dans le délai imparti et ne peuvent pas être mis en pause. Si vous quittez l'atelier, vous devrez le recommencer depuis le début.
En haut à gauche de l'écran, cliquez sur Démarrer l'atelier pour commencer.
Utilisez la navigation privée
Copiez le nom d'utilisateur et le mot de passe fournis pour l'atelier
Cliquez sur Ouvrir la console en navigation privée
Connectez-vous à la console
Connectez-vous à l'aide des identifiants qui vous ont été attribués pour l'atelier. L'utilisation d'autres identifiants peut entraîner des erreurs ou des frais.
Acceptez les conditions d'utilisation et ignorez la page concernant les ressources de récupération des données.
Ne cliquez pas sur Terminer l'atelier, à moins que vous n'ayez terminé l'atelier ou que vous ne vouliez le recommencer, car cela effacera votre travail et supprimera le projet.
Ce contenu n'est pas disponible pour le moment
Nous vous préviendrons par e-mail lorsqu'il sera disponible
Parfait !
Nous vous contacterons par e-mail s'il devient disponible
Un atelier à la fois
Confirmez pour mettre fin à tous les ateliers existants et démarrer celui-ci
Utilisez la navigation privée pour effectuer l'atelier
Ouvrez une fenêtre de navigateur en mode navigation privée pour effectuer cet atelier. Vous éviterez ainsi les conflits entre votre compte personnel et le compte temporaire de participant, qui pourraient entraîner des frais supplémentaires facturés sur votre compte personnel.
In this lab, you create a simple App Engine application using the Cloud Shell local development environment, and then deploy it to App Engine.
Durée :
1 min de configuration
·
Accessible pendant 20 min
·
Terminé après 20 min