Building Scaleable .NET Apps Without Windows
Tags: dotnet, docker, googlecloud
Published: 2020-11-09 15:20:31

“I built a .NET Web App on macOS in Visual Studio and deployed a Linux Docker container to Google App Engine.”

![](https://cdn-images-1.medium.com/max/5000/1*sN0W0Ji2er3Lgd7YirLBhQ@2x.png)

That is a phrase you don’t hear too often, if at all. It wasn’t much more than a few years ago that .NET core was released. This open-source project allowed .NET developers to free themselves from the Windows platform, and allowed Microsoft to expand into what was once unfriendly territory. Fast forward to current technology trends, and you will find .NET developers expanding out to Linux and Mac Based machines. This once paradoxical development flow led me on a personal path to see how these technologies would fit into my Google Cloud, Mac-centric world. As it turns out, it feels quite natural.

Paradigms around which cloud provider is right for what purpose have persisted over the past few years. When engineers think about deploying a Windows web application in the cloud, they automatically think of Microsoft Azure. When Data Scientists want best-of-breed in Machine Learning and Analytics, they automatically think of Google Cloud. Amazon AWS is known for its global reach, maturity, and reputation. Over the past few years, these lines of distinction for building cloud-native applications have started to blur within not just cloud providers, but within the tools and operating systems used to create them. The following information contains a brief breakdown on how you or your team can start working with .NET outside of the Microsoft Windows ecosystem.

**Deploying .NET in Google App Engine**
For those that are not familiar with App Engine, it is a fully managed serverless application platform that takes advantage of Google’s years of building resilient and scalable architectures. It is an excellent solution if you want to start playing with .NET using Docker and don’t want to deal with Kubernetes.

**Prerequisites:**

* [Download](https://visualstudio.microsoft.com/vs/mac/) Visual Studio for Mac

* [Sign up](https://console.cloud.google.com/getting-started) for a Google Cloud Platform account. You will get $300 in free usage.

* [Install](https://cloud.google.com/sdk/docs/downloads-interactive) the Google Cloud SDK.

* [Create](https://console.cloud.google.com/projectselector2/home/dashboard?_ga=2.16975289.-1403532037.1573498213) a project in Google Cloud.

* Open Terminal in Mac and run the following command to set your default project:

```zsg
gcloud confid set project <PROJECT-NAME>
```

The following link contains [sample code](https://github.com/mgrofsky/NET_Docker_Google-_App_Engine) for those interested in trying out a pre-built Visual Studio Solution. Included is one example each for deploying a Docker container to Google App Engine as well as Kubernetes.

Visual Studio comes with the needed Dockerfile templates to help any developer jump into building a container ready application. When created, the Dockerfile will expose the necessary ports so that the Web App is reachable. One essential item here is that when designing and deploying a custom runtime, the App Engine front end will route incoming requests to the appropriate module on port 8080, and you must be sure that your application code is listening on that port.

The default **EXPOSE** when adding in Docker support to a .NET web application is:

```yaml
    FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
    WORKDIR /app
    EXPOSE 80
    EXPOSE 443
```

You will want to change this to:

```yaml
    FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
    WORKDIR /app
    EXPOSE 8080
    ENV ASPNETCORE_URLS=http://*:8080
```

Everything else will remain the same. You may then go ahead and create your .NET web application as usual. The final step before deploying to App Engine is to specify the custom runtime. Create a file called app.yaml and place it in your root directory.

```yaml
    runtime: custom
    env: flex
    manual_scaling:
      instances: 1
    resources:
      cpu: 1
      memory_gb: 0.5
      disk_size_gb: 10

    service: service-test
```

The sample app.yaml above incurs costs to run on the App Engine flexible environment. The settings are to reduce costs during testing and are not appropriate for production use. 

**Remember that the flex environment does not scale down to 0 and could become costly if you supply the wrong resources and forget about it.**

For more information, see: [https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml](https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml)

In Terminal on your Mac, browse to the root directory containing your app.yaml file and run the command:

```bash
gcloud app deploy
```

You can preview your running application by browsing to ***App-Engine>Services*** in the Google Cloud Platform Console.

You just deployed a highly resilient and scalable .NET application without running a Windows Client machine or bringing up any Windows Servers.

**Sample Visual Studio Solution**
{% github https://github.com/mgrofsky/NET_Docker_Google-_App_Engine %}

Translated for Ukrainian audiences:

{% medium https://medium.com/temy-ukraine/%D1%81%D1%82%D0%B2%D0%BE%D1%80%D0%B5%D0%BD%D0%BD%D1%8F-%D0%BC%D0%B0%D1%81%D1%88%D1%82%D0%B0%D0%B1%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%85-%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC-net-%D0%B1%D0%B5%D0%B7-windows-31ddacac5dba %}