Skip to content

Commit

Permalink
VCI-779: Minor fixes of codesmells (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro authored Jan 24, 2024
1 parent 8dffb5c commit 5b536aa
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 378 deletions.
2 changes: 1 addition & 1 deletion shelltests/packages.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ vc-build install -stable -v 4
>>>= 0

# Update to Bundle #5
vc-build update -v 4
vc-build update -v 5
>>>2
>>>= 0

Expand Down
183 changes: 94 additions & 89 deletions src/VirtoCommerce.Build/Build.cs

Large diffs are not rendered by default.

166 changes: 89 additions & 77 deletions src/VirtoCommerce.Build/Cloud/Build.SaaS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,103 +125,115 @@ private static bool CheckAppServiceStatus(string expected, string actual)
public Target PrepareDockerContext => _ => _
.Before(InitPlatform, DockerLogin, BuildImage, PushImage, BuildAndPush)
.Triggers(InitPlatform)
.Executes(async () =>
{
var dockerBuildContext = ArtifactsDirectory / "docker";
var platformDirectory = dockerBuildContext / "platform";
var modulesPath = platformDirectory / "modules";
var dockerfilePath = dockerBuildContext / "Dockerfile";
.Executes(async () => await PrepareDockerContextMethod());

private async Task PrepareDockerContextMethod()
{
var dockerBuildContext = ArtifactsDirectory / "docker";
var platformDirectory = dockerBuildContext / "platform";
var modulesPath = platformDirectory / "modules";
var dockerfilePath = dockerBuildContext / "Dockerfile";

FileSystemTasks.EnsureCleanDirectory(dockerBuildContext);

FileSystemTasks.EnsureCleanDirectory(dockerBuildContext);
await HttpTasks.HttpDownloadFileAsync(DockerfileUrl, dockerfilePath);

await HttpTasks.HttpDownloadFileAsync(DockerfileUrl, dockerfilePath);
var modulesSourcePath = Solution?.Path != null
? WebProject.Directory / "modules"
: RootDirectory / "modules";

var modulesSourcePath = Solution?.Path != null
? WebProject.Directory / "modules"
: RootDirectory / "modules";
CopyPlatformDirectory(platformDirectory, modulesSourcePath);

// Copy the platform
if (Solution?.Path != null)
CopyModules(modulesPath, modulesSourcePath);

DockerBuildContextPath = dockerBuildContext;

if (string.IsNullOrWhiteSpace(DockerImageName))
{
DockerImageName = $"{DockerUsername}/{EnvironmentName}";
}

DockerImageTag ??= DateTime.Now.ToString("MMddyyHHmmss");
DockerfilePath = dockerfilePath;
DiscoveryPath = modulesPath;
ProbingPath = Path.Combine(platformDirectory, "app_data", "modules");
AppsettingsPath = Path.Combine(platformDirectory, "appsettings.json");
}

private static void CopyModules(AbsolutePath modulesPath, AbsolutePath modulesSourcePath)
{
// Copy modules
var modulesDirectories = Directory.EnumerateDirectories(modulesSourcePath);
foreach (var directory in modulesDirectories)
{
var webProjects = Directory.EnumerateFiles(directory, $"*.Web.csproj");
var moduleDirectoryName = Path.GetFileName(directory);
var moduleDestinationPath = Path.Combine(modulesPath, moduleDirectoryName);
if (!webProjects.Any())
{
DotNetTasks.DotNetPublish(settings => settings
.SetConfiguration(Configuration)
.SetProcessWorkingDirectory(WebProject.Directory)
.SetOutput(platformDirectory));
FileSystemTasks.CopyDirectoryRecursively(directory, moduleDestinationPath, DirectoryExistsPolicy.Merge, FileExistsPolicy.OverwriteIfNewer);
}
else
{
var nukeDir = Path.Combine(RootDirectory, ".nuke");
var directories = Directory.GetDirectories(RootDirectory).Where(d => !PathConstruction.IsDescendantPath(modulesSourcePath, d)
&& !PathConstruction.IsDescendantPath(nukeDir, d)
&& !PathConstruction.IsDescendantPath(ArtifactsDirectory, d)).ToArray();
var files = Directory.GetFiles(RootDirectory);

foreach ( var dir in directories)
var webProjectPath = webProjects.FirstOrDefault();
var directoryInfo = new DirectoryInfo(directory);
if (directoryInfo.LinkTarget != null)
{
var dirName = Path.GetFileName(dir);
FileSystemTasks.CopyDirectoryRecursively(dir, Path.Combine(platformDirectory, dirName), DirectoryExistsPolicy.Merge, FileExistsPolicy.OverwriteIfNewer);
webProjectPath = Path.Combine(directoryInfo.LinkTarget, Path.GetFileName(webProjectPath));
}

foreach( var file in files)
{
FileSystemTasks.CopyFileToDirectory(file, platformDirectory);
}
}
var solutionDir = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(webProjectPath)));
var solutions = Directory.EnumerateFiles(solutionDir, "*.sln");
Assert.True(solutions.Count() == 1, $"Solutions found: {solutions.Count()}");
var solutionPath = solutions.FirstOrDefault();
var solution = ProjectModelTasks.ParseSolution(solutionPath);
var webProject = solution.AllProjects.First(p => p.Name.EndsWith(".Web"));

// Copy modules
var modulesDirectories = Directory.EnumerateDirectories(modulesSourcePath);
foreach (var directory in modulesDirectories)
{
var webProjects = Directory.EnumerateFiles(directory, $"*.Web.csproj");
var moduleDirectoryName = Path.GetFileName(directory);
var moduleDestinationPath = Path.Combine(modulesPath, moduleDirectoryName);
if (!webProjects.Any())
{
FileSystemTasks.CopyDirectoryRecursively(directory, moduleDestinationPath, DirectoryExistsPolicy.Merge, FileExistsPolicy.OverwriteIfNewer);
}
else
WebPackBuildMethod(webProject);
PublishMethod(webProject, Path.Combine(moduleDestinationPath, "bin"), Configuration);
foreach (var contentDirectory in _moduleContentFolders)
{
var webProjectPath = webProjects.FirstOrDefault();
var directoryInfo = new DirectoryInfo(directory);
if (directoryInfo.LinkTarget != null)
{
webProjectPath = Path.Combine(directoryInfo.LinkTarget, Path.GetFileName(webProjectPath));
}

var solutionDir = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(webProjectPath)));
var solutions = Directory.EnumerateFiles(solutionDir, "*.sln");
Assert.True(solutions.Count() == 1, $"Solutions found: {solutions.Count()}");
var solutionPath = solutions.FirstOrDefault();
var solution = ProjectModelTasks.ParseSolution(solutionPath);
var webProject = solution.AllProjects.FirstOrDefault(p => p.Name.EndsWith(".Web"));

WebPackBuildBody(webProject);
PublishBody(webProject, Path.Combine(moduleDestinationPath, "bin"), Configuration);
foreach (var contentDirectory in _moduleContentFolders)
{
var contentDestination = Path.Combine(moduleDestinationPath, contentDirectory);
var contentSource = Path.Combine(webProject.Directory, contentDirectory);
FileSystemTasks.CopyDirectoryRecursively(contentSource, contentDestination, DirectoryExistsPolicy.Merge, FileExistsPolicy.OverwriteIfNewer);
}

var moduleManifestPath = webProject.Directory / "module.manifest";
FileSystemTasks.CopyFileToDirectory(moduleManifestPath, moduleDestinationPath, FileExistsPolicy.OverwriteIfNewer);
var contentDestination = Path.Combine(moduleDestinationPath, contentDirectory);
var contentSource = Path.Combine(webProject.Directory, contentDirectory);
FileSystemTasks.CopyDirectoryRecursively(contentSource, contentDestination, DirectoryExistsPolicy.Merge, FileExistsPolicy.OverwriteIfNewer);
}

var moduleManifestPath = webProject.Directory / "module.manifest";
FileSystemTasks.CopyFileToDirectory(moduleManifestPath, moduleDestinationPath, FileExistsPolicy.OverwriteIfNewer);
}
}
}

