Skip to content

Commit

Permalink
Added Kudu.Console and exe that performs deployment.
Browse files Browse the repository at this point in the history
Changed logic to perform deployment as part of git push.
  • Loading branch information
davidfowl committed Apr 5, 2012
1 parent a5114d5 commit 4cd42b5
Show file tree
Hide file tree
Showing 25 changed files with 516 additions and 226 deletions.
9 changes: 9 additions & 0 deletions Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,14 @@ public static class Constants
public const string MappedLiveSite = "/_app";
public const string MappedDevSite = "/_devapp";
public const string RepositoryPath = "repository";

public const string LockPath = "locks";
public const string DeploymentLockFile = "deployments.lock";
public const string InitLockFile = "init.lock";

public const string DeploymentCachePath = "deployments";
public const string TracePath = @"LogFiles\Git\trace";
public const string DeploySettingsPath = "settings.xml";
public const string TraceFile = "trace.xml";
}
}
84 changes: 84 additions & 0 deletions Kudu.Console/Kudu.Console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E2B0EE28-8C96-497A-AB08-605B9FD841E9}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Kudu.Console</RootNamespace>
<AssemblyName>kudu</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Abstractions">
<HintPath>..\packages\System.IO.Abstractions.1.4.0.12\lib\net35\System.IO.Abstractions.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Common\Constants.cs">
<Link>Constants.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Kudu.Contracts\Kudu.Contracts.csproj">
<Project>{EC0ED988-2C60-4F31-A434-645E048BFD95}</Project>
<Name>Kudu.Contracts</Name>
</ProjectReference>
<ProjectReference Include="..\Kudu.Core\Kudu.Core.csproj">
<Project>{5320177C-725A-44BD-8FA6-F88D9725B46C}</Project>
<Name>Kudu.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Infrastructure\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
132 changes: 132 additions & 0 deletions Kudu.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using Kudu.Core;
using Kudu.Core.Deployment;
using Kudu.Core.Infrastructure;
using Kudu.Core.SourceControl.Git;
using Kudu.Core.Tracing;

namespace Kudu.Console
{
class Program
{
static int Main(string[] args)
{
if (args.Length < 2)
{
System.Console.WriteLine("Usage: kudu.exe {appRoot} {wapTargets}");
return 1;
}

while (!System.Diagnostics.Debugger.IsAttached)
{

}

System.Environment.SetEnvironmentVariable("GIT_DIR", null, System.EnvironmentVariableTarget.Process);

var appRoot = args[0];
var wapTargets = args[1];
string nugetCachePath = null;

IEnvironment env = GetEnvironment(appRoot, nugetCachePath);

// Setup the trace
string tracePath = Path.Combine(env.ApplicationRootPath, Constants.TracePath, Constants.TraceFile);
var traceFactory = new TracerFactory(() => new Tracer(tracePath));

// Calculate the lock path
string lockPath = Path.Combine(env.ApplicationRootPath, Constants.LockPath);
string deploymentLockPath = Path.Combine(lockPath, Constants.DeploymentLockFile);
var deploymentLock = new LockFile(traceFactory, deploymentLockPath);

var fs = new FileSystem();
var buildPropertyProvider = new BuildPropertyProvider(wapTargets);
var builderFactory = new SiteBuilderFactory(buildPropertyProvider, env);
var serverRepository = new GitDeploymentRepository(env.DeploymentRepositoryPath, traceFactory);

var logger = new ConsoleLogger();
var deploymentManager = new DeploymentManager(serverRepository,
builderFactory,
env,
fs,
traceFactory,
deploymentLock,
logger);

try
{
deploymentManager.Deploy();
}
catch(System.Exception ex)
{
System.Console.Error.WriteLine(ex.Message);

throw;
}

if (logger.HasErrors)
{
return 1;
}

return 0;
}

private static IEnvironment GetEnvironment(string root, string nugetCachePath)
{
string deployPath = Path.Combine(root, Constants.WebRoot);
string deployCachePath = Path.Combine(root, Constants.DeploymentCachePath);
string deploymentRepositoryPath = Path.Combine(root, Constants.RepositoryPath);
string tempPath = Path.GetTempPath();
string deploymentTempPath = Path.Combine(tempPath, Constants.RepositoryPath);

return new Environment(root,
tempPath,
() => deploymentRepositoryPath,
() => null,
deployPath,
deployCachePath,
nugetCachePath);
}

private class BuildPropertyProvider : IBuildPropertyProvider
{
private readonly string _extensionsPath;

public BuildPropertyProvider(string extensionsPath)
{
_extensionsPath = extensionsPath;
}

public IDictionary<string, string> GetProperties()
{
return new Dictionary<string, string> {
{ "MSBuildExtensionsPath32", _extensionsPath }
};
}
}

private class ConsoleLogger : ILogger
{
public ILogger Log(string value, LogEntryType type)
{
if (type == LogEntryType.Error)
{
HasErrors = true;

System.Console.Error.WriteLine(value);
}
else
{
System.Console.WriteLine(value);
}

return NullLogger.Instance;
}

public bool HasErrors { get; set; }
}
}
}
36 changes: 36 additions & 0 deletions Kudu.Console/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Kudu.Console")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Kudu.Console")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1d669d37-1397-4533-8bb7-561c46217f5d")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
3 changes: 3 additions & 0 deletions Kudu.Console/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
4 changes: 4 additions & 0 deletions Kudu.Console/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.IO.Abstractions" version="1.4.0.12" />
</packages>
7 changes: 7 additions & 0 deletions Kudu.Contracts/Deployment/IDeploymentCommandGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Kudu.Core.Deployment
{
public interface IDeploymentCommandGenerator
{
string GetDeploymentCommand();
}
}
1 change: 0 additions & 1 deletion Kudu.Contracts/IEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ public interface IEnvironment
string ApplicationRootPath { get; }
string NuGetCachePath { get; }
string TempPath { get; }
string AppName { get; }
}
}
2 changes: 1 addition & 1 deletion Kudu.Contracts/Infrastructure/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void Catch(this Task task, Action<Exception> handler)
Trace.TraceError(t.Exception.Message);
handler(t.Exception);
}
}, TaskContinuationOptions.OnlyOnFaulted);
}, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously);
}

