Created
January 9, 2016 11:32
-
-
Save miklund/d096a9b9940c7f5f8a9a to your computer and use it in GitHub Desktop.
2011-08-02 Deploy to Azure with Powershell
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
# Title: Deploy to Azure with Powershell | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2011/08/02/deploy-to-azure-with-powershell.html |
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
# Include Azure cmdlets from http://wappowershell.codeplex.com/ | |
Add-PSSnapin AzureManagementToolsSnapIn | |
### HELPER FUNCTION ### | |
Function Get-Staging ([string]$serviceName, [string]$subscriptionId, [System.Security.Cryptography.X509Certificates.X509Certificate2]$cert) | |
{ | |
Get-HostedService -serviceName $serviceName -subscriptionId $subscriptionId -certificate $cert | Get-Deployment -slot Staging | |
} | |
### VARIABLES #### | |
$bin_iexplore = "C:\Program Files (x86)\Internet Explorer\iexplore.exe" | |
$azure_service = "litemediainfo" | |
$azure_sub = "aacbcab88-4f34ef4-8330-090abf3c3b" | |
$azure_cert = Get-Item "cert:\CurrentUser\My\089E87E963B472906F6345345345NBMNBN345NBBBB" | |
$azure_package = "build\Deploy\LiteMedia.Web.Azure.cspkg" | |
$azure_config = "build\Deploy\ServiceConfiguration.cscfg" | |
$azure_label = "litemedia.info " + [System.DateTime]::Now.ToString() | |
$azure_role = "litemedia.info" | |
$azure_storage = "litemedia" | |
### DEPLOY WORKFLOW STARTS HERE ### | |
# GET STAGING ENVIRONMENT | |
$staging = Get-Staging $azure_service $azure_sub $azure_cert | |
# FOUND STAGING | |
if ($staging.Url) { # YES | |
Write-Host "Upgrade existing staging environment" | |
$staging | | |
Set-Deployment -mode Auto -package $azure_package -label $azure_label -StorageServicename $azure_storage -configuration $azure_config | | |
Get-OperationStatus –WaitToComplete | |
} | |
else { # NO | |
Write-Host "Create new staging environment" | |
New-Deployment -serviceName $azure_service -subscriptionId $azure_sub -certificate $azure_cert -slot Staging -package $azure_package -label $azure_label -StorageServicename $azure_storage -configuration $azure_config | | |
Get-OperationStatus -WaitToComplete | |
} | |
# GET STAGING ENVIRONMENT | |
$staging = Get-Staging $azure_service $azure_sub $azure_cert | |
Write-Host "Startup Staging" | |
$staging | | |
Set-DeploymentStatus running | | |
Get-OperationStatus –WaitToComplete | |
Write-Host "Starting browser for staging review" | |
&$bin_iexplore $staging.Url | |
$deploy = Read-Host "Move staging to production? (y/N)" | |
# WAS STAGING OK? | |
if ($deploy -eq 'y') { # YES | |
Write-Host "Swapping staging for production" | |
$staging | | |
Move-Deployment | | |
Get-OperationStatus –WaitToComplete | |
} | |
Write-Host "Suspend staging environment" | |
$staging | | |
Set-DeploymentStatus suspended | | |
Get-OperationStatus –WaitToComplete | |
Write-Host "Remove staging environment" | |
Remove-Deployment -slot Staging -serviceName $azure_service -subscriptionId $azure_sub -certificate $azure_cert | | |
Get-OperationStatus –WaitToComplete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment