0
votes

I've done a bit of digging and I haven't found any recent documents for this:

I have a .NET 4.6 solution consisting of a number of projects that I now wish to deploy to the cloud - specifically as an Azure Cloud Service.

It would be preferable not to have to create a Cloud Service project as part of my solution because I believe this is a deployment detail and thus is irrelevant to my solution which could as easily be hosted on a local IIS machine, or even IIS Express. As such, all the documents I have found which require the addition of a cloud service project to my solution just feel... dirty.

I have Jenkins and Octopus Deploy for my deployment tools and I would like, if possible to have them deploy the project directly - which it seems Octopus does out of the box, except for one detail, I have a startup script which will need to be run on the Azure cloud service:

  • To ensure the correct version of the .NET Framework is installed and if required, install it.
  • To install an SSL client cert which is required to communicate with one of my other servers.

For on-premises or a local IIS installation, this wouldn't be a problem as the Octopus Tentacle can run a script on the server to ensure the existence of the correct version of the .NET Framework and the installation of the SSL cert, but I can't fathom how to mirror this task on an Azure Cloud Service.

2

2 Answers

0
votes

First you will have to automate the deployment of the cloud service from your octopus script. For example in PowerShell, you can code it in this way :

function CreateNewDeployment()
{
write-progress -id 3 -activity "Creating New Deployment" -Status "In progress"
Write-Output "$(Get-Date –f $timeStampFormat) - Creating New Deployment: In progress"

$opstat = New-AzureDeployment -Slot $slot -Package $packageLocation -Configuration $cloudConfigLocation -label $deploymentLabel -ServiceName $serviceName

$completeDeployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot
$completeDeploymentID = $completeDeployment.deploymentid

write-progress -id 3 -activity "Creating New Deployment" -completed -Status "Complete"
Write-Output "$(Get-Date –f $timeStampFormat) - Creating New Deployment: Complete, Deployment ID: $completeDeploymentID"

#StartInstances
}

$packageLocation = "$currentDirectory/$packagefile"
$cloudConfigLocation = "$currentDirectory/$cloudConfigFile"

Import-AzurePublishSettingsFile $publishsettings
Set-AzureSubscription -SubscriptionName $azureSubscription -CurrentStorageAccount $storageAccount

CreateNewDeployment

Second, you will have to configure a startup task with an elevated execution context in order to run your startup script.

A startup task is a unique feature of Cloud Services that enable you to perform configuration changes to the virtual machine for a role instance before the role is started
A startup task is defined in the cloud service definition (.csdef) file using the <Task> element within a <WebRole> or <WorkerRole> element. A <Task> element contains three properties that you can use to influence permissions and behaviors for the task, which are:

  • commandLine Identifies the program or script you want to execute.
  • executionContext Sets the permission level needed by the script, and can be either limited or elevated. Configuration changes such as changing IIS settings will require that the task be run in an elevated mode.
  • taskType Can be either simple, foreground, or background. A simple task is executed synchronously before a role starts. Foreground and background tasks are executed asynchronously in parallel with the role. A foreground task can keep a role running and prevent it from shutting down or recycle. A background task will be stopped if a role needs to shut down or be recycled

    Task commandLine="startup\startup.cmd" executionContext="elevated" taskType="simple"

Reference documentation is here https://azure.microsoft.com/en-us/documentation/articles/cloud-services-startup-tasks/ Hope this helps Happy new year ! Best regards Stéphane

0
votes

Essentially the Cloud Service Project helps you authoring the required files, package the solution and deploy it. These steps can be broken out in to individual tasks, where the authoring and deployment part is described by stephgou and Mr Lister.

To package you need to use CSPack.exe. https://azure.microsoft.com/en-us/documentation/articles/cloud-services-model-and-package/#servicepackagecspkg.

Also take a look here to understand the process. The PowerShell provided in the other answer will substitute the GUI guidance in this article: https://azure.microsoft.com/en-us/documentation/articles/cloud-services-how-to-create-deploy-portal/