From 326bd096626ab712e03b78e6e7a30a52f93ad76b Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Thu, 27 Jun 2024 11:50:44 +0200 Subject: [PATCH] Upgraded server images to new mooncore forms --- Moonlight/Core/Database/DataContext.cs | 5 + Moonlight/Core/UI/Views/Admin/Api/Keys.razor | 8 +- .../Core/UI/Views/Admin/Users/Index.razor | 2 +- .../Servers/Entities/ServerDockerImage.cs | 2 +- .../Features/Servers/Entities/ServerImage.cs | 12 +- .../ImageComponents/DefaultDockerImage.razor | 53 ++++++ .../UI/ImageComponents/EditorComponent.razor | 41 +++++ .../ImageComponents/ImageDockerImages.razor | 136 +++++++++----- .../ImageParseConfigEditor.razor | 159 +++++++++++++++++ .../UI/ImageComponents/ImageVariables.razor | 145 ++++++++++++--- .../UI/NodeComponents/NodeAllocations.razor | 13 +- .../Servers/UI/Views/Admin/Images/Index.razor | 166 +++++++++++++----- .../Servers/UI/Views/Admin/Nodes/Index.razor | 2 +- .../Servers/UI/Views/Servers/Networks.razor | 2 +- Moonlight/Moonlight.csproj | 2 +- 15 files changed, 604 insertions(+), 144 deletions(-) create mode 100644 Moonlight/Features/Servers/UI/ImageComponents/DefaultDockerImage.razor create mode 100644 Moonlight/Features/Servers/UI/ImageComponents/EditorComponent.razor create mode 100644 Moonlight/Features/Servers/UI/ImageComponents/ImageParseConfigEditor.razor diff --git a/Moonlight/Core/Database/DataContext.cs b/Moonlight/Core/Database/DataContext.cs index d987ada6..8ebd658d 100644 --- a/Moonlight/Core/Database/DataContext.cs +++ b/Moonlight/Core/Database/DataContext.cs @@ -50,4 +50,9 @@ public class DataContext : DbContext ); } } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + + } } \ No newline at end of file diff --git a/Moonlight/Core/UI/Views/Admin/Api/Keys.razor b/Moonlight/Core/UI/Views/Admin/Api/Keys.razor index 3bd01e14..ce9546a9 100644 --- a/Moonlight/Core/UI/Views/Admin/Api/Keys.razor +++ b/Moonlight/Core/UI/Views/Admin/Api/Keys.razor @@ -15,8 +15,8 @@
+ OnConfigureCreate="OnConfigureFrom" + OnConfigureEdit="OnConfigureFrom"> - @* - - - Download and import a image from our repository or create a new one. Need help? Check out our documentation - - - - - + + + + Import egg - - + + Import - - *@ - + + + @code { - private AutoCrud Crud; + private FastCrud Crud; + private MCBCustomFileSelect ImageUpload; private MCBCustomFileSelect EggUpload; - private IEnumerable Load(Repository repository) + private IEnumerable Loader(Repository repository) { - return repository.Get(); + return repository + .Get() + .Include(x => x.DockerImages) + .Include(x => x.Variables); } - private Task ValidateDelete(ServerImage serverImage) + private void OnConfigure(FastCrudConfiguration configuration) { - if (ServerRepository.Get().Any(x => x.Image.Id == serverImage.Id)) - throw new DisplayException("A server using this image exists. Please delete the servers using this image to continue"); + configuration.ValidateDelete = image => + { + if (ServerRepository.Get().Any(x => x.Image.Id == image.Id)) + throw new DisplayException("A server using this image exists. Please delete the servers using this image to continue"); - return Task.CompletedTask; + return Task.CompletedTask; + }; + + configuration.CustomDelete = CustomDelete; } - private Task ValidateAdd(ServerImage image) + private void OnConfigureForm(FastConfiguration configuration, ServerImage image) { - // Set defaults + // General + configuration.AddProperty(x => x.Name) + .WithDefaultComponent() + .WithPage("General") + .WithValidation(FastValidators.Required); - image.StopCommand = "^C"; - image.StartupCommand = "echo Startup command here"; - image.AllocationsNeeded = 1; - image.InstallScript = "#! /bin/bash\necho Done"; - image.InstallShell = "/bin/bash"; - image.InstallDockerImage = "debian:latest"; - image.OnlineDetection = "Running"; - image.AllowDockerImageChange = false; - image.DefaultDockerImage = 0; - image.ParseConfiguration = "[]"; + configuration.AddProperty(x => x.Author) + .WithDefaultComponent() + .WithPage("General") + .WithValidation(FastValidators.Required); - return Task.CompletedTask; + configuration.AddProperty(x => x.DonateUrl) + .WithDefaultComponent() + .WithPage("General") + .WithDescription("Provide a url here in order to give people the ability to donate for your work"); + + configuration.AddProperty(x => x.UpdateUrl) + .WithDefaultComponent() + .WithPage("General") + .WithDescription("A http(s) url directly to a json file which will serve as an update for the image. When a update is fetched, it will just get this url and try to load it"); + + // Power + configuration.AddProperty(x => x.StartupCommand) + .WithDefaultComponent() + .WithValidation(FastValidators.Required) + .WithPage("Start, Stop & Status") + .WithDescription("This command will be executed at the start of a server. You can use environment variables in a {} here"); + + configuration.AddProperty(x => x.OnlineDetection) + .WithDefaultComponent() + .WithValidation(FastValidators.Required) + .WithPage("Start, Stop & Status") + .WithDescription("A regex string specifying that a server is online when the daemon finds a match in the console output matching this expression"); + + configuration.AddProperty(x => x.StopCommand) + .WithDefaultComponent() + .WithValidation(FastValidators.Required) + .WithPage("Start, Stop & Status") + .WithDescription("A command which will be sent to the servers stdin when it should get stopped. Power signals can be achived by using ^. E.g. ^C"); + + // Parsing + configuration.AddProperty(x => x.ParseConfiguration) + .WithComponent() + .WithPage("Parsing"); + + configuration.AddCustomPage("Variables", ComponentHelper.FromType(parameters => + { + parameters.Add("Image", image); + })); + + configuration.AddCustomPage("Docker Images", ComponentHelper.FromType(parameters => + { + parameters.Add("Image", image); + })); + + configuration.AddProperty(x => x.AllowDockerImageChange) + .WithComponent() + .WithPage("Miscellaneous") + .WithDescription("This toggle specifies if a user is allowed to change the docker image from the list of docker images associated to the image"); + + configuration.AddProperty(x => x.DefaultDockerImage) + .WithComponent() + .WithAdditionalOption("Image", image) + .WithPage("Miscellaneous"); + + configuration.AddProperty(x => x.AllocationsNeeded) + .WithDefaultComponent() + .WithPage("Miscellaneous") + .WithValidation(x => x > 1 ? ValidationResult.Success : new ValidationResult("This specifies the amount of allocations needed for this image in order to create a server")); + + configuration.AddProperty(x => x.InstallDockerImage) + .WithDefaultComponent() + .WithPage("Installation") + .WithName("Docker Image") + .WithValidation(FastValidators.Required) + .WithValidation(RegexValidator.Create("^(?:[a-zA-Z0-9\\-\\.]+\\/)?[a-zA-Z0-9\\-]+(?:\\/[a-zA-Z0-9\\-]+)*(?::[a-zA-Z0-9_\\.-]+)?$", "You need to provide a valid docker image name")); + + configuration.AddProperty(x => x.InstallShell) + .WithDefaultComponent() + .WithPage("Installation") + .WithName("Shell") + .WithValidation(FastValidators.Required); + + configuration.AddProperty(x => x.InstallScript) + .WithComponent() + .WithPage("Installation") + .WithName("Script") + .WithValidation(FastValidators.Required); } private Task CustomDelete(ServerImage serverImage) diff --git a/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor b/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor index 59ec6be5..dd8f4ffd 100644 --- a/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor +++ b/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor @@ -207,7 +207,7 @@ }; } - private void OnConfigureCreate(FastConfiguration configuration) + private void OnConfigureCreate(FastConfiguration configuration, ServerNode _) { configuration.AddProperty(x => x.Name) .WithDefaultComponent() diff --git a/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor b/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor index 7b01e632..3815f758 100644 --- a/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor +++ b/Moonlight/Features/Servers/UI/Views/Servers/Networks.razor @@ -92,7 +92,7 @@ }; } - private void OnConfigureCreate(FastConfiguration configuration) + private void OnConfigureCreate(FastConfiguration configuration, ServerNetwork _) { configuration.AddProperty(x => x.Name) .WithDefaultComponent() diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index ea125abc..b180b0ea 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -94,7 +94,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - +