public
Last active

DropkicK Deployment Example

  • Download Gist
TheDeployment.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
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; }
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.