diff --git a/Stardust.Data/Deployment/Model.xml b/Stardust.Data/Deployment/Model.xml index 10625243..6dee080e 100644 --- a/Stardust.Data/Deployment/Model.xml +++ b/Stardust.Data/Deployment/Model.xml @@ -123,6 +123,7 @@ + diff --git a/Stardust.Data/Deployment/Stardust.htm b/Stardust.Data/Deployment/Stardust.htm index 4af4a53e..b829760c 100644 --- a/Stardust.Data/Deployment/Stardust.htm +++ b/Stardust.Data/Deployment/Stardust.htm @@ -809,6 +809,17 @@

部署版本(AppDeployVersion)

需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝 + + Mode + 发布模式 + Int32 + + + + N + 1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件 + + Size 文件大小 diff --git "a/Stardust.Data/Deployment/\351\203\250\347\275\262\347\211\210\346\234\254.cs" "b/Stardust.Data/Deployment/\351\203\250\347\275\262\347\211\210\346\234\254.cs" index 6d5684e9..4b07c273 100644 --- "a/Stardust.Data/Deployment/\351\203\250\347\275\262\347\211\210\346\234\254.cs" +++ "b/Stardust.Data/Deployment/\351\203\250\347\275\262\347\211\210\346\234\254.cs" @@ -70,6 +70,14 @@ public partial class AppDeployVersion [BindColumn("Overwrite", "覆盖文件。需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝", "")] public String Overwrite { get => _Overwrite; set { if (OnPropertyChanging("Overwrite", value)) { _Overwrite = value; OnPropertyChanged("Overwrite"); } } } + private Stardust.Models.DeployModes _Mode; + /// 发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件 + [DisplayName("发布模式")] + [Description("发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件")] + [DataObjectField(false, false, false, 0)] + [BindColumn("Mode", "发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件", "")] + public Stardust.Models.DeployModes Mode { get => _Mode; set { if (OnPropertyChanging("Mode", value)) { _Mode = value; OnPropertyChanged("Mode"); } } } + private Int64 _Size; /// 文件大小 [DisplayName("文件大小")] @@ -216,6 +224,7 @@ public override Object this[String name] "Enable" => _Enable, "Url" => _Url, "Overwrite" => _Overwrite, + "Mode" => _Mode, "Size" => _Size, "Hash" => _Hash, "Runtime" => _Runtime, @@ -243,6 +252,7 @@ public override Object this[String name] case "Enable": _Enable = value.ToBoolean(); break; case "Url": _Url = Convert.ToString(value); break; case "Overwrite": _Overwrite = Convert.ToString(value); break; + case "Mode": _Mode = (Stardust.Models.DeployModes)value.ToInt(); break; case "Size": _Size = value.ToLong(); break; case "Hash": _Hash = Convert.ToString(value); break; case "Runtime": _Runtime = (Stardust.Models.RuntimeIdentifier)value.ToInt(); break; @@ -312,6 +322,9 @@ public partial class _ /// 覆盖文件。需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝 public static readonly Field Overwrite = FindByName("Overwrite"); + /// 发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件 + public static readonly Field Mode = FindByName("Mode"); + /// 文件大小 public static readonly Field Size = FindByName("Size"); @@ -381,6 +394,9 @@ public partial class __ /// 覆盖文件。需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝 public const String Overwrite = "Overwrite"; + /// 发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件 + public const String Mode = "Mode"; + /// 文件大小 public const String Size = "Size"; diff --git a/Stardust.Data/make.bat b/Stardust.Data/xcodetool.bat similarity index 100% rename from Stardust.Data/make.bat rename to Stardust.Data/xcodetool.bat diff --git a/Stardust.Server/Controllers/DeployController.cs b/Stardust.Server/Controllers/DeployController.cs index 6e98ca01..5250c1ac 100644 --- a/Stardust.Server/Controllers/DeployController.cs +++ b/Stardust.Server/Controllers/DeployController.cs @@ -72,6 +72,7 @@ public DeployInfo[] GetAll() Url = ver?.Url, Hash = ver?.Hash, Overwrite = ver?.Overwrite, + Mode = ver.Mode, Service = item.ToService(app), }; diff --git a/Stardust.Web/Areas/Deployment/Controllers/AppDeployController.cs b/Stardust.Web/Areas/Deployment/Controllers/AppDeployController.cs index beec80c6..0f9db16a 100644 --- a/Stardust.Web/Areas/Deployment/Controllers/AppDeployController.cs +++ b/Stardust.Web/Areas/Deployment/Controllers/AppDeployController.cs @@ -19,7 +19,7 @@ public class AppDeployController : EntityController static AppDeployController() { ListFields.RemoveCreateField(); - ListFields.RemoveField("AppId", "Repository", "Branch", "ProjectPath", "PackageFilters", "WorkingDirectory", "UserName", "MaxMemory", "Mode", "Remark"); + ListFields.RemoveField("AppId", "MultiVersion", "Repository", "Branch", "ProjectPath", "PackageFilters", "WorkingDirectory", "UserName", "Environments", "MaxMemory", "Mode", "Remark"); AddFormFields.RemoveCreateField(); LogOnChange = true; diff --git a/Stardust/Deployment/ZipDeploy.cs b/Stardust/Deployment/ZipDeploy.cs index 2df06485..d3755a2e 100644 --- a/Stardust/Deployment/ZipDeploy.cs +++ b/Stardust/Deployment/ZipDeploy.cs @@ -2,6 +2,7 @@ using System.Xml.Serialization; using NewLife; using NewLife.Log; +using Stardust.Models; namespace Stardust.Deployment; @@ -37,6 +38,9 @@ public class ZipDeploy /// 覆盖文件。需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝 public String? Overwrite { get; set; } + /// 发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件 + public DeployModes Mode { get; set; } + /// 进程 public Process? Process { get; private set; } @@ -391,19 +395,42 @@ public virtual void Extract(String shadow, CopyModes exefile, CopyModes configfi { if (FileName.IsNullOrEmpty()) throw new ArgumentNullException(nameof(FileName)); - using var span = Tracer?.NewSpan("ZipDeploy-Extract", new { shadow, WorkingDirectory, Overwrite }); + using var span = Tracer?.NewSpan("ZipDeploy-Extract", new { shadow, WorkingDirectory, Overwrite, Mode }); var fi = WorkingDirectory.CombinePath(FileName).AsFile(); var rundir = fi.DirectoryName!; WriteLog("解压缩 {0} 到 {1}", FileName, shadow); + var sdi = shadow.AsDirectory(); + span?.AppendTag($"sdi={sdi.FullName} rundir={rundir}"); + + // 前置清理 + switch (Mode) + { + case DeployModes.Partial: + break; + case DeployModes.Standard: + WriteLog("清空影子目录中的可执行文件"); + foreach (var item in sdi.GetFiles()) + { + if (IsExe(item.Extension)) + item.Delete(); + } + break; + case DeployModes.Full: + WriteLog("清空影子目录中的所有文件"); + sdi.Delete(true); + shadow.EnsureDirectory(false); + break; + default: + break; + } + fi.Extract(shadow, true); var ovs = Overwrite?.Split(';'); // 复制配置文件和数据文件到运行目录 - var sdi = shadow.AsDirectory(); - span?.AppendTag($"sdi={sdi.FullName} rundir={rundir}"); if (!sdi.FullName.EnsureEnd("\\").EqualIgnoreCase(rundir.EnsureEnd("\\"))) { if (exefile == CopyModes.ClearBeforeCopy) diff --git a/Stardust/Managers/ServiceController.cs b/Stardust/Managers/ServiceController.cs index fad2c91e..20df0d59 100644 --- a/Stardust/Managers/ServiceController.cs +++ b/Stardust/Managers/ServiceController.cs @@ -225,12 +225,18 @@ public Boolean Start() Name = Name, FileName = file, WorkingDirectory = workDir, - Overwrite = DeployInfo?.Overwrite, Tracer = Tracer, Log = new ActionLog(WriteLog), }; + var di = DeployInfo; + if (di != null) + { + deploy.Overwrite = di.Overwrite; + deploy.Mode = di.Mode; + } + //var args = service.Arguments?.Trim(); if (!args.IsNullOrEmpty() && !deploy.Parse(args.Split(" "))) return null; @@ -271,12 +277,18 @@ public Boolean Start() WorkingDirectory = workDir, UserName = service.UserName, Environments = service.Environments, - Overwrite = DeployInfo?.Overwrite, Tracer = Tracer, Log = new ActionLog(WriteLog), }; + var di = DeployInfo; + if (di != null) + { + deploy.Overwrite = di.Overwrite; + deploy.Mode = di.Mode; + } + // 如果出现超过一次的重启,则打开调试模式,截取控制台输出到日志 if (_error > 1) deploy.Debug = true; diff --git a/Stardust/Models/DeployInfo.cs b/Stardust/Models/DeployInfo.cs index 87e89b3b..6f89ca05 100644 --- a/Stardust/Models/DeployInfo.cs +++ b/Stardust/Models/DeployInfo.cs @@ -18,6 +18,9 @@ public class DeployInfo /// 覆盖文件。需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝 public String? Overwrite { get; set; } + /// 发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件 + public DeployModes Mode { get; set; } + /// 应用服务 public ServiceInfo? Service { get; set; } } \ No newline at end of file diff --git a/Stardust/Models/DeployModes.cs b/Stardust/Models/DeployModes.cs new file mode 100644 index 00000000..61300a1a --- /dev/null +++ b/Stardust/Models/DeployModes.cs @@ -0,0 +1,22 @@ +using System.ComponentModel; + +namespace Stardust.Models; + +/// 发布模式 +public enum DeployModes +{ + ///// 默认 + //Default = 0, + + /// 部分包。覆盖已有文件,保留其它文件 + [Description("部分包")] + Partial = 1, + + /// 标准包。清空所有可执行文件,保留配置和数据等其它文件 + [Description("标准包")] + Standard = 2, + + /// 完整包。清空所有文件 + [Description("完整包")] + Full = 3, +} \ No newline at end of file