Scott Hanselman

Trying ASP.NET Core on the Google Cloud Platform "App Engine Flexible Environment"

March 30, 2017 Comment on this post [5] Posted in DotNetCore
Sponsored By

Last week I used Zeit and "now" to deploy an ASP.NET Core app (via a container) to the Zeit cloud. Tonight the kids are asleep so I thought I'd deploy to the Google Cloud. They've got beta support for open source ASP.NET so it's a perfect time. Google even has Google Cloud Tools for Visual Studio (2015).

I'll install the Google Cloud SDK. I checked "beta" as well.

Installing the Google Cloud SDK

Install it, login to your Google account and setup/select a project. I make a new folder and put an "app.yaml" in there with this inside as a directive to the Google Cloud Platform.

runtime: aspnetcore
env: flex

Here's a gratuitous screenshot:

App.yaml

I did a dotnet new, dotnet restore, and finally a:

dotnet publish -c Release

which makes a publish folder that will get sent up to the cloud.

IMPORTANT NOTE: I initially tried to push a .NET Core app using the .NET Core 1.1 runtime but Google Cloud's beta support in the flexible environment is set up for the 1.0.3 runtime (using their own custom docker base image) as of the time of this blog post, so you'll want to "dotnet new mvc --framework netcoreapp1.0" and set the "RuntimeFrameworkVersion" to get that specific shared LTS (Long Term Support) version. As soon as the Google Cloud flex runtime has the latest LTS (1.0.4, at the time of this writing) then apps would just roll forward.

<PropertyGroup>
  <TargetFramework>netcoreapp1.0</TargetFramework>
<RuntimeFrameworkVersion>1.0.3</RuntimeFrameworkVersion> </PropertyGroup>

Otherwise you'll get errors. Fortunately those errors are very clear.

.NET Core Runtime 1.0.3 supported

The walkthrough on Google Cloud suggests you copy the app.yaml file using a standard CLI copy command. However, since you're going to need that app.yaml EVERY publish, just add it to the csproj like this:

<ItemGroup>
<Content Include="app.yaml" CopyToOutputDirectory="Always" />
</ItemGroup>

This way it'll end up in publish automatically. You can then publish to the "AppEngine flexible environment:

dotnet restore
dotnet publish -c Release
gcloud beta app deploy .\bin\Release\netcoreapp1.0\publish\app.yaml
gcloud app browse // THIS IS JUST TO VISIT IT AFTER IT'S PUBLISHED

NOTE: You may get an ERROR that billing isn't enabled, or that the cloudbuild.googleapis.com aren't enabled. You'll need to ensure you have an active Free Trial, then go to the API Manager in the Google Cloud Platform dashboard and enable "Google Cloud Container Builder API." I also had to manually enable the API for the "Flexible" Environment and confirm I had a valid billing account.

Needed to enable some Billing APIs in the Google Cloud

Once I enabled a few APIs, I just did a standard "gcloud beta app deploy" as above:

gcloud beta app deploy

Pretty cool stuff! Here is my ASP.NET Core app running on GCP's Flex engine:

ASP.NET on Google Cloud

You can "tail" your app with "gcloud app logs tail -s default" and you'll see the output from .NET Core and ASP.NET (and Kestrel) in the Google Cloud!

gcloud app logs tail -s default

Or online in the Google "Stackdriver" logging page:

Google Stackdriver Logging page showing ASP.NET Core Logging

Go read up more on the Google Cloud Platform Blog. They even support Kubernetes clusters with ASP.NE Core apps packaged as Docker containers.


Sponsor: Thanks to Redgate! Track every change to your database! See who made changes, what they did, & why, with SQL Source Control. Get a full version history in your source control system. See how.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
March 30, 2017 12:30
Great to see you trying this, Scott :)

You might also want to give it a go on Container Engine - a similar experience, but based on Kubernetes.

Chris Smith and I presented on this at Google Cloud Next 2017: https://www.youtube.com/watch?v=wBbi5A1wlbk
March 30, 2017 13:28
You could deploy your project as a self-contained app, with any version of the runtime ?
March 30, 2017 14:03
Hi Scott, thanks for the post ;)

Could you please answer -- do docker/kubernetes support only .NET core?
Can GCloud's AppEngine be used to host non-core asp apps?
March 30, 2017 15:30
Really good to see there are options and using .NET Core does not restrict from deploying it anywhere (well mostly anywhere). Thanks for sharing little gems Scott, as always :)
March 31, 2017 6:30
copy con

wow, that brought back some memories.
PT

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.