Wednesday, May 23, 2018

GCP - App Engine - Quickstart (Node.js)

Introduction

In this tutorial, you'll deploy a sample Node.js application to Google App 
By the end, you'll have learned how to:
  • Configure Deployments
    Learn how to edit a YAML file to edit a deployment’s configuration
  • Deploy apps with Google Cloud Shell
    Deploy with Cloud Shell, a web-based command line tool
This is a real App Engine deployment, so when the tutorial is over you can keep working on it.

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
  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-20180523/nodejs_mvms_quickstart-2018-05-23-14-42
git clone https://github.com/GoogleCloudPlatform/nodejs-getting-started.git $TUTORIALDIR
Switch to the tutorial directory:
cd $TUTORIALDIR/1-hello-world

Configuring your deployment

You are now in the main directory for the sample code. We'll look at the files that configure your application.

The app.js file contains the JavaScript code to start a server and respond to requests.
The following code responds to requests from web clients by displaying the Hello World message, via a server that runs on port 8080.

Google App Engine uses YAML files to specify a deployment's configuration. app.yaml files contain information about your application, like the runtime environment, URL handlers, and more.


Testing your app

    Install npm packages
    We will install the npm packages on Cloud Shell in order to test run the Node.js app.
    To install npm packages, enter:
    npm install
  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:
    export PORT=8080
    npm start
  2. 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.
  3. Terminating the preview instance
    Terminate the instance of the application by pressing Ctrl+C in the Cloud Shell.

    Last steps

    Ensuring Compute Engine is initialized
    Compute Engine needs a few moments to initialize. The tutorial will continue automatically once it's ready.
    Deploying with Cloud Shell
    You can use Cloud Shell to deploy your app. To deploy your app enter:
    gcloud app deploy --project crawler-20180523
    Visit your app
    Congratulations! Your app has been deployed. The default URL of your app is crawler-20180523.appspot.com  Click the URL to visit it.
    The app is now running in the cloud. We will show you how to delete the project to avoid potential charges. 
    1. 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. Delete your tutorial project You should delete your project  to avoid additional charges.
      2. 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:

     

    Use MongoDB

    Deploy MongoDB on Compute Engine or use a managed, MongoDB service. 

    Learn to use Cloud Storage

    Cloud Storage is a powerful and simple object storage service.
     

No comments:

Post a Comment