Skip to content

Commit

Permalink
Merge branch 'release/3.19.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro committed Dec 8, 2023
2 parents 82a0c7e + ca51b1a commit bf7bb06
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Copyright>Copyright © VirtoCommerce 2011-2022</Copyright>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>3.18.0</VersionPrefix>
<VersionPrefix>3.19.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
</PropertyGroup>
Expand Down
48 changes: 27 additions & 21 deletions src/VirtoCommerce.Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,30 +462,36 @@ public static Solution Solution
public Target Publish => _ => _
.DependsOn(Compile)
.After(WebPackBuild, Test)
.Executes(() =>
{
Assert.NotNull(WebProject, "Web Project is not found!");
DotNetPublish(settings => settings
.SetProcessWorkingDirectory(WebProject.Directory)
.EnableNoRestore()
.SetOutput(IsModule ? ModuleOutputDirectory / "bin" : ArtifactsDirectory / "publish")
.SetConfiguration(Configuration));
});
.Executes(() => PublishBody(WebProject,
IsModule ? ModuleOutputDirectory / "bin" : ArtifactsDirectory / "publish",
Configuration));

private void PublishBody(Project webProject, string output, Configuration configuration)
{
Assert.NotNull(webProject, "Web Project is not found!");
DotNetPublish(settings => settings
.SetProcessWorkingDirectory(webProject.Directory)
.EnableNoRestore()
.SetOutput(output)
.SetConfiguration(configuration));
}

public Target WebPackBuild => _ => _
.Executes(() =>
.Executes(() => WebPackBuildBody(WebProject));

private void WebPackBuildBody(Project webProject)
{
if (webProject != null && (webProject.Directory / "package.json").FileExists())
{
if (WebProject != null && (WebProject.Directory / "package.json").FileExists())
{
NpmTasks.Npm("ci", WebProject.Directory);
NpmTasks.NpmRun(settings =>
settings.SetProcessWorkingDirectory(WebProject.Directory).SetCommand("webpack:build"));
}
else
{
Log.Information("Nothing to build.");
}
});
NpmTasks.Npm("ci", webProject.Directory);
NpmTasks.NpmRun(settings =>
settings.SetProcessWorkingDirectory(webProject.Directory).SetCommand("webpack:build"));
}
else
{
Log.Information("Nothing to build.");
}
}

public Target Compile => _ => _
.DependsOn(Restore)
Expand Down
127 changes: 127 additions & 0 deletions src/VirtoCommerce.Build/Cloud/Build.SaaS.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Cloud.Client;
using Cloud.Models;
using Microsoft.Build.Evaluation;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Docker;
using Nuke.Common.Tools.DotNet;
using Serilog;
using VirtoCommerce.Platform.Core.Common;
using Project = Nuke.Common.ProjectModel.Project;

namespace VirtoCommerce.Build;

Expand Down Expand Up @@ -95,4 +105,121 @@ private static bool CheckAppServiceStatus(string expected, string actual)

return false;
}

public static string DockerfileUrl { get; set; } = "https://raw.githubusercontent.com/krankenbro/vc-ci-test/master/Dockerfile";
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";

FileSystemTasks.EnsureCleanDirectory(dockerBuildContext);

await HttpTasks.HttpDownloadFileAsync(DockerfileUrl, dockerfilePath);

var modulesSourcePath = Solution?.Path != null
? WebProject.Directory / "modules"
: RootDirectory / "modules";

// 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);

foreach ( var dir in directories)
{
var dirName = Path.GetFileName(dir);
FileSystemTasks.CopyDirectoryRecursively(dir, Path.Combine(platformDirectory, dirName), DirectoryExistsPolicy.Merge, FileExistsPolicy.OverwriteIfNewer);
}

foreach( var file in files)
{
FileSystemTasks.CopyFileToDirectory(file, platformDirectory);
}
}

// 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
{
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);
}
}

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");
});

public Target DeployImage => _ => _
.DependsOn(PrepareDockerContext, BuildAndPush)
.Executes(async () =>
{
var cloudClient = new VirtoCloudClient(CloudUrl, CloudToken);
var env = await cloudClient.GetEnvironment(EnvironmentName, SaaSOrganizationName);

var envHelmParameters = env.Helm.Parameters;

envHelmParameters["platform.image.repository"] = DockerImageName;
envHelmParameters["platform.image.tag"] = DockerImageTag;

await cloudClient.UpdateEnvironmentAsync(env);
});
}
6 changes: 4 additions & 2 deletions src/VirtoCommerce.Build/Docker/Build.Docker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ internal partial class Build
[Parameter("Docker Image Name")] public static string DockerImageName { get; set; }
[Parameter("Docker Image Tag")] public static string DockerImageTag { get; set; }
[Parameter("Dockerfile Path")] public static string DockerfilePath { get; set; }
[Parameter("Docker build context path")] public static string DockerBuildContextPath { get; set; }

private static string DockerImageFullName => string.IsNullOrEmpty(DockerImageTag) ? DockerImageName : DockerImageName.Append($":{DockerImageTag}");

