Giter VIP home page Giter VIP logo

bicep-app-service-slots's Introduction

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.

bicep-app-service-slots's People

Contributors

xaviermignot avatar

Stargazers

Vien avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.