Skip to content

Commit

Permalink
Multiple Changes - Continued Nest Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
miyu committed Dec 8, 2015
1 parent 5ed0cf9 commit 5bb9942
Show file tree
Hide file tree
Showing 26 changed files with 348 additions and 52 deletions.
22 changes: 22 additions & 0 deletions dargon-root.sln
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "trinket-dim", "dargon\DargonInjectedModule\Dargon - Injected Module.vcxproj", "{D1C97EAF-0503-4031-A690-CD6CCAD48C5A}"
ProjectSection(ProjectDependencies) = postProject
{6615AB36-20B2-4F72-B5BF-7134E06F74C5} = {6615AB36-20B2-4F72-B5BF-7134E06F74C5}
{52D8CBEE-1B14-4FCA-B824-096A43776456} = {52D8CBEE-1B14-4FCA-B824-096A43776456}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dargon.Courier.Api", "dependencies\Dargon.Courier\Dargon.Courier\Dargon.Courier.Api.csproj", "{00A1DA2F-D316-4387-8BD4-F1A47C05A402}"
Expand Down Expand Up @@ -374,6 +375,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "deployments", "deployments"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dargon-client-deployment", "dev\dargon-client-deployment\dargon-client-deployment.csproj", "{664BC68C-1AAF-4F03-B193-C142200A8A29}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "deploy-nest-core-and-client", "dev\deploy-nest-core-and-client\deploy-nest-core-and-client.csproj", "{F6222CE1-C6F4-4FF5-BFBD-703333114D24}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Console|Any CPU = Console|Any CPU
Expand Down Expand Up @@ -2727,6 +2730,24 @@ Global
{664BC68C-1AAF-4F03-B193-C142200A8A29}.Release|x64.Build.0 = Release|Any CPU
{664BC68C-1AAF-4F03-B193-C142200A8A29}.Release|x86.ActiveCfg = Release|Any CPU
{664BC68C-1AAF-4F03-B193-C142200A8A29}.Release|x86.Build.0 = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Console|Any CPU.ActiveCfg = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Console|Any CPU.Build.0 = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Console|x64.ActiveCfg = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Console|x64.Build.0 = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Console|x86.ActiveCfg = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Console|x86.Build.0 = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Debug|x64.ActiveCfg = Debug|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Debug|x64.Build.0 = Debug|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Debug|x86.ActiveCfg = Debug|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Debug|x86.Build.0 = Debug|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Release|Any CPU.Build.0 = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Release|x64.ActiveCfg = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Release|x64.Build.0 = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Release|x86.ActiveCfg = Release|Any CPU
{F6222CE1-C6F4-4FF5-BFBD-703333114D24}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2900,5 +2921,6 @@ Global
{0ED45046-0E3D-42EC-814A-8E8BCD1FFE28} = {18439844-AFEB-46FA-8CF8-0C5138261415}
{A08D2FFF-95DB-4951-9023-BD4C27CA8CB4} = {18439844-AFEB-46FA-8CF8-0C5138261415}
{664BC68C-1AAF-4F03-B193-C142200A8A29} = {A08D2FFF-95DB-4951-9023-BD4C27CA8CB4}
{F6222CE1-C6F4-4FF5-BFBD-703333114D24} = {18439844-AFEB-46FA-8CF8-0C5138261415}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion dependencies/Dargon.Ryu
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<Compile Include="DevDeployment.cs" />
<Compile Include="NestDeployer.cs" />
<Compile Include="NestDeployerConstants.cs" />
<Compile Include="NestEgg.cs" />
<Compile Include="DevEgg.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -83,6 +83,9 @@
<Name>init</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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.
Expand Down
2 changes: 1 addition & 1 deletion dev/Dargon.Nest.DevelopmentUtilities/DevBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Dargon.Nest.DevelopmentUtilities {
public abstract class DevBundle {
public abstract string Name { get; }
public string InitScript { get; protected set; }
public List<NestEgg> Eggs { get; } = new List<NestEgg>();
public List<DevEgg> Eggs { get; } = new List<DevEgg>();
}
}
2 changes: 2 additions & 0 deletions dev/Dargon.Nest.DevelopmentUtilities/DevDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Dargon.Nest.DevelopmentUtilities {
public abstract class DevDeployment {
public abstract string Name { get; }
public List<DevBundle> Bundles { get; } = new List<DevBundle>();
public List<DevEgg> AdditionalEggs { get; } = new List<DevEgg>();
public virtual int NestClusterPort { get; } = -1;
public virtual string Version { get; set; } = "dev";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
using ItzWarty;

namespace Dargon.Nest.DevelopmentUtilities {
public class NestEgg {
public class DevEgg {
public string Name { get; set; }
public string SourceDirectory { get; set; }

public static NestEgg FromProject(string name, Type projectType) {
public static DevEgg FromProject(string name, Type projectType) {
return FromRelativeProject(name, projectType, ".");
}

public static NestEgg FromRelativeProject(string name, Type projectType, string relativeProjectDirectoryPath) {
public static DevEgg FromRelativeProject(string name, Type projectType, string relativeProjectDirectoryPath) {

var codeBase = new Uri(projectType.Assembly.CodeBase).AbsolutePath;
var projectName = new FileInfo(codeBase).Name.Pass(x => x.Substring(0, x.Length - 4));
Expand All @@ -30,7 +30,7 @@ public static NestEgg FromRelativeProject(string name, Type projectType, string
var matchDirectory = Path.GetDirectoryName(match);
var finalPath = Path.GetFullPath(Path.Combine(matchDirectory, relativeProjectDirectoryPath));
progress.Update(finalPath);
return new NestEgg() {
return new DevEgg() {
Name = name,
SourceDirectory = Path.Combine(finalPath, "bin", "Debug")
};
Expand Down
134 changes: 113 additions & 21 deletions dev/Dargon.Nest.DevelopmentUtilities/NestDeployer.cs
Original file line number Diff line number Diff line change
@@ -1,63 +1,152 @@
using Dargon.Nest.Internals;
using Dargon.Nest.Internals.Eggs;
using Dargon.Ryu;
using dev_egg_runner;
using ItzWarty;
using ItzWarty.IO;
using Nest.Init;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Dargon.Nest.DevelopmentUtilities {
public static class NestDeployer {
private static readonly IFileSystemProxy fileSystemProxy;
private static readonly string dargonPath;
private static readonly string nestClientPath;
private static readonly string nestServerPath;

static NestDeployer() {
var ryu = new RyuFactory().Create();
ryu.Touch<ItzWartyProxiesRyuPackage>();
fileSystemProxy = ryu.Get<IFileSystemProxy>();

dargonPath = Path.Combine(NestDeployerConstants.RootSolutionDirectoryPath, "deploy", "nest_client");
fileSystemProxy.PrepareDirectory(dargonPath);
nestClientPath = Path.Combine(NestDeployerConstants.RootSolutionDirectoryPath, "deploy", "nest_client");
fileSystemProxy.PrepareDirectory(nestClientPath);

// nestServerPath = Path.Combine(NestDeployerConstants.RootSolutionDirectoryPath, "deploy", "nest_server");
nestServerPath = @"C:\Apache24\htdocs"; //Path.Combine(NestDeployerConstants.RootSolutionDirectoryPath, "deploy", "nest_server");
fileSystemProxy.PrepareDirectory(nestServerPath);
}

public static void Clean() {
public static void ClientClean() => CleanDirectory(nestClientPath);

public static void ServerClean() => CleanDirectory(nestServerPath);

private static void CleanDirectory(string path) {
while (true) {
try {
if (Directory.Exists(dargonPath)) {
Directory.Delete(dargonPath, true);
if (Directory.Exists(path)) {
Directory.Delete(path, true);
}
break;
} catch (IOException e) {
Console.WriteLine($"Can't clear {dargonPath}: {e}");
Console.WriteLine($"Can't clear {path}: {e}");
Thread.Sleep(2000);
} catch (UnauthorizedAccessException e) {
Console.WriteLine($"This sometimes happens (ignore?): {e}");
}
}
Directory.CreateDirectory(dargonPath);
Directory.CreateDirectory(path);
}

public static void ServerLikeDeployAndInit(DevDeployment developmentDeployment) {
var eggsDirectoryPath = Path.Combine(nestServerPath, NestConstants.kEggsDirectoryName);
fileSystemProxy.PrepareDirectory(eggsDirectoryPath);

var bundlesDirectoryPath = Path.Combine(nestServerPath, NestConstants.kBundlesDirectoryName);
fileSystemProxy.PrepareDirectory(bundlesDirectoryPath);

var deploymentsDirectoryPath = Path.Combine(nestServerPath, NestConstants.kDeploymentsDirectoryName);
fileSystemProxy.PrepareDirectory(deploymentsDirectoryPath);

foreach (var developmentBundle in developmentDeployment.Bundles) {
foreach (var developmentEgg in developmentBundle.Eggs) {
ServerLikeDeployEgg(developmentDeployment, eggsDirectoryPath, developmentEgg);
}

// create bundle release
var bundleReleasePath = Path.Combine(bundlesDirectoryPath, developmentBundle.Name, NestConstants.kReleasesDirectoryName, developmentBundle.Name + "-" + developmentDeployment.Version);
fileSystemProxy.PrepareDirectory(bundleReleasePath);

var eggsString = string.Join("\r\n", developmentBundle.Eggs.Select(e => e.Name + " " + developmentDeployment.Version));
fileSystemProxy.WriteAllText(Path.Combine(bundleReleasePath, NestConstants.kEggsFileName), eggsString);

var initScript = developmentBundle.InitScript ?? "";
fileSystemProxy.WriteAllText(Path.Combine(bundleReleasePath, NestConstants.kInitJsonFileName), initScript);
}

// Deploy additional eggs (namely, init)
foreach (var developmentEgg in developmentDeployment.AdditionalEggs) {
ServerLikeDeployEgg(developmentDeployment, eggsDirectoryPath, developmentEgg);

// point latest to our egg
var stablePath = Path.Combine(eggsDirectoryPath, developmentEgg.Name, NestConstants.kChannelsDirectoryName, "stable");
fileSystemProxy.PrepareParentDirectory(stablePath);
File.WriteAllText(stablePath, developmentDeployment.Version);
}

// Deploy the deployment
var deploymentDirectoryPath = Path.Combine(deploymentsDirectoryPath, developmentDeployment.Name);
var deploymentLatestPath = Path.Combine(deploymentDirectoryPath, NestConstants.kChannelsDirectoryName, "stable");
fileSystemProxy.PrepareParentDirectory(deploymentLatestPath);
fileSystemProxy.WriteAllText(deploymentLatestPath, developmentDeployment.Version);

var deploymentReleasePath = Path.Combine(deploymentDirectoryPath, NestConstants.kReleasesDirectoryName, developmentDeployment.Name + "-" + developmentDeployment.Version);
fileSystemProxy.PrepareDirectory(deploymentReleasePath);

var bundlesString = developmentDeployment.Bundles.Select(b => b.Name + " " + developmentDeployment.Version).Join("\r\n");
fileSystemProxy.WriteAllText(Path.Combine(deploymentReleasePath, NestConstants.kBundlesFileName), bundlesString);
}

private static void ServerLikeDeployEgg(DevDeployment deployment, string serverEggsDirectoryPath, DevEgg developmentEgg) {
var serverEggDirectory = Path.Combine(serverEggsDirectoryPath, developmentEgg.Name);

// import dev egg to cache directory
var cache = new NestFileCache(Path.Combine(serverEggDirectory, NestConstants.kCacheDirectoryName));
var inMemoryEgg = EggFactory.InMemory(developmentEgg.Name, developmentEgg.SourceDirectory, "dev");
var cacheDeployTasks = new List<Task>();
var fileList = inMemoryEgg.EnumerateFilesAsync().Result.ToArray();
foreach (var fileEntry in fileList) {
var cacheDeployTask = cache.OpenOrAddAndOpenAsync(fileEntry.Guid, add => {
var fullPath = inMemoryEgg.ComputeFullPath(fileEntry.InternalPath);
return IoUtilities.ReadBytesAsync(fullPath);
});
cacheDeployTasks.Add(cacheDeployTask);
}

// create release
var releaseDirectoryPath = Path.Combine(serverEggDirectory, NestConstants.kReleasesDirectoryName, developmentEgg.Name + "-" + deployment.Version);
fileSystemProxy.PrepareDirectory(releaseDirectoryPath);
var filelistContents = EggFileEntrySerializer.Serialize(fileList);
File.WriteAllText(Path.Combine(releaseDirectoryPath, NestConstants.kFileListFileName), filelistContents);
}

public static void DeployAndInit(DevDeployment developmentDeployment) {
var deploymentPath = Path.Combine(dargonPath, NestConstants.kDeploymentsDirectoryName, developmentDeployment.Name);
fileSystemProxy.PrepareDirectory(deploymentPath);
public static void ClientLikeDeployAndInit(DevDeployment developmentDeployment) {
var clientDeploymentPath = Path.Combine(nestClientPath, NestConstants.kDeploymentsDirectoryName, developmentDeployment.Name);
fileSystemProxy.PrepareDirectory(clientDeploymentPath);

// create cache directory
var cacheDirectoryPath = IoUtilities.CombinePath(clientDeploymentPath, NestConstants.kCacheDirectoryName);
IoUtilities.PrepareDirectory(cacheDirectoryPath);

// setup bundles directory
var bundlesPath = Path.Combine(deploymentPath, "bundles");
fileSystemProxy.PrepareDirectory(bundlesPath);
var clientBundlesPath = Path.Combine(clientDeploymentPath, "bundles");
fileSystemProxy.PrepareDirectory(clientBundlesPath);

// deploy bundles
foreach (var developmentBundle in developmentDeployment.Bundles) {
var bundlePath = Path.Combine(bundlesPath, developmentBundle.Name);
var bundlePath = Path.Combine(clientBundlesPath, developmentBundle.Name);
fileSystemProxy.PrepareDirectory(bundlePath);

var bundle = BundleFactory.Local(bundlePath);
foreach (var egg in developmentBundle.Eggs) {
var progress = new CliProgressSpinner($"Installing egg {developmentBundle.Name}/{egg.Name}.");
progress.Update("...");
bundle.InstallEgg(EggFactory.InMemory(egg.Name, egg.SourceDirectory, "dev"));
bundle.InstallEggAsync(EggFactory.InMemory(egg.Name, egg.SourceDirectory, "dev")).Wait();
progress.Update("Done");
}

Expand All @@ -67,13 +156,16 @@ public static void DeployAndInit(DevDeployment developmentDeployment) {
}
}

// deploy init
var initDirectory = NestEgg.FromProject("init", typeof(InitNestBundleDummy)).SourceDirectory;
var initPath = Path.Combine(initDirectory, "init.exe");
var deployedInitPath = Path.Combine(deploymentPath, new FileInfo(initPath).Name);
File.Copy(initPath, deployedInitPath, true);
// deploy init, sort of a hack
var clientBundle = BundleFactory.Local(clientDeploymentPath);
var developmentInitEgg = DevEgg.FromProject("init", typeof(InitNestBundleDummy));
clientBundle.InstallEggAsync(EggFactory.InMemory("init", developmentInitEgg.SourceDirectory, "dev")).Wait();

var initEggDirectory = IoUtilities.CombinePath(clientDeploymentPath, "init");
var deployedInitPath = Path.Combine(initEggDirectory, "init.exe");

// start init
Console.WriteLine("Starting init: " + deployedInitPath);
Process.Start(
new ProcessStartInfo(
deployedInitPath,
Expand All @@ -85,7 +177,7 @@ public static void DeployAndInit(DevDeployment developmentDeployment) {
var spinner = new CliProgressSpinner("Ctrl+C = Kill Nest");
Console.CancelKeyPress += (s, e) => {
var commanderName = "dev-nest-commander";
var commanderProject = NestEgg.FromProject(commanderName, typeof(CommanderNestBundleDummy));
var commanderProject = DevEgg.FromProject(commanderName, typeof(CommanderNestBundleDummy));
var commanderPath = Path.Combine(commanderProject.SourceDirectory, commanderName + ".exe");

Process.Start(
Expand Down
3 changes: 3 additions & 0 deletions dev/Dargon.Nest.DevelopmentUtilities/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
</packages>
4 changes: 2 additions & 2 deletions dev/client-bundle/ClientBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class ClientBundle : DevBundle {
public override string Name => "client";

public ClientBundle() {
Eggs.Add(NestEgg.FromProject("dargon-client", typeof(DargonClientEgg)));
Eggs.Add(NestEgg.FromProject("thumbnail-generator", typeof(ThumbnailGenerationEgg)));
Eggs.Add(DevEgg.FromProject("dargon-client", typeof(DargonClientApplication)));
Eggs.Add(DevEgg.FromProject("thumbnail-generator", typeof(ThumbnailGenerationApplication)));

InitScript = Encoding.UTF8.GetString(Properties.Resources.init);
}
Expand Down
4 changes: 2 additions & 2 deletions dev/core-bundle/CoreBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class CoreBundle : DevBundle {
public override string Name => "core";

public CoreBundle() {
Eggs.Add(NestEgg.FromProject("cored", typeof(CoreDaemonApplicationEgg)));
Eggs.Add(NestEgg.FromProject("dargon-cli", typeof(DargonCliBundleDummyClass)));
Eggs.Add(DevEgg.FromProject("cored", typeof(CoreDaemonApplication)));
Eggs.Add(DevEgg.FromProject("dargon-cli", typeof(DargonCliBundleDummyClass)));

InitScript = Encoding.UTF8.GetString(global::core_bundle.Properties.Resources.init);
}
Expand Down
4 changes: 4 additions & 0 deletions dev/dargon-client-deployment/DargonClientDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
using core_bundle;
using Dargon.Nest.DevelopmentUtilities;
using nest_bundle;
using Nest.Init;
using trinket_bundle;

namespace dargon_client {
public class DargonClientDeployment : DevDeployment {
public override string Name => "dargon-client";
public override int NestClusterPort => 21999;
public override string Version => "0.0.6-alpha";

public DargonClientDeployment() {
Bundles.Add(new ClientBundle());
Bundles.Add(new CoreBundle());
Bundles.Add(new NestBundle());
Bundles.Add(new TrinketBundle());

AdditionalEggs.Add(DevEgg.FromProject("init", typeof(InitNestBundleDummy)));
}
}
}
11 changes: 11 additions & 0 deletions dev/dargon-client-deployment/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Loading

0 comments on commit 5bb9942

Please sign in to comment.