Deploy to App Service
What is Azure App Service?
The Azure App Service allows you to quickly build, deploy, and scale enterprise-grade web, mobile, and API apps running on any platform whilst meeting rigorous performance, scalability, security and compliance requirements using a fully-managed platform to perform infrastructure maintenance.
It comes in a number of pricing plans, including a free option and has options for scale-up, scale-out, turn-key authentication as well as powerful monitoring capabilities. It is compatible with many runtimes and includes excellent support for both .NET Framework and .NET Core.
Custom FAKE build tasks
The Azure variant of the SAFE template adds the following extra build stages:
- Bundle - Runs after the standard Build step. It combines the outputs of the Client and Server application into a single folder.
- ArmTemplate - Deploys an Azure Resource Manager (ARM) template containing an entire environment as required by the SAFE application.
- AppService - Zips up the bundled folder and deploys it into the created environment.
There is a known issue that currently the FAKE script may sometimes fail the first time you run it with this error. If this occurs, simply open the FAKE script in your favourite editor, add a new line anywhere in the script, save and re-run. We're looking to fix this as soon as possible!
What is an ARM template?
An ARM template is a declarative JSON file which contains the details of the Azure resources you require in your environment. This might include a web application, database, VM and messaging service - essentially any service supported by Azure. ARM templates are smart, in that you can repeatedly deploy them over an existing environment and only the newly added elements in the template will be applied onto the environment - perfect for a CI / CD approach. This also allows you to create entire dev / test environments from scratch within just a few minutes. The ARM template that comes with the SAFE template includes everything you need for a complete deployment to Azure from a clean state.
Deploying your application through FAKE is relatively simple. Use the following command:
fake build --target appservice -e subscriptionId=<subId> -e clientId=<clientId> -e environment=<environment> (optional) -e location=<location> (optional) -e pricingTier=<pricingTier> (optional)
subscriptionIdis an Azure Subscription ID.
clientIdis the Application ID of an Azure App Registration.
environmentis an optional environment name that will be appended to all Azure resources created, which allows you to create entire dev / test environments quickly and easily. This defaults to a random GUID.
locationis the Azure data center location you wish to use. There are currently over 30 different data centers worldwide. This defaults to
westeurope; the full list can be viewed here. The location must be supplied in lower case and without spaces.
pricingTieris the pricing tier of the app service that hosts your SAFE app. This defaults to F1 (free); the full list can be viewed here.
Note that you can also modify the FAKE script and embed both the
clientId values directly in the script and commit into source control. This is completely safe to do as the Client ID is not sufficient on its own to authenticate into Azure (see below).
When running the build script, you will need to interactively authenticate with Azure in order to deploy the ARM template. During the FAKE script, you will see the following midway through the build cycle:
Navigating to that URL will request you to input the code shown above:
Finally, you will be prompted sign into Azure using your normal user account. After a short delay, the FAKE script will continue.
Note: If you're getting
Microsoft.Rest.ClientRuntime.Azure, try editing and rerunning FAKE script (see details).
Creating a fully automated deployment
You can also elect to implement a fully-automated (non-interactive) deployment model, ideal for Continuous Deployment (CD) scenarios through tools such as AppVeyor and Visual Studio Team Services, using an Azure Active Directory Application. In this model, in addition to a SubscriptionID and Client ID, you also supply a Tenant ID and an Application Secret into the FAKE script to deploy your ARM resources; these identities should normally be secured and supplied into your FAKE script as arguments rather than committed into source control.
Viewing the deployed SAFE application
Once the deployment is complete, you can log into the Azure Portal and see your environment being created.
- Log into the Azure Portal.
- Navigate to the Resource Groups blade and locate the newly-created group. Its name will be
- Navigate to the App Service entry shown in the group following the convention
- Hit Browse from the new App Service blade that appears.
- Your application will be shown in the browser running on a url following the convention
You can also deploy to a Docker Container.