Deploying containers on Google App Engine

In my last blog about Serverless Applications with Google App Engine we looked at how to create and deploy simple Flask/Python based application on Google App Engine (GAE). The application is a Serverless Continuous Running Application or ‘SCRA’. A SCRA application runs continuously, has virtually no limit on the code size and programming languages that can be used and you pay only for what you use. Above all, with SCRA applications, you don’t manage servers.

This time we will deploy the application to Google App Engine (GAE) Containers. Lets take a look!

Google App Engine

GAE is a platform for serverless applications that provides development and hosting capabilities to developers. Programs can be developed in most popular programming languages like Python, Go and Java. GAE provides the infrastructure for running web applications at cloud scale. The architecture of GAE is fixed which means that GAE is fit for purpose for certain applications like stateful web applications.

Custom Runtimes and Containers

To support running unsupported runtimes on GAE, like eg. Haskell, Google App Engine provides support for Custom Runtimes in the GAE flexible environment. Custom runtimes are created with a Dockerfile with a base image of choice.

When creating custom runtimes, the application must listen to port 8080,

Example

Compared to the GAE – Python example, the GAE Custom Runtime example contains the following main differences:

.
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── app.yaml
├── main.py
└── requirements.txt.

The file app.yaml defines the custom runtime and flex environment.

<span style="font-weight:bold">runtime</span>:<span style="color:#bbb"> </span>custom<span style="color:#bbb">
</span><span style="color:#bbb"></span><span style="font-weight:bold">env</span>:<span style="color:#bbb"> </span>flex<span style="color:#bbb">
</span>

THe main difference is the addition of a Dockerfile:

<span style="font-weight:bold">FROM</span><span style="color:#b84"> 'python:3.7.1-alpine3.8'</span><span style="color:#a61717;background-color:#e3d2d2">
</span><span style="color:#a61717;background-color:#e3d2d2"></span><span style="font-weight:bold">ADD</span> requirements.txt /<span style="color:#a61717;background-color:#e3d2d2">
</span><span style="color:#a61717;background-color:#e3d2d2"></span><span style="font-weight:bold">RUN</span> pip install -r requirements.txt<span style="color:#a61717;background-color:#e3d2d2">
</span><span style="color:#a61717;background-color:#e3d2d2"></span><span style="font-weight:bold">ADD</span> main.py /<span style="color:#a61717;background-color:#e3d2d2">
</span><span style="color:#a61717;background-color:#e3d2d2"></span><span style="font-weight:bold">EXPOSE</span><span style="color:#b84"> 8080</span><span style="color:#a61717;background-color:#e3d2d2">
</span><span style="color:#a61717;background-color:#e3d2d2"></span><span style="font-weight:bold">CMD</span> python main.py<span style="color:#a61717;background-color:#e3d2d2">
</span>

To deploy the example type make deploy and to invoke the application type make browse. To remove the application, it must be disabled. A GAE can only be disabled by means of the web console. You have to login to console.cloud.google.com,
choose your project, navigate to GAE, go to settings and disable the application.

The username is user and the password is password.

Deploying to App Engine

The GAE deployment proces detects that the application defines a custom runtime. GAE will upload all project files to GAE and automatically build and upload a container to the Google Docker Registry called appengine which is part of the GCP project.

GAE will then automatically deploy the application and do a rolling update.

Conclusion

The GAE workflow for a custom runtime is the same as for a managed runtime. For a custom runtime a Dockerfile must be added that defines the application runtime and application dependencies. The container should expose port 8080 to get requests forwarded by GAE.

Share this article: Tweet this post / Post on LinkedIn