Skip to content

Commit

Permalink
feat: added prune functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhobson committed Feb 10, 2024
1 parent 8574840 commit 8793614
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Sergen.Core/Services/Containers/Docker/DockerInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ public async Task StopById(string serverId, IChatResponseToken icrt, string cont
}
}

public async Task Prune(IChatResponseToken icrt)
{
ulong spaceFreed = 0;
spaceFreed += (await _client.Containers.PruneContainersAsync()).SpaceReclaimed;
spaceFreed += (await _client.Images.PruneImagesAsync()).SpaceReclaimed;
await icrt.Respond($"Pruned {spaceFreed} bytes of containers and images.");
}

private async Task<Mount> CreateContainerMount(string gameFilesPath, string bindData)
{
string actualBind = bindData;
Expand Down
2 changes: 2 additions & 0 deletions src/Sergen.Core/Services/Containers/IContainerInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public interface IContainerInterface
Task Stop(string serverId, IChatResponseToken icrt, GameServer gameServer);

Task StopById(string serverId, IChatResponseToken icrt, string containerId);

Task Prune(IChatResponseToken icrt);
}
}
7 changes: 7 additions & 0 deletions src/Sergen.Main/Services/Chat/ChatProcessor/ChatProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ await icrt.Respond(@"Command list:
`-allowlist enable/disable` Will enable/disable the allowlist.
`-allowlist add @user` Will enable that user to control servers.
`-allowlist remove @user` Will stop that user from controlling servers.
`-prune` Will prune all dangling docker containers on the host.
");
break;
case "-ping":
Expand Down Expand Up @@ -83,6 +84,12 @@ await icrt.Respond(@"Command list:
var serverStringList = ObjectToString.Convert(serverNames);
await icrt.Respond($"Possible game servers are: {serverStringList}");
break;
case "-prune":
if (await VerifyUser(serverID, senderID, icrt))
{
await _containerInterface.Prune(icrt);
}
break;
}

if (input.StartsWith ("-run ") || input.StartsWith ("-start "))
Expand Down

0 comments on commit 8793614

Please sign in to comment.