Target DockerLogin => _ => _
.Before(BuildImage, PushImage)
.OnlyWhenDynamic(() => !string.IsNullOrEmpty(DockerUsername) && !string.IsNullOrEmpty(DockerPassword))
.Executes(() =>
{
DockerTasks.DockerLogger = (t, m) => Log.Debug(m);
DockerTasks.DockerLogger = (_, m) => Log.Debug(m);

var settings = new DockerLoginSettings()
.SetServer(DockerRegistryUrl)
Expand All @@ -38,7 +40,7 @@ internal partial class Build
var settings = new DockerBuildSettings()
.SetFile(DockerfilePath)
.SetPull(true)
.SetPath(RootDirectory)
.SetPath(DockerBuildContextPath ?? RootDirectory)
.SetTag(DockerImageFullName);
DockerTasks.DockerBuild(settings);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using Serilog;
using VirtoCommerce.Build.PlatformTools;
using VirtoCommerce.Platform.Core.Modularity;
using AzureBlobs = Azure.Storage.Blobs;

namespace PlatformTools.Azure
Expand All @@ -20,7 +20,7 @@ public AzureBlobModuleInstaller(string token, string destination)
_destination = destination;
}

protected override Task InnerInstall(ModuleSource source)
protected override Task InnerInstall(ModuleSource source, IProgress<ProgressMessage> progress)
{
var azureBlobSource = (AzureBlob)source;
var blobClientOptions = new AzureBlobs.BlobClientOptions();
Expand All @@ -29,7 +29,7 @@ protected override Task InnerInstall(ModuleSource source)
Directory.CreateDirectory(_destination);
foreach (var moduleBlobName in azureBlobSource.Modules.Select(m => m.BlobName))
{
Log.Information($"Installing {moduleBlobName}");
progress.ReportInfo($"Installing {moduleBlobName}");
var zipName = moduleBlobName;
if(!zipName.EndsWith(".zip"))
{
Expand All @@ -42,12 +42,12 @@ protected override Task InnerInstall(ModuleSource source)
{
moduleDestination = moduleDestination.Replace(".zip", "");
}
Log.Information($"Downloading Blob {moduleBlobName}");
progress.ReportInfo($"Downloading Blob {moduleBlobName}");
var blobClient = containerClient.GetBlobClient(moduleBlobName);
blobClient.DownloadTo(zipPath);
Log.Information($"Extracting Blob {moduleBlobName}");
progress.ReportInfo($"Extracting Blob {moduleBlobName}");
ZipFile.ExtractToDirectory(zipPath, moduleDestination, true);
Log.Information($"Successfully installed {moduleBlobName}");
progress.ReportInfo($"Successfully installed {moduleBlobName}");
}
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;
using Serilog;
using VirtoCommerce.Build.PlatformTools;
using VirtoCommerce.Platform.Core.Modularity;

namespace PlatformTools.Azure
{
Expand All @@ -19,31 +19,31 @@ public AzurePipelineArtifactsModuleInstaller(string token, string discoveryPath)
this._discoveryPath = discoveryPath;
}

protected override async Task InnerInstall(ModuleSource source)
protected override async Task InnerInstall(ModuleSource source, IProgress<ProgressMessage> progress)
{
var artifacts = (AzurePipelineArtifacts)source;
var azureClient = new AzureDevClient(artifacts.Organization, _token);
var clientOptions = ExtModuleCatalog.GetOptions(_token, new List<string>() { "https://virtocommerce.com" });
var downloadClient = new AzurePipelineArtifactsClient(clientOptions);
foreach (var module in artifacts.Modules)
{
Log.Information($"Installing {module.Id}");
progress.ReportInfo($"Installing {module.Id}");
var moduleDestination = Path.Join(_discoveryPath, module.Id);
Directory.CreateDirectory(moduleDestination);
var zipName = $"{module.Id}.zip";
var zipDestination = Path.Join(moduleDestination, zipName);
var artifactUrl = await azureClient.GetArtifactUrl(Guid.Parse(artifacts.Project), module.Branch, module.Definition);
Log.Information($"Downloading {artifactUrl}");
progress.ReportInfo($"Downloading {artifactUrl}");
using (var stream = downloadClient.OpenRead(artifactUrl))
{
using (var output = File.OpenWrite(zipDestination))
{
await stream.CopyToAsync(output);
}
}
Log.Information($"Extracting {zipName}");
progress.ReportInfo($"Extracting {zipName}");
ZipFile.ExtractToDirectory(zipDestination, moduleDestination);
Log.Information($"Successfully installed {module.Id}");
progress.ReportInfo($"Successfully installed {module.Id}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Serilog;
using VirtoCommerce.Build.PlatformTools;
using VirtoCommerce.Platform.Core.Modularity;

namespace PlatformTools.Azure
{
Expand All @@ -21,12 +21,12 @@ public AzureUniversalPackagesModuleInstaller(string token, string discoveryPath)
this.discoveryPath = discoveryPath;
}

protected override Task InnerInstall(ModuleSource source)
protected override Task InnerInstall(ModuleSource source, IProgress<ProgressMessage> progress)
{
var artifacts = (AzureUniversalPackages)source;
foreach (var module in artifacts.Modules)
{
Log.Information($"Installing {module.Id}");
progress.ReportInfo($"Installing {module.Id}");
var moduleDestination = Path.Join(discoveryPath, module.Id);
Directory.CreateDirectory(moduleDestination);
FileSystemTasks.EnsureCleanDirectory(moduleDestination);
Expand All @@ -49,21 +49,16 @@ protected override Task InnerInstall(ModuleSource source)
var zipPath = Directory.GetFiles(moduleDestination).FirstOrDefault(p => p.EndsWith(".zip"));
if (zipPath == null)
{
Assert.Fail($"Can't download {module.Id} - {module.Version}");
progress.ReportError($"Can't download {module.Id} - {module.Version}");
}

Log.Information($"Extracting {zipPath}");
progress.ReportInfo($"Extracting {zipPath}");
ZipFile.ExtractToDirectory(zipPath, moduleDestination);
Log.Information($"Successfully installed {module.Id}");
progress.ReportInfo($"Successfully installed {module.Id}");
}

return Task.CompletedTask;
}

public override Task Install(ModuleSource source)
{
return InnerInstall((AzureUniversalPackages)source);
}
}
}

Loading

0 comments on commit bf7bb06

Please sign in to comment.