In this series of labs, you take a demo microservices Java application built with the Spring framework and modify it to use an external database server. You adopt some of the best practices for tracing, configuration management, and integration with other services using integration patterns.
So far in the labs, you've tested the application by running the application in Cloud Shell. Many options are available to deploy your application on Google Cloud. For example, you can deploy the application to virtual machines that you configure yourself. Or you can containerize your application and deploy it into a managed Google Kubernetes Engine cluster. You can also run your favorite platform as a service on Google Cloud (for example, Cloud Foundry and OpenShift).
App Engine is Google's fully managed serverless application platform. With App Engine, you can build and deploy applications on a fully managed platform. You can scale your applications without having to worry about managing the underlying infrastructure. App Engine includes capabilities such as automatic scaling-up and scaling-down of your application, and fully managed patching and management of your servers.
In this lab, you deploy the application into App Engine. You convert the application from fat WARs into the thin-WAR deployments that App Engine can deploy.
Objectives
In this lab, you learn how to perform the following tasks:
Initialize App Engine
Reconfigure an application to work with App Engine
Configure the Cloud Runtime Configuration API to automatically provide the backend URL to the Frontend application
Deploy the application to App Engine
Setup and requirements
How to start your lab and sign in to the Console
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method.
On the left is a panel populated with the temporary credentials that you must use for this lab.
Copy the username, and then click Open Google Console.
The lab spins up resources, and then opens another tab that shows the Choose an account page.
Note: Open the tabs in separate windows, side-by-side.
On the Choose an account page, click Use Another Account. The Sign in page opens.
Paste the username that you copied from the Connection Details panel. Then copy and paste the password.
Note: You must use the credentials from the Connection Details panel. Do not use your Google Cloud Skills Boost credentials. If you have your own Google Cloud account, do not use it for this lab (avoids incurring charges).
Click through the subsequent pages:
Accept the terms and conditions.
Do not add recovery options or two-factor authentication (because this is a temporary account).
Do not sign up for free trials.
After a few moments, the Cloud console opens in this tab.
Note: You can view the menu with a list of Google Cloud Products and Services by clicking the Navigation menu at the top-left.
After you complete the initial sign-in steps, the project dashboard appears.
Task 1. Fetch the application source files
In this task, you clone the source repository files that are used throughout this lab.
To begin the lab, click the Activate Cloud Shell button at the top of the Google Cloud Console and if prompted click Continue.
To activate the code editor, click the Open Editor button on the toolbar of the Cloud Shell window.
Click Open in a new window to set up the editor in a new tab with continued access to Cloud Shell.
Note: A Cloud Storage bucket that is named using the project ID for this lab is automatically created for you by the lab setup. The source code for your applications is copied into this bucket when the Cloud SQL server is ready. You might have to wait a few minutes for this action to complete.
In Cloud Shell, click Open Terminal and then enter the following command to create an environment variable that contains the project ID for this lab:
export PROJECT_ID=$(gcloud config list --format 'value(core.project)')
Verify that the demo application files were created:
The message The app is now created indicates that App Engine is enabled.
Note: App Engine deployments are regional. That is, your application might be deployed to multiple zones within a region. In general, you should deploy your App Engine application near your backend or database.
Task 3. Deploy Guestbook Frontend
In this task, you add the App Engine plugin to the guestbook frontend's pom.xml file.
In the Cloud Shell code editor, open ~/guestbook-frontend/pom.xml.
Add the following code at the end of the <plugin> section, immediately before the closing </plugins> tag:
In Cloud Shell, create an App Engine directory in Guestbook Frontend:
mkdir -p ~/guestbook-frontend/src/main/appengine
In the Cloud Shell code editor, create a file named app.yaml in the ~/guestbook-frontend/src/main/appengine/ directory. This file is required to deploy the application to App Engine.
Add the following code to the app.yaml file. Make sure to replacePROJECT_ID with your Project ID. You can use the command echo $PROJECT_ID in the Cloud Shell to retrieve it:
runtime: java
env: flex
runtime_config:
operating_system: "ubuntu22"
runtime_version: "21"
manual_scaling:
instances: 2
env_variables:
SPRING_PROFILES_ACTIVE: cloud
MESSAGES_ENDPOINT: https://guestbook-service-dot-PROJECT_ID.appspot.com/guestbookMessages
resources:
cpu: 1
memory_gb: 1
disk_size_gb: 10
handlers:
- url: /.*
script: this field is required, but ignored
In Cloud Shell, change to the frontend application directory:
cd ~/guestbook-frontend
Use Apache Maven to deploy the frontend application to App Engine. The deployment should take a few minutes:
mvn package appengine:deploy -DskipTests
Note: You may need to run the command twice if there is a build error!
This command reports out success like the following example:
[INFO] GCLOUD: Deployed service [default] to [https://PROJECT_ID.appspot.com]
[INFO] GCLOUD:
[INFO] GCLOUD: You can stream logs from the command line by running:
[INFO] GCLOUD: $ gcloud app logs tail -s default
[INFO] GCLOUD:
[INFO] GCLOUD: To view your application in the web browser run:
[INFO] GCLOUD: $ gcloud app browse
[INFO] ------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------
[INFO] Total time: 03:00 min
[INFO] Finished at: 2018-12-08T10:30:09Z
[INFO] ------------------------------------------------------
Find the frontend URL:
gcloud app browse
This command reports a URL that links to your application's frontend:
Did not detect your browser. Go to this link to view your app:
https://....appspot.com
Click the link to open a browser tab to the frontend URL.
An error occurs because the backend isn't deployed yet:
Leave the tab open. You'll come back to this later.
Task 4. Deploy Guestbook Service
In this task, you will add the App Engine Plugin to guestbook-service's pom.xml.
In the ~/guestbook-service/pom.xml file, add the following code at the end of the <plugin> section, immediately before the closing </plugins> tag:
Create an App Engine directory in Guestbook Service:
mkdir -p ~/guestbook-service/src/main/appengine
In the Cloud Shell code editor, create a file named app.yaml in the ~/guestbook-service/src/main/appengine/ directory. This file is required to deploy the application to App Engine.
Add the following code to the app.yaml file:
runtime: java
env: flex
service: guestbook-service
runtime_config:
operating_system: "ubuntu22"
runtime_version: "21"
manual_scaling:
instances: 2
env_variables:
SPRING_PROFILES_ACTIVE: cloud
resources:
cpu: 1
memory_gb: 1
disk_size_gb: 10
handlers:
- url: /.*
script: this field is required, but ignored
Note: This configuration uses manual scaling rather than automatic scaling. This is great if you want to have fine control over the number of application instances. However, in a production setting, you may want to use automatic scaling that can adapt dynamically to the load.
In Cloud Shell, first change to your guestbook-service directory, then use Maven to deploy the application. This will take a few minutes:
cd ~/guestbook-service
./mvnw package appengine:deploy -DskipTests
Find the deployed backend URL. Click the URL link for the backend guestbook service:
gcloud app browse -s guestbook-service
Links similar to the ones in the screenshot are displayed. You can use these URLs to list and inspect the contents of messages that have been posted to the application:
Follow the href links to see the messages, for example: https://guestbook-service-dot-PROJECT.appspot.com/guestbookMessages, and see the sample message that is preloaded by the lab setup process:
Lastly, switch to the tab showing the error generated by the frontend application and refresh the page. You should now see the correct user message posting interface that you are familiar with from earlier labs. You see the initial sample message that is preloaded by the lab setup process. Instead of running in Cloud Shell, the application is now running as two separate services on App Engine!
Task 5. Review
In this lab, you initialized App Engine and reconfigured an application to work with App Engine. You also configured the Cloud Runtime Configuration API to automatically provide the backend URL to the Frontend application. Finally, you deployed the application to 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.
I lab creano un progetto e risorse Google Cloud per un periodo di tempo prestabilito
I lab hanno un limite di tempo e non possono essere messi in pausa. Se termini il lab, dovrai ricominciare dall'inizio.
In alto a sinistra dello schermo, fai clic su Inizia il lab per iniziare
Utilizza la navigazione privata
Copia il nome utente e la password forniti per il lab
Fai clic su Apri console in modalità privata
Accedi alla console
Accedi utilizzando le tue credenziali del lab. L'utilizzo di altre credenziali potrebbe causare errori oppure l'addebito di costi.
Accetta i termini e salta la pagina di ripristino delle risorse
Non fare clic su Termina lab a meno che tu non abbia terminato il lab o non voglia riavviarlo, perché il tuo lavoro verrà eliminato e il progetto verrà rimosso
Questi contenuti non sono al momento disponibili
Ti invieremo una notifica via email quando sarà disponibile
Bene.
Ti contatteremo via email non appena sarà disponibile
Un lab alla volta
Conferma per terminare tutti i lab esistenti e iniziare questo
Utilizza la navigazione privata per eseguire il lab
Utilizza una finestra del browser in incognito o privata per eseguire questo lab. In questo modo eviterai eventuali conflitti tra il tuo account personale e l'account Studente, che potrebbero causare addebiti aggiuntivi sul tuo account personale.
Java Microservices with Spring Boot
Lab 09 Deploying to App Engine
Durata:
Configurazione in 1 m
·
Accesso da 120 m
·
Completamento in 120 m