lostintangent / node-azure

Tutorials that illustrate how to build Node.js apps with VS Code, and deploy them to Azure
http://azure.com/node
10 stars 7 forks source link

Deployment Slots ("Wish List") #10

Open fiveisprime opened 7 years ago

fiveisprime commented 7 years ago

An Azure deployment slot is a live Azure Web App with its own hostname, content, and app configuration that can be swapped between two deployment slots including the production slot. This functionality allows benefits such as blue-green deployments, zero-downtime deployments, and near-automatic reverting of a deployment.

Currently, this functionality is only available from within the Azure portal and not from the az CLI limiting the options for automation and forcing users into the Azure portal. The following illustrates a straw man experience for using deployment slots from the az CLI.

North Star

Setting up a deployment slot from the az CLI should be simple and allow the same functionality as from the portal. Along with configuring the deployment slot, a new git remote should be added (similar to when creating a new web app).

$ az login

  [Info] Launching browser to authenticate...

$ az appservice web create -n todo

  [Info] Resource group created: todo-group
  [Info] App Service Plan created: todo-plan
  [Info] Git remote added: azure
  [Info] Default resource group set: todo-group

  # ...

$ az appservice deployment slot create --slot staging  --configuration-source todo

  [Info] Selecting web app: todo
  [Info] Creating deployment slot: staging
  [Info] Git remote added: azure-staging
  [Info] Swapping to deployment slot: staging

$ az appservice deployment slot swap --slot staging --target-slot production

  [Info] Swapping to deployment slot: production

Targeting a specific deployment slot should be as simple as a regular deploy since the slot was added as a separate remote.

$ git push azure-staging master

Global Deployment Slot Option

The following use cases require that the --slot option be allowed globally.

Streaming log access to specific deployment slots is required to maximize the utility for deployment slots via the az CLI. In general, the --slot should be available to existing commands including logs.

$ az appservice web log tail -n todo --slot staging

Allow targeting specific deployment slots when updating environment variables.

$ az appservice web config appsettings update NODE_ENV=staging -n todo --slot staging

Blue-Green Deployments

The most common scenario will be blue-green deployments where a customer will deploy to a staging slot and validate functionality before swapping the deployed changes to the production slot. This method also facilitates zero-downtime deployments where the slot is swapped immediately after becoming available.

$ git push azure-staging master

  # ...

$ az appservice web browse -n todo -s staging --view-logs

  [Logs] Application log data

  # ...

$ az appservice deployment slot swap --slot staging --target-slot production

  [Info] Selecting web app: todo
  [Info] Swapping to deployment slot: production

Configuring Flighting

Configuring the percentage amount of traffic to each deployment slot is an incredibly powerful way to test changes to a production environment with very low impact. Configuring the traffic percentage then tailing logs for a deployment slot will help customers quickly test production changes.

$ az appservice deployment slot routing --slot staging --traffic 10 --view-logs
  [Info] Routing 10% of traffic to deployment slot: staging
  [Logs] Application log data..

Reverting a Deployment

In the same way that staging can be swapped in for production, customers can also perform an additional swap to revert changes. In this case, the user would deploy to the staging slot then swap for production, if the changes aren't working as intended, the user can swap production a staging again to return the web app to its original state.

How Do We Get There?

Achieving the above experience only requires some minor additions to the az CLI. Note that these additions are built upon changes that will be coming by the time //build happens (see #7).

1) Add appservice deployment-slot commands to the az CLI 1) Publish information about this - blog posts and how-tos

lostintangent commented 7 years ago

Could we include a scenario for flighting new releases as well? I realized last night this isn't possible from the CLI, and I think this is a pretty key scenario.

https://github.com/Azure/azure-cli/issues/2067

fiveisprime commented 7 years ago

Yeah! I really just needed to get this into GitHub before switching context with some other docs I'm working through.

lostintangent commented 7 years ago

Here are a few other minor issues that I'd like to track as part of this:

https://github.com/Azure/azure-cli/issues/1895 https://github.com/Azure/azure-cli/issues/1867

lostintangent commented 7 years ago

We should also think about what the workflow looks like for apps that are using custom containers and remote Git repos (e.g. when you create the slot, how do you configure it to pull from a separate branch/container?). Maybe this already works well, I'm just not sure.