When Google announced Google Cloud Run, a service for running stateless HTTP containers that are fully managed or in a GKE cluster, I was convinced that the serverless era of developing applications has arrived! As a developer, being able to write an application in the programming language of my choice is powerful.
It means I get to stick with a development stack for which I’m familiar so I’ll be productive immediately. I enjoy developing apps in C# and on .NET Core but at the time when I reviewed the quickstart documentation for Cloud Run, there weren’t any examples using C#. Currently, there is a quickstart tutorial describing how to deploy a .NET app to Google Cloud Run.
The steps I took to create a containerized .NET application were simple. I created a ASPNET Core web app running .NET Core 2.2. Created a Dockerfile with the build steps and environment configuration for ASPNET Core. Something I did differently than the current quickstart documentation is I added an environment variable for ASPNETCORE_URLS and exposed port 8080.
It’s a good idea to run your app locally to make sure it works. Once you confirm you have a working app, here’s what you do next:
- Ensure you have the beta version of the gcloud command line tool.
- Create a GCP project. Note – delete the project after you’re finished to prevent ongoing charges.
gcloud builds submit –tag gcr.io/[PROJECT-ID]/[appname]
- To deploy your container to Cloud Run using GCloud, type the command:
gcloud beta run deploy –image gcr.io/[PROJECT-ID]/[appname]
When the deployment is complete, the command line will display the service URL. Navigate to your deployed container and open the service URL. Success!
DotNet on Cloud Run
Deploying to Cloud Run was very easy so I decided to take it a step further. I integrated Cloud Firestore to create a truly serverless app on GCP. I created a simple guest book which users can sign their name and add a message. Users can also view the list of people who signed the guest book. See below for a link to the GitHub repository with the code. If you want to run the code locally, you need to download your service account credentials. NOTE: Do not check this credentials file into Github. It contains private keys. Store it in a directory outside of your main project file. See quick start instructions for more information.
The future of software development is serverless. It’s incredibly powerful when as a developer you only have to think about the things that bring value to your customers and not infrastructure. As with every new technology there are trade-offs so its important you understand the programming paradigms. All the code is in my GitHub repository. If you have feedback leave a comment below.