Created
January 8, 2016 20:34
-
-
Save miklund/62bee7ef412d97849b7c to your computer and use it in GitHub Desktop.
2011-06-08 Automate deploy of your Orchard CMS to Azure
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: Automate deploy of your Orchard CMS to Azure | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2011/06/08/automate-deploy-of-your-orchard-cms-to-azure.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
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
using System.Web.Routing; | |
using Autofac; | |
using Microsoft.WindowsAzure; | |
using Microsoft.WindowsAzure.ServiceRuntime; | |
using Orchard.Environment; | |
using Orchard.WarmupStarter; | |
namespace LiteMedia.Web.Lib | |
{ | |
public class AzureApplication : HttpApplication | |
{ | |
public static void RegisterRoutes(RouteCollection routes) | |
{ | |
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | |
} | |
protected void Application_Start() | |
{ | |
CloudStorageAccount.SetConfigurationSettingPublisher( | |
(configName, configSetter) => | |
configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)) | |
); | |
// For information on handling configuration changes | |
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. | |
RoleEnvironment.Changing += (sender, e) => | |
{ | |
// If a configuration setting is changing | |
if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange)) | |
{ | |
// Set e.Cancel to true to restart this role instance | |
e.Cancel = true; | |
} | |
}; | |
RegisterRoutes(RouteTable.Routes); | |
Starter.LaunchStartupThread(MvcSingletons); | |
} | |
protected void Application_BeginRequest() | |
{ | |
Context.Items["originalHttpContext"] = Context; | |
Starter.OnBeginRequest(Context, MvcSingletons); | |
} | |
protected void Application_EndRequest() | |
{ | |
Starter.OnEndRequest(); | |
} | |
static void MvcSingletons(ContainerBuilder builder) | |
{ | |
builder.Register(ctx => RouteTable.Routes).SingleInstance(); | |
builder.Register(ctx => ModelBinders.Binders).SingleInstance(); | |
builder.Register(ctx => ViewEngines.Engines).SingleInstance(); | |
} | |
} | |
} |
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
task default -depends Compile | |
task Clean { | |
# If build dir exists, delete it | |
if (Test-Path $dir_build) { | |
rd $dir_build -Recurse -Force | |
} | |
# Recreate build target directories | |
md $dir_build | |
md $dir_compile | |
md $dir_package | |
md $dir_test | |
md $dir_deploy | |
} |
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
# Compile the project | |
task Compile -depends Clean { | |
exec { msbuild $web_csproj /verbosity:minimal /p:Configuration="$configuration" /p:Platform="Any CPU" /p:OutDir="$dir_compile" /p:OutputPath="$dir_compile" /p:SolutionDir="$dir_source" } | |
} |
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 | |
# The tools version of msbuild | |
$framework = '4.0' | |
properties { | |
# Build a release build (compared to Debug) | |
$configuration = 'Release' | |
# Tools executables | |
$bin_cspack = "C:\Program Files\Windows Azure SDK\v1.4\bin\cspack.exe" | |
$bin_csrun = "C:\Program Files\Windows Azure SDK\v1.4\bin\csrun.exe" | |
# Current working directory | |
$cwd = [System.IO.Directory]::GetCurrentDirectory() + '\' | |
# Directories we use for the build | |
$dir_build = $cwd + 'Build\' | |
$dir_compile = $dir_build + 'Compile\' | |
$dir_package = $dir_build + 'Package\' | |
$dir_test = $dir_build + 'Test\' | |
$dir_deploy = $dir_build + 'Deploy\' | |
$dir_approot = $dir_package + "LiteMedia.Web.Azure.csx\roles\LiteMedia.Web\approot\" | |
# Source directories | |
$dir_source = $cwd + 'Source\' | |
$dir_web = $dir_source + 'Main\LiteMedia.Web\' | |
$dir_azure = $dir_source + 'Main\LiteMedia.Web.Azure\' | |
# Orchard CMS project file and Azure project | |
$web_csproj = $dir_web + 'LiteMedia.Web.csproj' | |
$azure_ccproj = $dir_azure + 'LiteMedia.Web.Azure.ccproj' | |
# Specific Orchard Azure configuration | |
$dir_azureconfiguration = $cwd + 'Azure\' | |
$azure_web = $dir_azureconfiguration + 'Web\*' | |
$azure_serviceconfiguration = $dir_azureconfiguration + 'ServiceConfiguration\ServiceConfiguration.cscfg' | |
$azure_roleproperties = $dir_azureconfiguration + 'ServiceConfiguration\roleProperties.txt' | |
# Azure variables | |
$azure_service = "litemediainfo" | |
$azure_sub = "a8bdaa82-4fa3-4434-8b30-066553bc1c3e" | |
$azure_cert = Get-Item "cert:\CurrentUser\My\089E7878658AB876CCAB876AB8768BA687B6ADAD" | |
$azure_package = "$dir_deploy\LiteMedia.Web.Azure.cspkg" | |
$azure_config = "$azure_serviceconfiguration" | |
$azure_label = "litemedia.info " + [System.DateTime]::Now.ToString() | |
$azure_role = "litemedia.info" | |
$azure_storage = "litemedia" | |
} |
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
# Upload and deploy application to Azure | |
task DeployToAzure -depends PackageAzure { | |
#Upgrade the current staging deployment | |
Get-HostedService -serviceName $azure_service -subscriptionId $azure_sub -certificate $azure_cert | | |
Get-Deployment -slot Staging | | |
Set-Deployment -mode Auto -package $azure_package -label $azure_label -StorageServicename $azure_storage -configuration $azure_config | | |
Get-OperationStatus –WaitToComplete | |
#Set to running | |
Get-HostedService -serviceName $azure_service -subscriptionId $azure_sub -certificate $azure_cert | | |
Get-Deployment -slot Staging | | |
Set-DeploymentStatus running | | |
Get-OperationStatus –WaitToComplete | |
#Move staging to production, this will actually swap them over | |
Get-HostedService -serviceName $azure_service -subscriptionId $azure_sub -certificate $azure_cert | | |
Get-Deployment -slot staging | | |
Move-Deployment | | |
Get-OperationStatus –WaitToComplete | |
} |
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
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration> | |
<configSections> | |
<section name="autofac" type="Autofac.Configuration.SectionHandler, Autofac.Configuration"/> | |
</configSections> | |
<autofac defaultAssembly="Orchard.Framework"> | |
<components> | |
<component instance-scope="single-instance" | |
type="Orchard.Azure.Environment.Configuration.AzureShellSettingsManager, Orchard.Azure" | |
service="Orchard.Environment.Configuration.IShellSettingsManager"> | |
</component> | |
</components> | |
</autofac> | |
</configuration> |
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
# Create an Azure package | |
task PackageAzure -depends Compile { | |
# Build to the package directory | |
exec { msbuild $azure_ccproj /verbosity:minimal /p:Configuration="$configuration" /p:Platform="Any CPU" /p:OutDir="$dir_package" /p:OutputPath="$dir_package" /p:SolutionDir="$dir_source" } | |
# Copy Orchard specific Azure configuration to AppRoot | |
cp $azure_web $dir_approot -Recurse -Force | |
Write-Host "Create Azure Package" | |
&$bin_cspack /role:"LiteMedia.Web;$dir_approot;LiteMedia.Web.dll" /rolePropertiesFile:"LiteMedia.Web;$azure_roleproperties" "$dir_package\LiteMedia.Web.Azure.csx\ServiceDefinition.build.csdef" /out:"$dir_deploy\LiteMedia.Web.Azure.cspkg" | |
# Copy the ServiceConfiguration file to deploy directory | |
cp $azure_serviceconfiguration $dir_deploy | |
} |
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
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration> | |
<configSections> | |
<section name="autofac" type="Autofac.Configuration.SectionHandler, Autofac.Configuration"/> | |
</configSections> | |
<autofac defaultAssembly="Orchard.Framework"> | |
<components> | |
<component instance-scope="per-lifetime-scope" | |
type="Orchard.Azure.FileSystems.Media.AzureBlobStorageProvider, Orchard.Azure" | |
service="Orchard.FileSystems.Media.IStorageProvider"> | |
</component> | |
</components> | |
</autofac> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment