.NET Core on Google App Engine

There is an easy tutorial on how to run .NET Core apps on Google Developers Codelabs. As a supplement to that I have some bits to share that may be of use to you.

Before we begin

Please read Google’s tutorial on how to Deploy an ASP.NET Core app to App Engine which links to Build and launch an ASP.NET Core app from Google Cloud Shell.

The stuff that I share below is correct to my best knowledge as at time of writing.

Alternative to Google Cloud Shell

You do not have to use Google Cloud Shell to run through their tutorial and you would very likely not use it for day-to-day development.

Visual Studio Code is a fine editor

Their guide shows Eclipse Orion. Alternatively you can install Visual Studio Code, a free and open source text editor for assorted programming languages. It runs on Windows, Mac and Linux.

Specify newer .NET Core runtime in Dockerfile

It is possible to use a newer version of the .NET Core runtime. Example:

FROM microsoft/dotnet:1.0.3-runtime
COPY . /app
WORKDIR /app
EXPOSE 8080/tcp
ENV ASPNETCORE_URLS http://*:8080
ENTRYPOINT ["dotnet", "HelloWorldAspNetCore.dll"]

The DLL filename is case sensitive on Linux.

Error while generating app.yaml

When I attempted to run the following command:

gcloud beta app gen-config --custom

It spewed errors:

ERROR: gcloud failed to load (gcloud.beta.app.gen_config): Problem loading
gcloud.beta.app.gen_config: cannot import name DependencyWarning.

This usually indicates corruption in your gcloud installation or problems with
your Python interpreter.

Had to do the following to fix it:

gcloud components reinstall

The app.yaml generated does not specify the underlying virtual machine specification required. The defaults are:

  • 1 core; not possible to have 0.2 or 0.5 unlike Compute Engine
  • 0.6GB RAM
  • 10GB disk, the minimum allowed
  • Health checks are enabled so you will see a lot of /_an/health accesses in Stackdriver logging
  • Auto scaling is enabled with minimum instances set to 2 which you probably do not need for development purposes

Set project before deploying

Be sure to set the current project to the desired one or else the app will be deployed to the wrong project!

gcloud config set project <project name>
gcloud app deploy

It is not free of charge

They do tell you to enable billing for a reason. .NET Core (and Node JS) can run only on App Engine Flexible Environment which has no free tier and no SLA unlike the Standard Environment. Only Python, Java, PHP and Go are supported on Standard Environment.

Since auto scaling is enabled by default with minimum of 2 instances, the bill will be for 2 of course.

Your app is hosted on [project].appspot-preview.com

You can setup a custom domain pointing to your App Engine but their servers issue a redirect to [project].appspot-preview.com. This has been reported in November 2016 by various people on Google Groups but still behaving the same when I tried just few days ago.

In short, App Engine Flexible Environment is good only for non-public facing services for now.

One-to-one relationship between Project and App Engine

It is not possible to have multiple App Engines per Project.

App Engine with multiple services

Their tutorial described how to deploy a single service named default. App Engine can have multiple services hosted within. The obvious benefit is cost saving and allows developers to build micro services that can be hosted on the same VM initially before moving out to scale in future.

Cleaning up

Stopping the instance saves you the bulk of the cost. There is a bit of leftovers though. Cloud Storage is still keeping the deployed files. You will find 5 buckets being created under your Project. They are named:

  • [project].appspot.com
  • staging.[project].appspot.com
  • [region].artifacts.[project].appspot.com
  • vm-config.[project].appspot.com
  • vm-containers.[project].appspot.com

Conclusion

It was a good exercise to explore the offerings of App Engine. I like the auto scale functionality but really need them to stop redirecting to appspot-preview.com which is a deal breaker.