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

Dev Tips

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.

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:


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.

<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:

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

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 .binReleasenetcoreapp1.0publishapp.yaml

NOTE: You may get an ERROR that billing isn’t enabled, or that the 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.

Source link

Leave a Reply