Wednesday, December 20, 2017

GCP - App Engine - Quickstart (Java)

Introduction

This tutorial shows you how to deploy a sample Java  application to Google App Engine using the App Engine Maven plugin.
Here are the steps you will be taking.
  • Build and run your "Hello, world!" app
    You will learn how to run your app using Google Cloud Shell, right in your browser. At the end you'll deploy your app to the web using the App Engine Maven plugin.
  • After the app...
    Your app will be real and you'll be able to experiment with it after you deploy, or you can remove it and start fresh.

Using Google Cloud Shell

Cloud Shell is a built-in command line tool for the console. We're going to use Cloud Shell to deploy our app.
  1. Open Google Cloud Shell
    Open Cloud Shell by clicking
    from the navigation bar at the top. show me how
  2. Clone the sample code
    Use Cloud Shell to clone and navigate to the "Hello World" code. The sample code is cloned from your project repository to the Cloud Shell.
    In Cloud Shell enter:
    Clone a sample repository:
    TUTORIALDIR=src/crawler-188409/java_gae_quickstart-2017-12-21-14-03
git clone https://github.com/GoogleCloudPlatform/appengine-try-java.git $TUTORIALDIR
Switch to the tutorial directory:
cd $TUTORIALDIR
 

Configuring your deployment


  1. You are now in the main directory for the sample code. We'll look at the files that configure your application.
    1. Exploring the application
      Enter the following command to view your application code:
      cat src/main/java/myapp/DemoServlet.java
  2. This servlet responds to any request by sending a response containing the message Hello, world!.
  3. Exploring your configuration
    For Java, Google App Engine uses XML files to specify a deployment's configuration.
    Enter the following command to view your configuration file:
    cat pom.xml
  4. The helloworld app uses Maven, which means you must specify a Project Object Model, or POM, which contains information about the project and configuration details used by Maven to build the project.

 Testing your app

    1. Test your app on Cloud Shell
      Cloud Shell lets you test your app before deploying to make sure it's running as intended, just like debugging on your local machine.
      To test your app enter:
      mvn appengine:run
  1. Preview your app with "Web preview"
    Your app is now running on Cloud Shell. You can access the app by using "Web preview" to connect to port 8080. show me how
  2. Terminating the preview instance
    Terminate the instance of the application by pressing Ctrl+C in the Cloud Shell

    Create the application

    In order to deploy our app, we need to create an App Engine application. This sets up the app and selects a region.
    To create your app enter:
    gcloud app create

      Last steps

      1. Deploying with Cloud Shell
        You can use Cloud Shell to deploy your app. To deploy your app enter:
        gcloud config set project crawler-188409
      mvn appengine:deploy
    1. Visit your app
      Congratulations! Your app has been deployed. The default URL of your app is crawler-188409.appspot.com  Click the URL to visit it.
    2. View your app's status
      You can check in on your app by monitoring its status on the App Engine dashboard.
      Open the menu on the left side of the console.
      Then, select the App Engine section.

        Congratulations

        You have successfully deployed an App Engine application! Here are some next steps:
        1. Download the Google Cloud SDK and develop locally
      1. After it downloads, extract the file  and initialize the SDK .
      2. Build your next application Learn how to use App Engine with other Cloud Platform products:Learn to use Cloud Datastore Cloud Datastore is a highly-scalable NoSQL database for your applications.

        Learn to use Cloud Datastore

        Cloud Datastore is a highly-scalable NoSQL database for your applications. 

        Learn to use Cloud Storage

        Cloud Storage is a powerful and simple object storage service.
         
        .

1 comment: