Set up Fanray on Azure App Service

Fanray can be deployed to any environment .NET Core runs on, Azure App Service is the best choice for most web apps. The setup is straight forward, I start by creating the necessary Azure resources.

Create Web App + SQL

At minimum an App Service and a SQL database are required.  Go to Azure Portal, click on New and choose Web App + SQL template.  Following instructions the portal will create the web app and database in one step and put the database connection string in the web app’s Application settings. During this process, a Resource Group and Service plan will also be created.

Azure organizes resources like this,

  • Web: Subscription > Resource Group > Service plan > App services
  • SQL: Subscription > Resource Group > SQL server > SQL databases

Normally one gets started on Azure with a subscription. Under subscription there is Resource Group, a container for your resources, it enables you to easily say delete your Resource Group or transfer it to a different subscription, then all the resources the group contains will be deleted or transferred together.

A Service Plan contains one or more app services like web app, mobile app etc. and you scale up / out these apps at the service plan level.

A SQL server contains one or more SQL databases, unlike a service plan you scale up and down workloads on the individual SQL databases in the unit of DTUs. This article Tuning performance in Azure SQL Database explains the different database service tiers and their performance.

I created one Resource Group, one Service plan (Basic Service plan, B1), one App Service, one SQL server, one SQL database (Standard SQL database, S0).  I see the following after I set up my resources, all these live in my Resource Group.

fanray-azure-resources
Fanray Azure resources

 

After creating all the resources, go to your App Service > Application settings, under Connection strings there should be an entry named “defaultConnection” pointing to the SQL server and database you just created.

application-settings-defaultconnection
Application settings defaultConnection

 

Create Storage account and Application Insights

I also recommend creating an Azure storage account and an Application Insights resource, though these are not required.

Fanray can use Azure Blob storage to store uploaded files and log to Application Insights in addition to files. These can be configured in appsettings.Production.json, for example you can choose to store uploaded files instead on the file system of your App Service (not recommended).

Below are the options I chose when created my storage account for Blob Storage. I wanted the cheapest way possible thus Standard, LRS and Cool. As of this writing the cost for Cool, LRS in West US region for the First 50 TB / Mo is $0.0152. I also chose Enabled for Secure transfer required option, this will require your requests to be https. I’ll set up SSL for my site in the next post.

create-storage-account
Create storage account

 

Then I created Application Insights for ASP.NET web application. For Location I tried to find the closest location, currently West US is not available though West US 2 is.  The pricing for Application Insights is that your first 1 GB for each app is free, so if you're just experimenting or developing, you're unlikely to have to pay.

create-application-insights
Create Application Insights

 

After creating these two resources, you need to add your Application Insights Instrumentation Key and Blob storage connection string to your App Service App settings.  Go to your Application Insights resource find the Instrumentation Key.

application-insights-instrumentation-key
Application Insights Instrumentation Key

 

And go to your Storage account > Access keys, copy one of the Connection Strings after key1 or key2.  This key is secretive and don’t share it. It’s also recommended to refresh with new values from time to time. There are two keys, key1 and key2, exactly for this purpose, when you are getting a new value for one, your app can still function with the other.

azure-storage-account-access-keys
Azure Storage Account Access keys

 

Go back to your App Service > Application settings, scroll down to App settings section and add “ApplicationInsights:InstrumentationKey property.  Then, in Connection strings section, add “BlobStorageConnectionString” property.

add-blob-connstr-and-appinsights-key
Add Blob Connection String and AppInsights Key

 

Disqus and Google Analytics

Before we deploy code, there are two more resources I recommend, Disqus and Google Analytics. On the blog setup page later you can optionally put in your Disqus Shortname and Google Analytics Tracking ID.

To find your Disqus Shortname, go to disqus.com > Admin > select your site > Settings > General

disqus-shortname
Disqus Shortname

 

To find your Google Analytics Tracking ID, logon Google Analytics > Admin > Tracking Code

google-analytics-tracking-id
Google Analytics Tracking ID

 

Deploy from GitHub

Code can be deployed to Azure in many ways, directly from GitHub is a super easy way and you can start by forking the Fanray repo on GitHub. Then go into App Service > Deployment options > Choose Source and select GitHub, then authenticate, choose project and branch.  Click OK and it will start initial deployment and every subsequent push of commits will trigger this deployment process again.

github-deployment-options
GitHub Deployment Options

 

Launch your site

At this time my azure website http://fanray.azurewebsites.net is up and running!  Visiting the site for the first time, Entity Framework will create the database and populate the tables for you, then you will see the blog setup page show up.

11-fanray-blog-setup
Fanray blog setup

 

Summary

By now you should have a Fanray blog running live on Azure. The next step I recommend is to set up Custom Domain and HTTPS for your Azure Web App.