Search code examples
azurevisual-studio-2013azure-web-rolesazure-configuration

A single cloud project for each environment?


Previously I have always had separate cloud projects for each environment, like this:

Cloud Project layout

This poses some problems:

  • Maintaining multiple ServiceDefinition.csdef files
  • When building to a common output path, which ServiceDefinition.csdef is copied?

I am proposing using a single Cloud Project with multiple ServiceConfiguration files for each environment, and multiple profiles for publishing:

Single Cloud Project

Pros:

  • Less maintenance issues (1 project and 1 ServiceDefinition.csdef)
  • A single ServiceDefinition.csdef is copied to the output folder

The problem I have now is that all environments need to have the same instance size as this is defined in the ServiceDefinition.csdef.

Is there any way I can get around this problem?


Solution

  • Yes, we create multiple packages (one for each environment). We have different powershell scripts to patch things like the vm-size (one example):

    param(
        [parameter(Mandatory=$true)]
        [string]$fileToPatch,
    
        [parameter(Mandatory=$true)]
        [string]$roleName,
    
        [parameter(Mandatory=$true)]
        [validateSet("ExtraSmall", "Small", "Medium", "Large", "ExtraLarge", "A5", "A6", "A7")]
        [string]$vmsize = 'Small'
    )
    #  MAIN
    
    $xml = New-Object System.Xml.XmlDocument
    $xml.Load($fileToPatch)
    
    $namespaceMgr = New-Object System.Xml.XmlNamespaceManager $xml.NameTable
    $namespace = $xml.DocumentElement.NamespaceURI
    $namespaceMgr.AddNamespace("ns", $namespace)
    
    $xpathWorkerRoles = "/ns:ServiceDefinition/ns:WorkerRole"
    $xpathWebRoles = "/ns:ServiceDefinition/ns:WebRole"
    $Roles = $xml.SelectNodes($xpathWebRoles, $namespaceMgr) + $xml.SelectNodes($xpathWorkerRoles, $namespaceMgr)
    
    $Roles | Where-Object { $_.name -eq $RoleName} | % { $_.vmsize = $vmsize; Write-Host 'Patched vmsize to' $vmsize 'for' $_.name } 
    
    $xml.Save($fileToPatch)