Introduction
You probably found yourself rebuilding your Windows Azure application just to make a small modification in the application configuration.
For example, let's say that your initial design was to set for each Role instance a virtual machine size of Small VM (1 CPU).
Along the way, you noticed that the initial VM size was just not enough and the Role instances need a bigger VM.
The common way to fix that is to just open Visual Studio and change the application service definition configurations that will be eventually reflected in the ServiceDefinition.csdefe file under <WebRole name=[WebRoleName] vmsize=[VM_SIZE]>
.
It would have been easier if you could have opened the application package and made the changes without the need for the development environment.
In addition, it's a valid option that you as the DevOp just don't have access to the application source code and application provisioning is an issue that needs to be addressed on a closed application package file.
The trouble with the application package old format is that the file content is encrypted (using the Azure SDK) and cannot be edited.
Luckily, Windows Azure provides a way to use an open format (OPC) application package that can be opened with simple archive tools such as WinZip or WinRaR in order to modify specific files.
In this post, I would demonstrate how to create an application package with the new format using a simple PowerShell script.
First let's quickly cover the parts that assemble an Azure application.
Application Package Old vs New Format
Every application package contains 2 files:
- *.cspkg - application code which includes the important ServiceDefinition.csdefe file mentioned above
- ServiceConfiguration.cscfg
Using the Code
In the CSPack command line tool, Microsoft added 2 new options for supporting the new package format:
- /useCtpPackageFormat - creates the new OPC application package format
- /convertToCtpPackage - converts the application package old to new format
The code below creates the Azure application in an OPC format: (The CSPack
command can be found in the following path: C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\<sdk-version>\bin).
# Working script parms
$cppack = 'C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\2012-10\bin\cspack.exe'
$workingDir = "C:\Users\[USER_NAME]\Documents\Visual Studio 2010\Projects\TestDepOneRole"
$serviceName = "TestDepOneRole"
$roleName = "WebRole1Update"
$roleBinDir = [string]::Format("{0}\{1}",$workingDir,"WebRole1")
$outPath = [string]::Format("{0}\{1}",$workingDir,"packages")
# CSPack command parms
$_serviceDefinitionPath =
[string]::Format("{0}\{1}\ServiceDefinition.csdef",$workingDir,$serviceName)
$_serviceConfigurationPath =
[string]::Format("{0}\{1}\ServiceConfiguration.Cloud.cscfg",$workingDir,$serviceName)
$_role = [string]::Format("/role:{0};{1}", $roleName,$roleBinDir)
$_sites = [string]::Format("/sites:{0};Web;{1}",$roleName,$roleBinDir)
$_out = [string]::Format("/out:{0}\package\{1}OPC.cspkg",$workingDir,$serviceName)
# Running script
if(!(test-path $outPath -pathtype container)){
new-item -Name "package" -ItemType directory -Path $workingDir
}
& $cppack $_serviceDefinitionPath $_role $_sites $_out /useCtpPackageFormat
Copy-Item $_serviceConfigurationPath $outPath
Opening the file using WinRaR reveals the following:
You can notice that the service definition can be edited and inserted back to the application package to submit the changes.
Points of Interest
The OPC format should be used well in Azure for static content editing, for example, modifying external properties files in the application package. However, in the current implementation, the OPC does not resemble the structure you would expect from the cloud solution.
For example, the LocalContent folder contains hash files that cannot be extracted and there isn't a proper directory structure like in Visual Studio cloud project so editing a simple CSS file is not yet possible.