public static Task Then<TInnerResult>(this Task<TInnerResult> task, Action<TInnerResult> continuation, CancellationToken cancellationToken = default(CancellationToken))
Expand Down
2 changes: 2 additions & 0 deletions Kudu.Contracts/Kudu.Contracts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="Commands\ICommandExecutor.cs" />
<Compile Include="Deployment\DeployResult.cs" />
<Compile Include="Deployment\DeployStatus.cs" />
<Compile Include="Deployment\IDeploymentCommandGenerator.cs" />
<Compile Include="Deployment\IDeploymentManager.cs" />
<Compile Include="Deployment\IDeploymentManagerFactory.cs" />
<Compile Include="Deployment\LogEntry.cs" />
Expand All @@ -61,6 +62,7 @@
<Compile Include="Infrastructure\IOperationLock.cs" />
<Compile Include="Infrastructure\LockExtensions.cs" />
<Compile Include="Infrastructure\TaskExtensions.cs" />
<Compile Include="SourceControl\IDeploymentRepository.cs" />
<Compile Include="SourceControl\RepositoryConfiguration.cs" />
<Compile Include="Tracing\ITracer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
13 changes: 13 additions & 0 deletions Kudu.Contracts/SourceControl/IDeploymentRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Kudu.Core.SourceControl;

namespace Kudu.Core.SourceControl
{
public interface IDeploymentRepository
{
void Clean();
ChangeSet GetChangeSet(string id);
PushInfo GetPushInfo();
void Update();
void Update(string id);
}
}
7 changes: 1 addition & 6 deletions Kudu.Contracts/SourceControl/IServerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ namespace Kudu.Core.SourceControl
{
public interface IServerRepository
{
string CurrentId { get; }
bool Exists { get; }
PushInfo GetPushInfo();
bool Initialize(RepositoryConfiguration configuration);
ChangeSet Initialize(RepositoryConfiguration configuration, string path);
ChangeSet GetChangeSet(string id);
void Update(string id);
void Update();
void Clean();
RepositoryType GetRepositoryType();
void Clean();
}
}
20 changes: 20 additions & 0 deletions Kudu.Core/Deployment/CascadeLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Kudu.Core.Deployment
{
internal class CascadeLogger : ILogger
{
private readonly ILogger _primary;
private readonly ILogger _secondary;

public CascadeLogger(ILogger primary, ILogger secondary)
{
_primary = primary;
_secondary = secondary;
}

public ILogger Log(string value, LogEntryType type)
{
_secondary.Log(value, type);
return _primary.Log(value, type);
}
}
}
Loading

0 comments on commit 4cd42b5

Please sign in to comment.