Skip to content

Commit

Permalink
[feat]支持多运行时版本部署,例如上传win-x64/osx-arm64/linux-musl-arm等不同包,各节点根据需要拉取满足…
Browse files Browse the repository at this point in the history
…自己系统类型和芯片架构的包。#57
  • Loading branch information
nnhy committed May 23, 2024
1 parent cccf118 commit 8a26ef9
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 4 deletions.
1 change: 1 addition & 0 deletions Stardust.Data/Deployment/Model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Column Name="Enable" DataType="Boolean" Description="启用" />
<Column Name="Nodes" DataType="Int32" Description="节点。该应用部署集所拥有的节点数" />
<Column Name="Version" DataType="String" Description="版本。应用正在使用的版本号" />
<Column Name="MultiVersion" DataType="Boolean" Description="多版本。支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本" />
<Column Name="AutoPublish" DataType="Boolean" Description="自动发布。应用版本后自动发布到启用节点,加快发布速度" />
<Column Name="PackageName" DataType="String" Description="包名。用于判断上传包名是否正确,避免错误上传其它应用包,支持*模糊匹配" />
<Column Name="Repository" DataType="String" ItemType="url" Length="200" Description="代码库。下载代码的位置" Category="编译参数" />
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 @@ -137,6 +137,17 @@ <h3>应用部署(AppDeploy)</h3>
<td>应用正在使用的版本号</td>
</tr>

<tr>
<td>MultiVersion</td>
<td>多版本</td>
<td>Boolean</td>
<td></td>
<td></td>
<td></td>
<td>N</td>
<td>支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本</td>
</tr>

<tr>
<td>AutoPublish</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 @@ -87,6 +87,14 @@ public partial class AppDeploy
[BindColumn("Version", "版本。应用正在使用的版本号", "")]
public String Version { get => _Version; set { if (OnPropertyChanging("Version", value)) { _Version = value; OnPropertyChanged("Version"); } } }

private Boolean _MultiVersion;
/// <summary>多版本。支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本</summary>
[DisplayName("多版本")]
[Description("多版本。支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本")]
[DataObjectField(false, false, false, 0)]
[BindColumn("MultiVersion", "多版本。支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本", "")]
public Boolean MultiVersion { get => _MultiVersion; set { if (OnPropertyChanging("MultiVersion", value)) { _MultiVersion = value; OnPropertyChanged("MultiVersion"); } } }

private Boolean _AutoPublish;
/// <summary>自动发布。应用版本后自动发布到启用节点,加快发布速度</summary>
[DisplayName("自动发布")]
Expand Down Expand Up @@ -282,6 +290,7 @@ public override Object this[String name]
"Enable" => _Enable,
"Nodes" => _Nodes,
"Version" => _Version,
"MultiVersion" => _MultiVersion,
"AutoPublish" => _AutoPublish,
"PackageName" => _PackageName,
"Repository" => _Repository,
Expand Down Expand Up @@ -316,6 +325,7 @@ public override Object this[String name]
case "Enable": _Enable = value.ToBoolean(); break;
case "Nodes": _Nodes = value.ToInt(); break;
case "Version": _Version = Convert.ToString(value); break;
case "MultiVersion": _MultiVersion = value.ToBoolean(); break;
case "AutoPublish": _AutoPublish = value.ToBoolean(); break;
case "PackageName": _PackageName = Convert.ToString(value); break;
case "Repository": _Repository = Convert.ToString(value); break;
Expand Down Expand Up @@ -381,6 +391,9 @@ public partial class _
/// <summary>版本。应用正在使用的版本号</summary>
public static readonly Field Version = FindByName("Version");

/// <summary>多版本。支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本</summary>
public static readonly Field MultiVersion = FindByName("MultiVersion");

/// <summary>自动发布。应用版本后自动发布到启用节点,加快发布速度</summary>
public static readonly Field AutoPublish = FindByName("AutoPublish");

Expand Down Expand Up @@ -471,6 +484,9 @@ public partial class __
/// <summary>版本。应用正在使用的版本号</summary>
public const String Version = "Version";

/// <summary>多版本。支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本</summary>
public const String MultiVersion = "MultiVersion";

/// <summary>自动发布。应用版本后自动发布到启用节点,加快发布速度</summary>
public const String AutoPublish = "AutoPublish";

Expand Down
4 changes: 3 additions & 1 deletion Stardust.Server/Controllers/DeployController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public DeployInfo[] GetAll()
app = AppDeploy.FindByKey(app.Id);
if (app == null || !app.Enable) continue;

