diff --git a/Stardust.Data/Deployment/Model.xml b/Stardust.Data/Deployment/Model.xml index 56ead0b7..23a2cbf0 100644 --- a/Stardust.Data/Deployment/Model.xml +++ b/Stardust.Data/Deployment/Model.xml @@ -49,6 +49,7 @@ + diff --git a/Stardust.Data/Deployment/Stardust.htm b/Stardust.Data/Deployment/Stardust.htm index 77b107b4..4db3246a 100644 --- a/Stardust.Data/Deployment/Stardust.htm +++ b/Stardust.Data/Deployment/Stardust.htm @@ -137,6 +137,17 @@

应用部署(AppDeploy)

应用正在使用的版本号 + + MultiVersion + 多版本 + Boolean + + + + N + 支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本 + + AutoPublish 自动发布 diff --git "a/Stardust.Data/Deployment/\345\272\224\347\224\250\351\203\250\347\275\262.cs" "b/Stardust.Data/Deployment/\345\272\224\347\224\250\351\203\250\347\275\262.cs" index f4160111..6ee0843b 100644 --- "a/Stardust.Data/Deployment/\345\272\224\347\224\250\351\203\250\347\275\262.cs" +++ "b/Stardust.Data/Deployment/\345\272\224\347\224\250\351\203\250\347\275\262.cs" @@ -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; + /// 多版本。支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本 + [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; /// 自动发布。应用版本后自动发布到启用节点,加快发布速度 [DisplayName("自动发布")] @@ -282,6 +290,7 @@ public override Object this[String name] "Enable" => _Enable, "Nodes" => _Nodes, "Version" => _Version, + "MultiVersion" => _MultiVersion, "AutoPublish" => _AutoPublish, "PackageName" => _PackageName, "Repository" => _Repository, @@ -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; @@ -381,6 +391,9 @@ public partial class _ /// 版本。应用正在使用的版本号 public static readonly Field Version = FindByName("Version"); + /// 多版本。支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本 + public static readonly Field MultiVersion = FindByName("MultiVersion"); + /// 自动发布。应用版本后自动发布到启用节点,加快发布速度 public static readonly Field AutoPublish = FindByName("AutoPublish"); @@ -471,6 +484,9 @@ public partial class __ /// 版本。应用正在使用的版本号 public const String Version = "Version"; + /// 多版本。支持多运行时版本,此时只认可部署版本中符合运行时要求的最新可用版本 + public const String MultiVersion = "MultiVersion"; + /// 自动发布。应用版本后自动发布到启用节点,加快发布速度 public const String AutoPublish = "AutoPublish"; diff --git a/Stardust.Server/Controllers/DeployController.cs b/Stardust.Server/Controllers/DeployController.cs index d1249f1f..6a98a47b 100644 --- a/Stardust.Server/Controllers/DeployController.cs +++ b/Stardust.Server/Controllers/DeployController.cs @@ -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 { diff --git a/Stardust.Server/Services/DeployService.cs b/Stardust.Server/Services/DeployService.cs index 9502a168..acb81a40 100644 --- a/Stardust.Server/Services/DeployService.cs +++ b/Stardust.Server/Services/DeployService.cs @@ -1,5 +1,4 @@ using NewLife; -using System.Xml.Linq; using Stardust.Data; using Stardust.Data.Deployment; using Stardust.Data.Nodes; @@ -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); + } + /// 更新应用部署的节点信息 /// public void UpdateDeployNode(AppOnline online) diff --git a/Stardust/Models/OSKindHelper.cs b/Stardust/Models/OSKindHelper.cs index 8ec4269c..fd31f05a 100644 --- a/Stardust/Models/OSKindHelper.cs +++ b/Stardust/Models/OSKindHelper.cs @@ -123,4 +123,68 @@ public static OSKinds ParseLinux(String osName, String osVersion) return 0; } + + /// 获取指定类型操作系统在指定架构上的运行时标识。如win-x64/linux-musl-arm64 + /// 系统类型 + /// 芯片架构。小写 + /// + 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 + { + rid + }; + + var rid2 = (RuntimeIdentifier)((Int32)rid / 10); + if (rid2 != rid) ids.Add(rid2); + + return ids.ToArray(); + } } \ No newline at end of file diff --git a/Stardust/Models/RuntimeIdentifier.cs b/Stardust/Models/RuntimeIdentifier.cs index d439f0bd..7a921a57 100644 --- a/Stardust/Models/RuntimeIdentifier.cs +++ b/Stardust/Models/RuntimeIdentifier.cs @@ -18,7 +18,7 @@ public enum RuntimeIdentifier WinArm64 = 14, /// 任意Linux系统 - Linux = 2, + Linux = 20, ///// Linux系统(32位) //LinuxX86 = 21, /// Linux系统(64位) @@ -44,7 +44,7 @@ public enum RuntimeIdentifier LinuxMuslArm64 = 34, /// 任意OSX系统 - Osx = 4, + Osx = 40, ///// OSX系统(32位) //OsxX86 = 41, /// OSX系统(64位)