Skip to content

Instantly share code, notes, and snippets.

@GeorgDangl
Last active November 13, 2018 19:49
Show Gist options
  • Save GeorgDangl/aac6b7ea1ce3fd578fc8bddc4de199ec to your computer and use it in GitHub Desktop.
Save GeorgDangl/aac6b7ea1ce3fd578fc8bddc4de199ec to your computer and use it in GitHub Desktop.
Using Microsoft.Azure.Management.Fluent to swap App Service staging and production slots - used with AVACloud, see https://blog.dangl.me/archive/deploy-to-azure-app-service-with-no-downtime-by-using-staging-slots/
if (PublishEnvironmentName == "Production")
{
var azureCredentials = SdkContext.AzureCredentialsFactory
.FromServicePrincipal(AzureServicePrincipalClientId,
AzureServicePrincipalClientSecret,
AzureServicePrincipalTenantId,
AzureEnvironment.AzureGlobalCloud);
IAzure azure = Azure.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(azureCredentials)
.WithDefaultSubscription();
var webApp = (await azure.AppServices.WebApps
.ListAsync())
.First(app => app.Name == AzureAppServiceName);
var slot = (await webApp.DeploymentSlots.ListAsync())
.First(s => s.Name == AzureAppServiceStagingSlotName);
var statusUrl = $"https://{slot.DefaultHostName}/status";
if (!(bool)JObject.Parse(await HttpDownloadStringAsync(statusUrl))["isHealthy"])
{
ControlFlow.Fail("The web app in the staging slot does not report a healthy status");
}
// "production" is the default name for the main slot
await slot.SwapAsync("production");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment