Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 3.42 KB

README.md

File metadata and controls

45 lines (32 loc) · 3.42 KB

Azure App Service with Bicep, deployment slots and app settings

This repository contains a demo on how to use Azure Services deployment slots with Bicep (yes, with app settings too !). It is an adaptation of a demo I had previously made using Terraform, and it's covered by a series of two posts on my blog here and here.
The demo consists in:

  • a few Bicep files to provision an App Service and a deployment slot
  • a simple ASP.NET web app
  • GitHub Action workflows to:
    • provision the Azure resources
    • deploy the web app: the blue version on the production slot, and the green version on the staging slot
    • swap the staging slot with the production one (as many time of you want)
    • destroy the Azure resources once you have finished to save costs

Getting started

To run this demo by yourself there is nothing to install on you machine as everything is running in the cloud. You need to configure a few things in GitHub and in you Azure subscription.

Create a service principal in Azure

To grant access to your Azure subscription to the GitHub Action runners, you need to create a service principal with the contributor role to your subscription.
Everything is well explained here, follow the instructions and save your subscriptionId for later.

Fork the repository and set a few secrets

To run the GitHub Actions workflows you need to fork this repository. I haven't tested the fork myself as I don't have a secondary account, so I hope this works.

In your fork you need to set a few secrets. You should already have the AZURE_CREDENTIALS secret set from the previous step.
Add these secrets required to deploy the Bicep templates:

  • AZURE_SUBCRIPTION with your subscription id
  • AZURE_REGION with the Azure region you want to use

Then, as some of the workflows are creating secrets in GitHub, you'll need to create a Personal Access Token for that with the following permissions:

  • Access to your fork's repo
  • Read and write access to secrets (this will also select the read access to metadata)

Once the PAT generated, save its value in the GH_PAT secret, and you're all set !

Run the demo

Once everything has been set-up you can run the 01 - Initial deployment workflow from the Actions tab in GitHub. This will create the resources in Azure, deploy a blue version of the code in the production slot, and a green version of the code in staging.
Go to the Azure portal to see the resources in the rg-aps-slots-demo resource group. You can browse both versions from there.

To make a swap, run 02 - Swap App Service slots using Azure CLI workflow.
Once the swap has been done, refresh the app in your browser, you should see the green version in production and the blue one in staging.

Eventually you can perform another swap if you want to simulate a rollback.

Lastly, do not forget to run the 03 - Destroy Azure resources with Azure CLI once you have finished to save costs as the App Service runs in a Standard plan, which is not free of charge.