DockerBuildContextPath = dockerBuildContext;
private static void CopyPlatformDirectory(AbsolutePath platformDirectory, AbsolutePath modulesSourcePath)
{
// Copy the platform
if (Solution?.Path != null)
{
DotNetTasks.DotNetPublish(settings => settings
.SetConfiguration(Configuration)
.SetProcessWorkingDirectory(WebProject.Directory)
.SetOutput(platformDirectory));
}
else
{
var nukeDir = Path.Combine(RootDirectory, ".nuke");
var directories = Directory.GetDirectories(RootDirectory).Where(d => !PathConstruction.IsDescendantPath(modulesSourcePath, d)
&& !PathConstruction.IsDescendantPath(nukeDir, d)
&& !PathConstruction.IsDescendantPath(ArtifactsDirectory, d)).ToArray();
var files = Directory.GetFiles(RootDirectory);

if (string.IsNullOrWhiteSpace(DockerImageName))
foreach (var dir in directories)
{
DockerImageName = $"{DockerUsername}/{EnvironmentName}";
var dirName = Path.GetFileName(dir);
FileSystemTasks.CopyDirectoryRecursively(dir, Path.Combine(platformDirectory, dirName), DirectoryExistsPolicy.Merge, FileExistsPolicy.OverwriteIfNewer);
}

DockerImageTag ??= DateTime.Now.ToString("MMddyyHHmmss");
DockerfilePath = dockerfilePath;
DiscoveryPath = modulesPath;
ProbingPath = Path.Combine(platformDirectory, "app_data", "modules");
AppsettingsPath = Path.Combine(platformDirectory, "appsettings.json");
});
foreach (var file in files)
{
FileSystemTasks.CopyFileToDirectory(file, platformDirectory);
}
}
}

public Target CloudDeploy => _ => _
.DependsOn(PrepareDockerContext, BuildAndPush)
Expand Down
3 changes: 2 additions & 1 deletion src/VirtoCommerce.Build/GrabMigrator/Build.GrabMigrator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nuke.Common;
using GrabMigratorNamespace = GrabMigrator;

namespace VirtoCommerce.Build
{
Expand All @@ -11,7 +12,7 @@ internal partial class Build
.Requires(() => GrabMigratorConfig)
.Executes(() =>
{
new GrabMigrator.GrabMigrator().Do(GrabMigratorConfig);
GrabMigratorNamespace.GrabMigrator.Do(GrabMigratorConfig);
});
}
}
Loading

0 comments on commit 5b536aa

Please sign in to comment.