Home / 

How to Configure and Deploy An Application on Google App Engine

Vishnuvardhan Nayakam

Vishnuvardhan Nayakam

Associate Software Engineer

Published Feb 05 2020

Writing code alone is not good enough to effortlessly run an application and maintain it. To ensure that the application is available to the user, many people work behind the scenes and manage different requests that come from the app, maintenance, server health checks, installing security patches, upgrading software packages, and firewalls to protect servers from hackers.

All of this seems like a gigantic task. Right?

Well, the answer is ‘No.’

Even though all these tasks require a significant amount of energy, focus, and efforts, in the era of cloud computing, some of these tasks can be automated via scripts.

This blog will talk about GCP’s App Engine and we will discuss the deployment of an application in the App Engine and the underlying processes by using Node.js application as an example. App Engine is one of the computing services provided by GCP. Let’s discuss them briefly.

  1. Compute Engine - Infrastructure as a Service (IaaS): It is a clean virtual machine (a new and an empty server). It’s important to take care of all configurations according to the requirement.
  2. App Engine - Platform as a Service (PaaS): It is a fully-managed service where we deploy code to make the application up and running. The maintenance, configuration, scaling, security patches, upgrades, etc. are managed by Google.
  3. Kubernetes Engine - Container as a Service (CaaS): It is a container management service and is widely used in microservices to make them lightweight and independent.
  4. Cloud Functions - Function as a service (FaaS): It is a fully-managed service. Some functions are executed for a few minutes or seconds. It doesn’t cause any wastage of resources while executing the function; instead, these cloud functions can be executed on the basis of triggers.

Cloud Computing Services Offered by GCP

To get an overview of agile data processing options available on the Google Cloud Platform (GCP) for data analytics, click here.

An Introduction to Google App Engine

The App Engine is a fully-managed platform as a service (PaaS) for building web applications in which the user doesn’t need to manage the underlying operating systems, configurations, security issues, firewalls, and auto-scaling. By using this service, developers can manage the entire application just by making a configuration file called app.yaml to make the code compatible with the App Engine.

The App Engine is based on serverless architecture. It is available with two types of runtime environments:

  1. Standard environment: It supports only a few languages, including Python, Node js, Go, PHP, .Net, Java. To deploy a Python application, it requires a standard environment along with a configuration file that defines our runtime environment in the file app.yaml.
  2. Flexible environment: It supports all kinds of applications and provides some control over the infrastructure. It uses Docker containers as a resource to run the application. Besides the supported runtimes, it can also make custom runtime using a Dockerfile.
Feature Standard environment Flexible environment
Instance startup time Seconds Minutes
Maximum request timeout Depends on the runtime and type of scaling. 60 minutes
Background threads Yes, with restrictions Yes
Background processes No Yes
SSH debugging No Yes
Scaling Manual, Basic, Automatic Manual, Automatic
Scale to zero Yes No, minimum 1 instance
Writing to local disk Java 8, Java 11, Node.js, Python 3.7, PHP 7.2, PHP 7.3, Ruby 2.5 (beta), Go 1.11, Go 1.12, and Go 1.13 have read and write access to the /tmp directory.
Python 2.7, Go 1.9, and PHP 5.5 don't have write access to the disk.
Yes, ephemeral (disk initialized on each VM startup)
Modifying the runtime No Yes (through Dockerfile)
Deployment time Seconds Minutes
Automatic in-place security patches Yes Yes (excludes container image runtime)
Access to App Engine APIs & Services such as NDB, Users API, Memcache, Images API and others. Yes for Python 2.7, Go 1.9, PHP 5.5, and Java 8
No for Java 11, Node.js, Python 3.7, PHP 7.2, PHP 7.3, Ruby 2.5 (beta), Go 1.11, Go 1.12, and Go 1.13
No
Network access Yes for Java 8, Java 11, Node.js, Python 3.7, PHP 7.2, PHP 7.3, Ruby 2.5 (beta), Go 1.11, Go 1.12, and Go 1.13.
Python 2.7, Go 1.9, and PHP 5.5 (billing-enabled): Only via App Engine services (includes outbound sockets).
Yes
Supports installing third-party binaries Yes for Java 8, Java 11 Node.js, Python 3.7, PHP 7.2, PHP 7.3, Ruby 2.5 (beta), Go 1.11, Go 1.12, and Go 1.13.
No for Python 2.7, Go 1.9, and PHP 5.5.
Yes
Location North America, Asia Pacific, or Europe North America, Asia Pacific, or Europe
(Source: Cloud.google.com)

