Implemented more life cycle handling. Added support for rootless environments

This commit is contained in:
2024-12-27 20:08:05 +01:00
parent 039db22207
commit 92e9f42fbc
21 changed files with 738 additions and 20 deletions

View File

@@ -0,0 +1,36 @@
using Docker.DotNet;
using MoonlightServers.Daemon.Models;
using MoonlightServers.DaemonShared.Enums;
namespace MoonlightServers.Daemon.Extensions.ServerExtensions;
public static class ServerCreateExtensions
{
public static async Task Create(this Server server)
{
var dockerClient = server.ServiceProvider.GetRequiredService<DockerClient>();
// Ensure image is pulled
await server.EnsureDockerImage();
// Ensure runtime storage is created
await server.EnsureRuntimeStorage();
// Creating container
await server.NotifyTask(ServerTask.CreatingContainer);
var parameters = server.GetRuntimeContainerParameters();
var container = await dockerClient.Containers.CreateContainerAsync(parameters);
server.ContainerId = container.ID;
// Attach console
await server.Attach();
}
public static async Task ReCreate(this Server server)
{
await server.Destroy();
await server.Create();
}
}