C Y B E R D R E A D

Analyze the Future

Google Cloud Logo

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:

  1. Ensure you have the beta version of the gcloud command line tool.
  2. Create a GCP project.  Note – delete the project after you’re finished to prevent ongoing charges.
  3. Run:

    gcloud builds submit –tag gcr.io/[PROJECT-ID]/[appname]

    from the directory containing your Dockerfile.  This command will build your container image using Cloud Build.  If successful, your image will be stored in the Container Registry.
  4. To deploy your container to Cloud Run using GCloud, type the command:

    gcloud beta run deploy –image gcr.io/[PROJECT-ID]/[appname]

      When prompted, select a region and confirm the service name. Respond “y” to allow unauthenticated invocations.

When the deployment is complete, the command line will display the service URL.  Navigate to your deployed container and open the service URL. Success!

ASPNETCore on Cloud Run
ASPNETCore 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.

Summary

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.

Related Post

Leave a Comment

Cyberdread Newsletter