Skip to content

Commit

Permalink
新增部署版本时,支持指定发布模式,局部发布还是完整发布
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jul 28, 2024
1 parent d25440a commit 32e07ca
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 6 deletions.
1 change: 1 addition & 0 deletions Stardust.Data/Deployment/Model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<Column Name="Enable" DataType="Boolean" Description="启用" />
<Column Name="Url" DataType="String" ItemType="file" Length="500" Description="资源地址。一般打包为Zip包,StarAgent下载后解压缩覆盖" />
<Column Name="Overwrite" DataType="String" Length="100" Description="覆盖文件。需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝" />
<Column Name="Mode" DataType="Int32" Description="发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件" Type="Stardust.Models.DeployModes" />
<Column Name="Size" DataType="Int64" ItemType="GMK" Description="文件大小" />
<Column Name="Hash" DataType="String" Description="文件哈希。MD5散列,避免下载的文件有缺失" />
<Column Name="Runtime" DataType="Int32" Description="运行时。RID是运行时标识符,用于标识应用程序运行所在的目标平台。如win-x64/linux-arm" Type="Stardust.Models.RuntimeIdentifier" />
Expand Down
11 changes: 11 additions & 0 deletions Stardust.Data/Deployment/Stardust.htm
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,17 @@ <h3>部署版本(AppDeployVersion)</h3>
<td>需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝</td>
</tr>

<tr>
<td>Mode</td>
<td>发布模式</td>
<td>Int32</td>
<td></td>
<td></td>
<td></td>
<td>N</td>
<td>1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件</td>
</tr>

<tr>
<td>Size</td>
<td>文件大小</td>
Expand Down
16 changes: 16 additions & 0 deletions Stardust.Data/Deployment/部署版本.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/// <summary>发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件</summary>
[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;
/// <summary>文件大小</summary>
[DisplayName("文件大小")]
Expand Down Expand Up @@ -216,6 +224,7 @@ public override Object this[String name]
"Enable" => _Enable,
"Url" => _Url,
"Overwrite" => _Overwrite,
"Mode" => _Mode,
"Size" => _Size,
"Hash" => _Hash,
"Runtime" => _Runtime,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -312,6 +322,9 @@ public partial class _
/// <summary>覆盖文件。需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝</summary>
public static readonly Field Overwrite = FindByName("Overwrite");

/// <summary>发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件</summary>
public static readonly Field Mode = FindByName("Mode");

/// <summary>文件大小</summary>
public static readonly Field Size = FindByName("Size");

Expand Down Expand Up @@ -381,6 +394,9 @@ public partial class __
/// <summary>覆盖文件。需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝</summary>
public const String Overwrite = "Overwrite";

/// <summary>发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件</summary>
public const String Mode = "Mode";

/// <summary>文件大小</summary>
public const String Size = "Size";

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions Stardust.Server/Controllers/DeployController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public DeployInfo[] GetAll()
Url = ver?.Url,
Hash = ver?.Hash,
Overwrite = ver?.Overwrite,
Mode = ver.Mode,

Service = item.ToService(app),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AppDeployController : EntityController<AppDeploy>
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;
Expand Down
33 changes: 30 additions & 3 deletions Stardust/Deployment/ZipDeploy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Xml.Serialization;
using NewLife;
using NewLife.Log;
using Stardust.Models;

namespace Stardust.Deployment;

Expand Down Expand Up @@ -37,6 +38,9 @@ public class ZipDeploy
/// <summary>覆盖文件。需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝</summary>
public String? Overwrite { get; set; }

/// <summary>发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件</summary>
public DeployModes Mode { get; set; }

/// <summary>进程</summary>
public Process? Process { get; private set; }

Expand Down Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions Stardust/Managers/ServiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions Stardust/Models/DeployInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class DeployInfo
/// <summary>覆盖文件。需要拷贝覆盖已存在的文件或子目录,支持*模糊匹配,多文件分号隔开。如果目标文件不存在,配置文件等自动拷贝</summary>
public String? Overwrite { get; set; }

/// <summary>发布模式。1部分包,仅覆盖;2标准包,清空可执行文件再覆盖;3完整包,清空所有文件</summary>
public DeployModes Mode { get; set; }

/// <summary>应用服务</summary>
public ServiceInfo? Service { get; set; }
}
22 changes: 22 additions & 0 deletions Stardust/Models/DeployModes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.ComponentModel;

namespace Stardust.Models;

/// <summary>发布模式</summary>
public enum DeployModes
{
///// <summary>默认</summary>
//Default = 0,

/// <summary>部分包。覆盖已有文件,保留其它文件</summary>
[Description("部分包")]
Partial = 1,

/// <summary>标准包。清空所有可执行文件,保留配置和数据等其它文件</summary>
[Description("标准包")]
Standard = 2,

/// <summary>完整包。清空所有文件</summary>
[Description("完整包")]
Full = 3,
}

0 comments on commit 32e07ca

Please sign in to comment.