Skip to content
Browse files

better check for AzureManagementToolsSnapIn and added exec helper fun…

…c along with msbuild shortcut
  • Loading branch information...
1 parent 0328041 commit bbcd538c8e72b8c175046e27cc8f907076331401 @tclem committed Nov 19, 2010
Showing with 81 additions and 17 deletions.
  1. +9 −0 pstrano.psm1
  2. +72 −17 pstranofile_azure.ps1
View
9 pstrano.psm1
@@ -20,6 +20,15 @@
#-- Public Module Variables -- The pstrano hashtable variable is initialized in the invoke-pstrano function
$script:pstrano = @{}
Export-ModuleMember -Variable "pstrano","roles"
+#-- Helper functions
+function exec([scriptblock]$command, [string]$errorMsg) {
+ & $command
+ if ($lastExitCode -ne 0) {
+ throw $errorMsg
+ }
+}
+$script:v4_net_version = (ls "$env:windir\Microsoft.NET\Framework\v4.0*").Name
+$script:msbuild = "C:\Windows\Microsoft.NET\Framework\$v4_net_version\MSBuild.exe"
#-- Private Module Functions
function ExecuteTask
View
89 pstranofile_azure.ps1
@@ -3,56 +3,103 @@
# Use deploy.ps1 for your custom project settings instead
include 'config\deploy_azure.ps1'
-$s = Get-PSSnapin AzureManagementToolsSnapIn
+$s = Get-PSSnapin | ? { $_.Name -like "Azure*" }
if($s -eq $null){
Add-PSSnapin AzureManagementToolsSnapIn
}
-$script:service = $null
-$script:sub = $null
-$script:cert = $null
-$script:package = $null
-$script:config = $null
-$script:label = (date).ToString('hh:mm:ss MM/dd/yyyy')
+[hashtable]$script:vars = @{}
+
+#Default Settings
+$service = $null
+$storage_service = $null
+$sub = $null
+$cert = $null
+$package = $null
+$config = $null
+$prod_config = $null
+$label = (date).ToString('hh:mm:ss MM/dd/yyyy')
setup{
+ $storage_service = $service = $vars["service"]
+ if($vars["storage_service"] -ne $null){
+ $storage_service = $vars["storage_service"]
+ }
+ $sub = $vars["sub"]
+ $cert = $vars["cert"]
+ $package = $vars["package"]
+ $config = $vars["staging_config"]
+ $prod_config = $vars["production_config"]
+
Assert ($service -ne $null) "Failed: You must specify a value for service."
- Assert ($sub -ne $null) "Failed: You must specify a value for sub. This is your azure subscriptionId"
+ Assert ($sub -ne $null) "Failed: You must specify a value for sub. This is your azure subscriptionId."
Assert ($cert -ne $null) "Failed: You must specify a value for cert. This is your azure certificate. Use Get-Item cert:\CurrentUser\My\<thumbprintinuppercase>"
- Assert ($package -ne $null) "Failed: You must specify a value for package. This is your azure deployment package"
- Assert ($config -ne $null) "Failed: You must specify a value for config. This is your azure deployment configuration"
+ Assert ($package -ne $null) "Failed: You must specify a value for package. This is the local path to your azure deployment package."
+ Assert ($config -ne $null) "Failed: You must specify a value for staging_config. This is the local path to your azure deployment configuration file(*.cscfg)."
+ Assert ($prod_config -ne $null) "Failed: You must specify a value for production_config. This is the local path to your azure deployment configuration file(*.cscfg)."
Write-Host "ServiceName = $service"
Write-Host "SubscriptionID = $sub"
Write-Host "Certificate = " $cert.Subject
Write-Host "Package = $package"
- Write-Host "Config = $config"
+ Write-Host "Staging Config = $config"
+ Write-Host "Production Config = $prod_config"
Write-Host "label = $label"
-
}
teardown{
}
task Deploy{
+ $d = Get-Deployment -serviceName $service -subscriptionId $sub -certificate $cert -slot staging
+ if($d.Status) {
+ "Updating deployment"
+ Get-HostedService -serviceName $service -subscriptionId $sub -certificate $cert |
+ Get-Deployment -slot staging |
+ Set-Deployment -package $package -label $label |
+ Get-OperationStatus –WaitToComplete
+ } else {
+ "Creating new deployment"
+ New-Deployment -serviceName $service -StorageServiceName $storage_service -subscriptionId $sub -certificate $cert -slot staging -package $package -configuration $config -label $label |
+ Get-OperationStatus –WaitToComplete
+ }
}
task CheckStagingStatus{
Get-Deployment -serviceName $service -subscriptionId $sub -certificate $cert -slot staging
}
+task CheckProductionStatus{
+ Get-Deployment -serviceName $service -subscriptionId $sub -certificate $cert -slot production
+}
+
+task UpdateStagingConfig {
+ if((Test-Path "$config~")){
+ rm -Force "$config~"
+ }
+
+ $d = Get-Deployment -serviceName $service -subscriptionId $sub -certificate $cert -slot staging
+ (Get-Content $config) |
+ % {$_ -replace "{staging_guid}", $d.DeploymentId} |
+ Set-Content "$config~"
+
+ $d |
+ Set-DeploymentConfiguration -Configuration "$config~" |
+ Get-OperationStatus –WaitToComplete
+}
+
task CreateStagingDeployment{
# create the new deployment
- New-Deployment -serviceName $service -subscriptionId $sub -certificate $cert -slot staging -package $package -configuration $config -label $label |
+ New-Deployment -serviceName $service -StorageServiceName $storage_service -subscriptionId $sub -certificate $cert -slot staging -package $package -configuration $config -label $label |
Get-OperationStatus –WaitToComplete
}
task UpgradeStagingDeployment{
# upgrade the staging deployment
Get-HostedService -serviceName $service -subscriptionId $sub -certificate $cert |
Get-Deployment -slot staging |
- Set-Deployment -package $package -label $label |
+ Set-Deployment -package $package -StorageServiceName $storage_service -label $label |
Get-OperationStatus –WaitToComplete
}
task RunStagingDeployment{
@@ -64,11 +111,19 @@ task RunStagingDeployment{
Get-OperationStatus –WaitToComplete
}
task SwapSlots{
+
+ $d = Get-Deployment -serviceName $service -subscriptionId $sub -certificate $cert -slot staging
+
+ # make sure we upload our production configuration
+ "Updating staging slot to use production configuration ($prod_config)"
+ $d |
+ Set-DeploymentConfiguration -Configuration $prod_config |
+ Get-OperationStatus –WaitToComplete
# swap the staging and production slots
- Get-HostedService -serviceName $service -subscriptionId $sub -certificate $cert |
- Get-Deployment -slot staging |
+ "Swapping production and staging"
+ $d |
Move-Deployment |
- Get-OperationStatusWaitToComple
+ Get-OperationStatusWaitToComplete
}

0 comments on commit bbcd538

Please sign in to comment.
Something went wrong with that request. Please try again.