Skip to content
ferventcoder edited this page Oct 28, 2011 · 8 revisions

Deployment Plans

Deployment Plan (C#)

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,s => 
        {
          //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)'

Example

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("__REPLACE_ME__")
                                           .WithVersionFile("_BuildInfo.xml")
                                           .WithRoundhousEMode(settings.RoundhousEMode)
                                           ;
                                   });

                DeploymentStepsFor(Web,
                                   s =>
                                   {
                                       s.CopyDirectory(@"..\_PublishedWebSites\__REPLACE_ME__").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 = "__REPLACE_ME__.{{Environment}}";
                                       s.WinService(serviceName).Stop();

                                       s.CopyDirectory(@"..\_PublishedApplications\__REPLACE_ME__").To(@"{{HostServicePath}}").DeleteDestinationBeforeDeploying();

                                       s.CopyFile(@"..\environment.files\{{Environment}}\{{Environment}}.__REPLACE_ME__.exe.config").ToDirectory(@"{{HostServicePath}}").RenameTo(@"__REPLACE_ME__.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("__REPLACE_ME__ ({{Environment}})").WithServicePath(@"{{HostServicePath}}\__REPLACE_ME__.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; }
    }
}

Clone this wiki locally