Last active
November 13, 2018 19:49
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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