Partager via


Deploying Microsoft Bot Framework app in Google Cloud!

Microsoft has provided a great framework for creating chat bots. If you are coming from a Windows background, you would typically create one in .NET Framework and deploy it to an Azure App Service since Visual Studio provides a really seamless way to deploy to Azure. But can you do the same in Google Cloud Platform (GCP)? Let's begin the adventure!

If you don't have a Google Cloud account, sign up for a free trial which gives you $300 to spend over a year. Once you are done signing up, open up the Google Cloud Console. (Note - All the features that we will explore here can be done via CLI or API calls. But for sake of simplicity we will use the UI provided by Google).

GCP provides multiple ways to host your app - App Engine Standard, App Engine Flexible, Compute Engine, Kubernetes Engine etc. App Engine and Kubernetes Engine are the PaaS offerings from GCP while Compute Engine is the IaaS one. We will use the Compute Engine as our bot will be developed in .NET 4.6 which is not a runtime offered by App Engine.

We begin with creating a Project in GCP. Think of it as the equivalent of subscription in Azure. All the resources that we will create will come under this project. GCP also has a nice feature of Service Accounts which allows us to add Identity to any resource that we will create. Service Accounts allow us to talk to any of the myriad services provided by GCP (like Google Cloud Storage) without the need of additional authentication. Everything is handled seamlessly without we having to write a single line of code.

Although all projects come with a default service account, we will follow the recommended approach and create a custom one to use in our project.

Next we will create a Virtual Network a.k.a VPC in GCP lingo. It's a typical exercise where you provide region and subnet configuration in CIDR blocks.

Next we will create a VM running Windows Server 2016. To do this we go to Compute Engine and fill in the details. We will make sure that we have selected the Service Account and VPC that we have created earlier.

This completes the infrastructure setup. Next we will configure Visual Studio to allow seamless integration with GCP. To do this we will install a Visual Studio Extension called "Google Cloud Tools for Visual Studio".

After we install the extension and sign in with our Google account, we get a host of features inside Visual Studio.

Our bot will be a simple bot which asks the user if they want to upload an image to a Google Cloud Storage Bucket or view the previously uploaded ones. The entire flow will be like this:

To access the Google Cloud APIs, we will install the Nuget package "Google.Apis" and "Google.Cloud.Storage.V1". This allows access to Google Storage APIs which we will use to create storage buckets and upload files in them.

You can find the entire source code here - https://github.com/mayankthebest/ms-bot-on-gcp

Now that we have completed developing our bot, let's deploy it on GCP. Instinctively we right-click on our project in Visual Studio and we get a nice little UI -> "Publish to Google Cloud". Voila!

 

And we are done. This publish mechanism uses Web Deploy to deploy the site but we can use any other method like FTP if it suits us.

Google Cloud Platform is rapidly developing and getting better day-by-day. It has tight integration with Google services which used and loved by millions of people around the world. And now that Google has provided such great tools for .NET developers, there has been no better time to give GCP a try.

What has your been your experience using GCP? Sound off in the comments below.