var ver = AppDeployVersion.FindByDeployIdAndVersion(app.Id, app.Version);
//var ver = AppDeployVersion.FindByDeployIdAndVersion(app.Id, app.Version);
var ver = _deployService.GetDeployVersion(app, _node);
if(ver == null) continue;

var inf = new DeployInfo
{
Expand Down
18 changes: 17 additions & 1 deletion Stardust.Server/Services/DeployService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NewLife;
using System.Xml.Linq;
using Stardust.Data;
using Stardust.Data.Deployment;
using Stardust.Data.Nodes;
Expand All @@ -16,6 +15,23 @@ public DeployService(RegistryService registryService)
_registryService = registryService;
}

public AppDeployVersion GetDeployVersion(AppDeploy app, Node node)
{
if (app.MultiVersion)
{
// 查找最新的一批版本,挑选符合目标节点的最新版本
var vers = AppDeployVersion.FindAllByDeployId(app.Id, 100);
vers = vers.Where(e => e.Enable).OrderByDescending(e => e.Id).ToList();

// 目标节点所支持的运行时标识符。一般有两个,如 win-x64/win
var rids = OSKindHelper.GetRID(node.OSKind, node.Architecture?.ToLower() + "");

return vers.FirstOrDefault(e => rids.Contains(e.Runtime));
}

return AppDeployVersion.FindByDeployIdAndVersion(app.Id, app.Version);
}

/// <summary>更新应用部署的节点信息</summary>
/// <param name="online"></param>
public void UpdateDeployNode(AppOnline online)
Expand Down
64 changes: 64 additions & 0 deletions Stardust/Models/OSKindHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,68 @@ public static OSKinds ParseLinux(String osName, String osVersion)

return 0;
}

/// <summary>获取指定类型操作系统在指定架构上的运行时标识。如win-x64/linux-musl-arm64</summary>
/// <param name="kind">系统类型</param>
/// <param name="arch">芯片架构。小写</param>
/// <returns></returns>
public static RuntimeIdentifier[] GetRID(OSKinds kind, String arch)
{
var rid = RuntimeIdentifier.Any;
if (kind >= OSKinds.MacOSX)
{
rid = arch switch
{
"x64" => RuntimeIdentifier.OsxX64,
"arm64" => RuntimeIdentifier.OsxArm64,
_ => RuntimeIdentifier.Osx,
};
}
else if (kind >= OSKinds.Linux || kind == OSKinds.SmartOS)
{
rid = arch switch
{
"x64" => RuntimeIdentifier.LinuxX64,
"arm" => RuntimeIdentifier.LinuxArm,
"arm64" => RuntimeIdentifier.LinuxArm64,
"mips64" => RuntimeIdentifier.LinuxMips64,
"loongarch64" => RuntimeIdentifier.LinuxLA64,
"riscv64" => RuntimeIdentifier.LinuxRiscV64,
_ => RuntimeIdentifier.Linux,
};
}
else if (kind >= OSKinds.Alpine)
{
rid = arch switch
{
"x64" => RuntimeIdentifier.LinuxMuslX64,
"arm" => RuntimeIdentifier.LinuxMuslArm,
"arm64" => RuntimeIdentifier.LinuxMuslArm64,
_ => RuntimeIdentifier.LinuxMusl,
};
}
else if (kind >= OSKinds.Win10)
{
rid = arch switch
{
"x86" => RuntimeIdentifier.WinX86,
"x64" => RuntimeIdentifier.WinX64,
"arm" => RuntimeIdentifier.WinArm,
"arm64" => RuntimeIdentifier.WinArm64,
_ => RuntimeIdentifier.Win,
};
}

if (rid == RuntimeIdentifier.Any) return [rid];

var ids = new List<RuntimeIdentifier>
{
rid
};

var rid2 = (RuntimeIdentifier)((Int32)rid / 10);
if (rid2 != rid) ids.Add(rid2);

return ids.ToArray();
}
}
4 changes: 2 additions & 2 deletions Stardust/Models/RuntimeIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum RuntimeIdentifier
WinArm64 = 14,

/// <summary>任意Linux系统</summary>
Linux = 2,
Linux = 20,
///// <summary>Linux系统(32位)</summary>
//LinuxX86 = 21,
/// <summary>Linux系统(64位)</summary>
Expand All @@ -44,7 +44,7 @@ public enum RuntimeIdentifier
LinuxMuslArm64 = 34,

/// <summary>任意OSX系统</summary>
Osx = 4,
Osx = 40,
///// <summary>OSX系统(32位)</summary>
//OsxX86 = 41,
/// <summary>OSX系统(64位)</summary>
Expand Down

0 comments on commit 8a26ef9

Please sign in to comment.