-
Notifications
You must be signed in to change notification settings - Fork 43
DeploymentPlan
This is the file where you talk about every role, tasks and steps to deploy each role. The class you use will inherit from dropkick.Dsl.Deployment
.
The class itself:
public class TheDeployment : Deployment<TheDeployment, DeploymentSettings> {}
Notice this is inheriting from Deployment, then it is passing itself and the Dropkick Configuration Settings back into the inheritor. This allows DK to perform some awesome sauce when inspecting the deployment plan.
In the class we implement a default constructor:
public TheDeployment()
{
Define(settings =>
{
DeploymentStepsFor(Db,server =>
{
//something happens here
});
}
}
Let's break this down. We define our execution plan, and it gives us the settings back to use for all of the roles/tasks/steps below that. Now we define 'DeploymentStepsFor(RoleName)' where RoleName is a Deployment Role that we have defined for the deployment.
When we we start to define our deployment steps, the server we are deploying to (server) is now also available to us. So now we can really define the tasks/steps we'd like to see on that server for this particular deployment role.
Adding tasks to the list of tasks that we can use is as simple as setting up the correct using
imports since all of the tasks hanging off of the server are Extension Methods.
using System.IO;
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 SomeDeployment
{
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("somewhereoutthere")
.WithVersionFile("_BuildInfo.xml")
.WithRoundhousEMode(settings.RoundhousEMode)
;
});
DeploymentStepsFor(Web,
s =>
{
s.CopyDirectory(@"..\_PublishedWebSites\WebAppName").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.WebsitePath, "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));
}
});
});
DeploymentStepsFor(VirtualDirectory,
s =>
{
s.Iis7Site(settings.VirtualDirectorySite)
.VirtualDirectory(settings.VirtualDirectoryName)
.SetAppPoolTo("Default Web Site", pool =>
{
pool.SetRuntimeToV4();
//pool.UseClassicPipeline();
//pool.Enable32BitAppOnWin64();
}).SetPathTo(@"{{WebsitePath}}");
});
DeploymentStepsFor(Host,
s =>
{
var serviceName = "AppHostName.{{Environment}}";
s.WinService(serviceName).Stop();
s.CopyDirectory(@"..\_PublishedApplications\AppHostName").To(@"{{HostServicePath}}").DeleteDestinationBeforeDeploying();
s.CopyFile(@"..\environment.files\{{Environment}}\{{Environment}}.AppHostName.exe.config").ToDirectory(@"{{HostServicePath}}").RenameTo(@"AppHostName.exe.config");
s.Security(o =>
{
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));
});
s.WinService(serviceName).Delete();
s.WinService(serviceName).Create().WithCredentials(settings.ServiceUserName, settings.ServiceUserPassword).WithDisplayName("AppHostName ({{Environment}})").WithServicePath(@"{{HostServicePath}}\AppHostName.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 VirtualDirectory { get; set; }
public static Role Host { get; set; }
}
}