Some of the features of the App Engine includes, zero-downtime for application deployment, scale-to-zero instance when there is no traffic, and traffic splitting between the latest and running version.

To get a comparative analysis of different cloud-storage services provided by Google Cloud Platform and Amazon Web Services for web applications, click here.

Understanding the App Engine Hierarchy

The App Engine’s hierarchy has four components - application, services, versions, and instances. An application that the customer needs is a combination of multiple services; each service can have various versions that are deployed in instances.

Hierarchy structure of App Engine

The best use cases to use the App Engine are those where you want zero downtime and you don’t want to:

  • configure and manage application infrastructure.
  • control security, firewalls, and SSL certificates of an application.
  • install and maintain packages required for the application.

It is better not to opt for App Engine when:

  • Having control over an underlying instance, configurations, and required packages is a must.
  • Need to run the application with customized images.

Configuring an Application for the App Engine

The App Engine does not understand the source code for deployment. The source code needs to be refactored with the configuration file called app.yaml, where it’s important to mention the runtime and scaling details.

Let’s discuss the information that the file app.yaml contains before taking a look at the sample file.

  • Runtime environment: Mention the source-code runtime here so that the App Engine can set up an environment to support and deploy the code for public usage.
  • Scaling information: Provide the information of scaling here, like what type of scaling is required to use for the application (automatic/basic/manual), how many instances will be available while scaling, and on how can it scales the application (on CPU utilization/concurrent requests/latency).
  • Resources information: Mention the number of CPUs, memory_gb (RAM), and disk_size available for the application.
  • Environment variables: Provide environment variables for the application, like passwords, API keys, etc., so that the application can use them securely.

It also contains information like health checks, network issues, etc. Let’s look at them directly in the sample app.yaml


service: my-service
runtime: nodejs10
instance_class: B8

automatic_scaling:
  target_cpu_utilization: 0.6
  min_instances: 1
  max_instances: 15
cool_down_period_sec: 180
  min_pending_latency: 30ms  # default value
  max_pending_latency: automatic
  max_concurrent_requests: 50

env_variables:
  BUCKET_NAME: "example-gcs-bucket"

network:
  instance_tag: TAG_NAME
  name: NETWORK_NAME
  subnetwork_name: SUB_NETWORK_NAME
  forwarded_ports:
	- PORT
	- HOST_PORT: CONTAINER_PORT
	- PORT/tcp
	- HOST_PORT: CONTAINER_PORT/udp

resources:
  cpu: 2
  memory_gb: 2.3
  disk_size_gb: 10
  volumes:
    - name: ramdisk1
      volumem_type: tmpfs
      size_gb: 0.5

liveness_check:
  path: "/liveness_check"
  check_interval_sec: 30
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2

(Source: Cloud.google.com)

A Brief on Google APP Engine Deployment, Versions, Migrating Traffic, and Switching Between Versions

The App Engine makes the application deployment process easy and fast. It can deploy the application by just typing "gcloud app deploy app.yaml." Also, it can have multiple versions for each service and seamlessly migrating traffic from one version to another in the App Engine by using a flag – ‘migrate.’ It can deploy and route the entire traffic to the latest version of the application with zero downtime.

The command mentioned below will migrate the entire traffic to version 2:

"gcloud app services set-traffic [MY_SERVICE] --splits [MY_VERSION]=2 --migrate"

It can also easily switch between the versions whenever any function is not working or when any new version is available.

The App Engine can quickly get the logs of our application from the stack driver logger, which saves all the log files by default. These logs will be visible only when they are filtered by selecting the Google App Engine (GAE) option. The App Engine enables the stack driver cloud debugging and monitoring by default.

Steps to Deploy an Application in the App Engine

With the above information, it is easy to understand the process of deploying an application in the App Engine, as mentioned below:

  1. Go to the Google cloud console and create an App Engine with runtime – ‘nodejs’ and environment – ‘standard’ present under ‘compute.’

    Snapshot of Google coud console

  2. Open cloud shell and clone the source code from the repo https://github.com/vishnu123sai/App-engine-example.git
  3. Configuration file app.yaml is also available in the repo. In this example, other options like scaling, resources, etc. in configuration file are not being used for the sake of simplicity.
  4. Just type “gcloud app deploy” to deploy your application.

    Deploying Application on App Engine

  5. Once the application is deployed, the output on the link [PROJECT_ID].appspot.com will be visible.
    For example, if the project id is vital-framing-245415, then the application URL will be https://vital-framing-245415.appspot.com/
  6. Test the URL on chrome

    Testing the deployed application URL on Chrome

Congratulations! The application is successfully deployed on the App Engine.