Created
June 9, 2011 17:47
-
-
Save ferventcoder/1017280 to your computer and use it in GitHub Desktop.
DropkicK Deployment Example
This file contains 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.IO; | |
using System.Security.Cryptography.X509Certificates; | |
using dropkick.Configuration.Dsl; | |
using dropkick.Configuration.Dsl.Files; | |
using dropkick.Configuration.Dsl.Iis; | |
using dropkick.Configuration.Dsl.RoundhousE; | |
using dropkick.Configuration.Dsl.Security; | |
using dropkick.Configuration.Dsl.WinService; | |
using dropkick.Wmi; | |
namespace App.Deployment | |
{ | |
public class TheDeployment : Deployment<TheDeployment, DeploymentSettings> | |
{ | |
public TheDeployment() | |
{ | |
Define(settings => | |
{ | |
DeploymentStepsFor(Db, | |
s => | |
{ | |
s.RoundhousE() | |
.ForEnvironment(settings.Environment) | |
.OnDatabase(settings.DbName) | |
.WithScriptsFolder(settings.DbSqlFilesPath) | |
.WithDatabaseRecoveryMode(settings.DbRecoveryMode) | |
.WithRestorePath(settings.DbRestorePath) | |
.WithRepositoryPath("https://github.com/chucknorris/roundhouse.git") | |
.WithVersionFile("_BuildInfo.xml") | |
.WithRoundhousEMode(settings.RoundhousEMode); | |
}); | |
DeploymentStepsFor(Web, | |
s => | |
{ | |
s.CopyDirectory(@"..\_PublishedWebSites\WebName").To(@"{{WebsitePath}}").DeleteDestinationBeforeDeploying(); | |
s.CopyFile(@"..\environment.files\{{Environment}}\{{Environment}}.web.config").ToDirectory(@"{{WebsitePath}}").RenameTo(@"web.config"); | |
s.Security(securityOptions => | |
{ | |
securityOptions.ForPath(settings.WebsitePath, fileSecurityConfig => fileSecurityConfig.GrantRead(settings.WebUserName)); | |
securityOptions.ForPath(Path.Combine(settings.HostServicePath, "logs"), fs => fs.GrantReadWrite(settings.WebUserName)); | |
securityOptions.ForPath(@"~\C$\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files", fs => fs.GrantReadWrite(settings.WebUserName)); | |
if (Directory.Exists(@"~\C$\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files")) | |
{ | |
securityOptions.ForPath(@"~\C$\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files", fs => fs.GrantReadWrite(settings.WebUserName)); | |
} | |
securityOptions.ForCertificate(settings.CertificateThumbprint, c => | |
{ | |
c.GrantReadPrivateKey() | |
.To(settings.WebUserName) | |
.InStoreLocation(StoreLocation.LocalMachine) | |
.InStoreName(StoreName.My); | |
}); | |
}); | |
}); | |
DeploymentStepsFor(Host, | |
s => | |
{ | |
var serviceName = "ServiceName.{{Environment}}"; | |
s.WinService(serviceName).Stop(); | |
s.CopyDirectory(@"..\_PublishedApplications\ServiceName").To(@"{{HostServicePath}}").DeleteDestinationBeforeDeploying(); | |
s.CopyFile(@"..\environment.files\{{Environment}}\{{Environment}}.servicename.exe.config").ToDirectory(@"{{HostServicePath}}").RenameTo(@"servicename.exe.config"); | |
s.Security(o => | |
{ | |
o.ForCertificate(settings.CertificateThumbprint, c => | |
{ | |
c.GrantReadPrivateKey() | |
.To(settings.ServiceUserName) | |
.InStoreLocation(StoreLocation.LocalMachine) | |
.InStoreName(StoreName.My); | |
}); | |
o.LocalPolicy(lp => | |
{ | |
lp.LogOnAsService(settings.ServiceUserName); | |
lp.LogOnAsBatch(settings.ServiceUserName); | |
}); | |
o.ForPath(settings.HostServicePath, fs => fs.GrantRead(settings.ServiceUserName)); | |
o.ForPath(Path.Combine(settings.HostServicePath,"logs"), fs => fs.GrantReadWrite(settings.ServiceUserName)); | |
o.ForPath(settings.ServiceWorkDirectory, fs => fs.GrantReadWrite(settings.ServiceUserName)); | |
o.ForPath(settings.ServiceTriggerWatchDirectory, fs => fs.GrantReadWrite(settings.ServiceUserName)); | |
o.ForPath(settings.SecureWorkDirectory, fs => | |
{ | |
fs.GrantReadWrite(settings.ServiceUserName); | |
fs.RemoveInheritance(); | |
fs.Clear().Preserve(settings.ServiceUserName) | |
.RemoveAdministratorsGroup() | |
.RemoveUsersGroup(); | |
}); | |
}); | |
s.WinService(serviceName).Delete(); | |
s.WinService(serviceName).Create().WithCredentials(settings.ServiceUserName, settings.ServiceUserPassword).WithDisplayName("servicename({{Environment}})").WithServicePath(@"{{HostServicePath}}\servicename.exe"). | |
WithStartMode(settings.ServiceStartMode) | |
.AddDependency("MSMQ"); | |
if (settings.ServiceStartMode != ServiceStartMode.Disabled && settings.ServiceStartMode != ServiceStartMode.Manual) | |
{ | |
s.WinService(serviceName).Start(); | |
} | |
}); | |
}); | |
} | |
//order is important | |
public static Role Db { get; set; } | |
public static Role Web { get; set; } | |
public static Role Host { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment