diff --git a/src/VirtoCommerce.Build/Build.cs b/src/VirtoCommerce.Build/Build.cs index a1b30c4..8e55bcb 100644 --- a/src/VirtoCommerce.Build/Build.cs +++ b/src/VirtoCommerce.Build/Build.cs @@ -275,12 +275,12 @@ public static Solution Solution var testProjects = Solution.GetProjects("*.Test|*.Tests|*.Testing"); var outPath = RootDirectory / ".tmp"; - foreach (var testProject in testProjects) + foreach (var testProjectPath in testProjects.Select(p=> p.Path).ToArray()) { - DotNet($"add \"{testProject.Path}\" package coverlet.collector"); + DotNet($"add \"{testProjectPath}\" package coverlet.collector"); var testSetting = new DotNetTestSettings() - .SetProjectFile(testProject.Path) + .SetProjectFile(testProjectPath) .SetConfiguration(Configuration) .SetFilter(TestsFilter) .SetNoBuild(true) @@ -1172,7 +1172,14 @@ private void CompressExecuteMethod() keepFiles = TextTasks.ReadAllLines(ModuleKeepFile).ToArray(); } - ArtifactPacker.CompressModule(ModuleOutputDirectory, ZipFilePath, ModuleManifest.Id, ModuleManifestFile, WebProject.Directory, ignoredFiles, keepFiles, _moduleContentFolders); + ArtifactPacker.CompressModule(options => options.WithSourceDirectory(ModuleOutputDirectory) + .WithOutputZipPath(ZipFilePath) + .WithModuleId(ModuleManifest.Id) + .WithModuleManifestPath(ModuleManifestFile) + .WithWebProjectDirectory(WebProject.Directory) + .WithIgnoreList(ignoredFiles) + .WithKeepList(keepFiles) + .WithModuleContentFolders(_moduleContentFolders)); } else { diff --git a/src/VirtoCommerce.Build/Cloud/Models/ArgoAppCustomAppSection.cs b/src/VirtoCommerce.Build/Cloud/Models/ArgoAppCustomAppSection.cs deleted file mode 100644 index 1d3a1ce..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/ArgoAppCustomAppSection.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System.Collections.Generic; - -namespace Cloud.Models -{ - public class ArgoAppCustomAppSection - { - private string _app; - - public ArgoAppCustomAppSection() - { - PlatformPath = new List(); - StorefrontPath = new List(); - ServicePath = new List(); - } - - public void SetApp(string name) - { - _app = name; - } - - private string GetPrefix() - { - return $"custom.{_app}."; - } - - public string Enabled { get; set; } - public string Type { get; set; } - public string AttachedTo { get; set; } - public string ProbePath { get; set; } - public string Replicas { get; set; } - public string Hostname { get; set; } - public string Port { get; set; } - public string Name { get; set; } - public string ImageRepository { get; set; } - public string ImageTag { get; set; } - public string IngressPath { get; set; } - public string RequestsMemory { get; set; } - public string RequestsCPU { get; set; } - public string LimitsMemory { get; set; } - public string LimitsCPU { get; set; } - public List PlatformPath { get; set; } - public List StorefrontPath { get; set; } - public List ServicePath { get; set; } - - public List GetParameters(string customAppName) - { - SetApp(customAppName); - var parameters = new List() - { - new HelmParameter(name: $"{GetPrefix()}enabled", value: Enabled), - new HelmParameter(name: $"{GetPrefix()}type", value: Type), - new HelmParameter(name: $"{GetPrefix()}attached_to", value: AttachedTo), - new HelmParameter(name: $"{GetPrefix()}probe_path", value: ProbePath), - new HelmParameter(name: $"{GetPrefix()}replicas", value: Replicas), - new HelmParameter(name: $"{GetPrefix()}hostname", value: Hostname), - new HelmParameter(name: $"{GetPrefix()}port", value: Port), - new HelmParameter(name: $"{GetPrefix()}name", value: Name), - new HelmParameter(name: $"{GetPrefix()}image.repository", value: ImageRepository), - new HelmParameter(name: $"{GetPrefix()}image.tag", value: ImageTag), - new HelmParameter(name: $"{GetPrefix()}ingress_path", value: IngressPath), - new HelmParameter(name: $"{GetPrefix()}resources.requests.memory", value: RequestsMemory), - new HelmParameter(name: $"{GetPrefix()}resources.requests.cpu", value: RequestsCPU), - new HelmParameter(name: $"{GetPrefix()}resources.limits.memory", value: LimitsMemory), - new HelmParameter(name: $"{GetPrefix()}resources.limits.cpu", value: LimitsCPU) - }; - - parameters.AddRange(ConvertToPathParameters(PlatformPath, $"{GetPrefix()}paths.platform")); - parameters.AddRange(ConvertToPathParameters(StorefrontPath, $"{GetPrefix()}paths.storefront")); - parameters.AddRange(ConvertToPathParameters(ServicePath, $"{GetPrefix()}paths.service")); - - return parameters; - } - - private static List ConvertToPathParameters(List parameters, string name) - { - var result = new List(); - for (var i = 0; i < parameters.Count; i++) - { - result.Add(new HelmParameter(name: $"{name}[{i}]", value: parameters[i])); - } - return result; - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/ArgoAppEnvironmentVariable.cs b/src/VirtoCommerce.Build/Cloud/Models/ArgoAppEnvironmentVariable.cs deleted file mode 100644 index 24db234..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/ArgoAppEnvironmentVariable.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Cloud.Models -{ - public class ArgoAppEnvironmentVariable - { - public string Value { get; set; } - public string SecretValue { get; set; } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/ArgoAppIngressSection.cs b/src/VirtoCommerce.Build/Cloud/Models/ArgoAppIngressSection.cs deleted file mode 100644 index 213faf4..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/ArgoAppIngressSection.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models -{ - public class ArgoAppIngressSection - { - public string Config { get; set; } - public string Hostname { get; set; } - public string StorefrontHostname { get; set; } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/ArgoAppPlatformSection.cs b/src/VirtoCommerce.Build/Cloud/Models/ArgoAppPlatformSection.cs deleted file mode 100644 index 86d82f6..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/ArgoAppPlatformSection.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; - -namespace Cloud.Models -{ - public class ArgoAppPlatformSection - { - public string ImageRepository { get; set; } - public string ImageTag { get; set; } - public string Tier { get; set; } - public Dictionary Config { get; set; } - public Dictionary SecretConfig { get; set; } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/ArgoAppStorefrontSection.cs b/src/VirtoCommerce.Build/Cloud/Models/ArgoAppStorefrontSection.cs deleted file mode 100644 index 05d6c66..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/ArgoAppStorefrontSection.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace Cloud.Models -{ - public class ArgoAppStorefrontSection - { - public string ImageRepository { get; set; } - public string ImageTag { get; set; } - public string ThemeUrl { get; set; } - public string ThemeName { get; set; } - public string Ingress { get; set; } - public Dictionary Config { get; set; } - public Dictionary SecretConfig { get; set; } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/ArgoApplication.cs b/src/VirtoCommerce.Build/Cloud/Models/ArgoApplication.cs deleted file mode 100644 index 2511489..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/ArgoApplication.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Collections.Generic; - -namespace Cloud.Models -{ - public class ArgoApplication - { - public string Name { get; set; } - public ArgoAppPlatformSection Platform { get; set; } - public ArgoAppStorefrontSection Storefront { get; set; } - public ArgoAppIngressSection Ingress { get; set; } - public Dictionary CustomApps { get; set; } - public List ProtectedParameters { get; set; } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Platform/Config.cs b/src/VirtoCommerce.Build/Cloud/Models/Platform/Config.cs deleted file mode 100644 index 411ef6d..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Platform/Config.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Platform -{ - public class Config : HelmParameter - { - public Config(string name, string value) : base(false, $"platform.config.{name}", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Platform/ImageRepository.cs b/src/VirtoCommerce.Build/Cloud/Models/Platform/ImageRepository.cs deleted file mode 100644 index 60a19c6..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Platform/ImageRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Platform -{ - public class ImageRepository : HelmParameter - { - public ImageRepository(string value) : base(false, "platform.image.repository", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Platform/ImageTag.cs b/src/VirtoCommerce.Build/Cloud/Models/Platform/ImageTag.cs deleted file mode 100644 index a176835..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Platform/ImageTag.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Platform -{ - public class ImageTag : HelmParameter - { - public ImageTag(string value) : base(false, "platform.image.tag", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Platform/IngressConfig.cs b/src/VirtoCommerce.Build/Cloud/Models/Platform/IngressConfig.cs deleted file mode 100644 index db8d682..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Platform/IngressConfig.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Platform -{ - public class IngressConfig : HelmParameter - { - public IngressConfig(string value) : base(false, $"ingress.config", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Platform/IngressHostname.cs b/src/VirtoCommerce.Build/Cloud/Models/Platform/IngressHostname.cs deleted file mode 100644 index 70e9953..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Platform/IngressHostname.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Platform -{ - public class IngressHostname : HelmParameter - { - public IngressHostname(string value) : base(false, $"ingress.hostname", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Platform/Secret.cs b/src/VirtoCommerce.Build/Cloud/Models/Platform/Secret.cs deleted file mode 100644 index 3df37d6..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Platform/Secret.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Platform -{ - public class Secret : HelmParameter - { - public Secret(string name) : base(false, $"platform.secrets.{name}", name) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Platform/SecretConfig.cs b/src/VirtoCommerce.Build/Cloud/Models/Platform/SecretConfig.cs deleted file mode 100644 index 4b7ab4f..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Platform/SecretConfig.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Platform -{ - public class SecretConfig : HelmParameter - { - public SecretConfig(string name, string value) : base(false, $"platform.secret_config.{name}", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Platform/Tier.cs b/src/VirtoCommerce.Build/Cloud/Models/Platform/Tier.cs deleted file mode 100644 index c3169b6..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Platform/Tier.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Platform -{ - public class Tier : HelmParameter - { - public Tier(string value) : base(false, "platform.tier", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Storefront/Config.cs b/src/VirtoCommerce.Build/Cloud/Models/Storefront/Config.cs deleted file mode 100644 index 3be09f0..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Storefront/Config.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Storefront -{ - public class Config : HelmParameter - { - public Config(string name, string value) : base(false, $"storefront.config.{name}", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Storefront/ImageRepository.cs b/src/VirtoCommerce.Build/Cloud/Models/Storefront/ImageRepository.cs deleted file mode 100644 index 323129f..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Storefront/ImageRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Storefront -{ - public class ImageRepository : HelmParameter - { - public ImageRepository(string value) : base(false, "storefront.image.repository", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Storefront/ImageTag.cs b/src/VirtoCommerce.Build/Cloud/Models/Storefront/ImageTag.cs deleted file mode 100644 index 6bac1bc..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Storefront/ImageTag.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Storefront -{ - public class ImageTag : HelmParameter - { - public ImageTag(string value) : base(false, "storefront.image.tag", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Storefront/IngressHostname.cs b/src/VirtoCommerce.Build/Cloud/Models/Storefront/IngressHostname.cs deleted file mode 100644 index 998c60c..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Storefront/IngressHostname.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Storefront -{ - public class IngressHostname : HelmParameter - { - public IngressHostname(string value) : base(false, $"ingress.storefront_hostname", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Storefront/SecretConfig.cs b/src/VirtoCommerce.Build/Cloud/Models/Storefront/SecretConfig.cs deleted file mode 100644 index 9252884..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Storefront/SecretConfig.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Storefront -{ - public class SecretConfig : HelmParameter - { - public SecretConfig(string name, string value) : base(false, $"storefront.secret_config.{name}", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Storefront/ThemeName.cs b/src/VirtoCommerce.Build/Cloud/Models/Storefront/ThemeName.cs deleted file mode 100644 index 272617f..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Storefront/ThemeName.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Storefront -{ - public class ThemeName : HelmParameter - { - public ThemeName(string value) : base(false, $"theme.name", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/Cloud/Models/Storefront/ThemeUrl.cs b/src/VirtoCommerce.Build/Cloud/Models/Storefront/ThemeUrl.cs deleted file mode 100644 index b04c3bd..0000000 --- a/src/VirtoCommerce.Build/Cloud/Models/Storefront/ThemeUrl.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cloud.Models.Storefront -{ - public class ThemeUrl : HelmParameter - { - public ThemeUrl(string value) : base(false, $"theme.url", value) - { - } - } -} diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsClient.cs b/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsClient.cs index d1c9de4..6c3a10f 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsClient.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsClient.cs @@ -34,7 +34,7 @@ public Stream OpenRead(Uri address) } finally { - ((IDisposable)client)?.Dispose(); + client?.Dispose(); } } } diff --git a/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs b/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs index da5efdd..8d6ab25 100644 --- a/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs +++ b/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs @@ -15,34 +15,38 @@ public static void CompressPlatform(string sourceDirectory, string outputZipPath CompressionTasks.CompressZip(sourceDirectory, outputZipPath); } - public static void CompressModule(string sourceDirectory, string outputZipPath, string moduleId, string moduleManifestPath, string webProjectDirectory, IEnumerable ignoreList, IEnumerable keepList, string[] moduleContentFolders) + public static void CompressModule(Action optionsBuilderAction) { - FileSystemTasks.CopyFileToDirectory(moduleManifestPath, sourceDirectory, + var optionsBuilder = new ModuleCompressionOptionsBuilder(); + optionsBuilderAction(optionsBuilder); + var options = optionsBuilder.Build(); + + FileSystemTasks.CopyFileToDirectory(options.ModuleManifestPath, options.SourceDirectory, FileExistsPolicy.Overwrite); //Exclude all ignored files and *module files not related to compressed module var ignoreModuleFilesRegex = new Regex(@".+Module\..*", RegexOptions.IgnoreCase); var includeModuleFilesRegex = - new Regex(@$".*{moduleId}(Module)?\..*", RegexOptions.IgnoreCase); + new Regex(@$".*{options.ModuleId}(Module)?\..*", RegexOptions.IgnoreCase); - foreach (var folderName in moduleContentFolders) + foreach (var folderName in options.ModuleContentFolders) { - var sourcePath = Path.Combine(webProjectDirectory, folderName); + var sourcePath = Path.Combine(options.WebProjectDirectory, folderName); if (Directory.Exists(sourcePath)) { - FileSystemTasks.CopyDirectoryRecursively(sourcePath, Path.Combine(sourceDirectory, folderName), + FileSystemTasks.CopyDirectoryRecursively(sourcePath, Path.Combine(options.SourceDirectory, folderName), DirectoryExistsPolicy.Merge, FileExistsPolicy.Overwrite); } } bool FilesFilter(FileInfo x) => - (!SkipFileByList(x.Name, ignoreList) && - !SkipFileByRegex(x.Name, ignoreModuleFilesRegex)) || KeepFileByList(x.Name, keepList) || + (!SkipFileByList(x.Name, options.IgnoreList) && + !SkipFileByRegex(x.Name, ignoreModuleFilesRegex)) || KeepFileByList(x.Name, options.KeepList) || KeepFileByRegex(x.Name, includeModuleFilesRegex); - FileSystemTasks.DeleteFile(outputZipPath); - CompressionTasks.CompressZip(sourceDirectory, outputZipPath, FilesFilter); + FileSystemTasks.DeleteFile(options.OutputZipPath); + CompressionTasks.CompressZip(options.SourceDirectory, options.OutputZipPath, FilesFilter); } diff --git a/src/VirtoCommerce.Build/Utils/ModuleCompressionOptions.cs b/src/VirtoCommerce.Build/Utils/ModuleCompressionOptions.cs new file mode 100644 index 0000000..0e56f79 --- /dev/null +++ b/src/VirtoCommerce.Build/Utils/ModuleCompressionOptions.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Utils +{ + public class ModuleCompressionOptions + { + public string SourceDirectory { get; set; } + public string OutputZipPath { get; set; } + public string ModuleId { get; set; } + public string ModuleManifestPath { get; set; } + public string WebProjectDirectory { get; set; } + public IEnumerable IgnoreList { get; set; } = new List(); + public IEnumerable KeepList { get; set; } = new List(); + public IEnumerable ModuleContentFolders { get; set; } = new List(); + } + + public class ModuleCompressionOptionsBuilder + { + private readonly ModuleCompressionOptions options = new ModuleCompressionOptions(); + + public ModuleCompressionOptionsBuilder WithSourceDirectory(string sourceDirectory) + { + options.SourceDirectory = sourceDirectory; + return this; + } + + public ModuleCompressionOptionsBuilder WithOutputZipPath(string outputZipPath) + { + options.OutputZipPath = outputZipPath; + return this; + } + + public ModuleCompressionOptionsBuilder WithModuleId(string moduleId) + { + options.ModuleId = moduleId; + return this; + } + + public ModuleCompressionOptionsBuilder WithModuleManifestPath(string moduleManifestPath) + { + options.ModuleManifestPath = moduleManifestPath; + return this; + } + + public ModuleCompressionOptionsBuilder WithWebProjectDirectory(string webProjectDirectory) + { + options.WebProjectDirectory = webProjectDirectory; + return this; + } + + public ModuleCompressionOptionsBuilder WithIgnoreList(IEnumerable ignoreList) + { + options.IgnoreList = ignoreList; + return this; + } + + public ModuleCompressionOptionsBuilder WithKeepList(IEnumerable keepList) + { + options.KeepList = keepList; + return this; + } + + public ModuleCompressionOptionsBuilder WithModuleContentFolders(IEnumerable moduleContentFolders) + { + options.ModuleContentFolders = moduleContentFolders; + return this; + } + + public ModuleCompressionOptions Build() + { + return options; + } + } +}