diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-05-21 14:20:38 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-05-21 14:20:38 +0200 |
commit | c873f3a1cb9d59caecfe3f78d04fd0b67e1d8161 (patch) | |
tree | 2cbe9f075102340423221f8e584e7b36dc6798e7 /planetwars-matchrunner/src/docker_runner.rs | |
parent | 39940aaabd057cb498d51cd2cceef7be187ab3d2 (diff) | |
download | planetwars.dev-c873f3a1cb9d59caecfe3f78d04fd0b67e1d8161.tar.xz planetwars.dev-c873f3a1cb9d59caecfe3f78d04fd0b67e1d8161.zip |
stop and remove bot containers after match is finished
Diffstat (limited to 'planetwars-matchrunner/src/docker_runner.rs')
-rw-r--r-- | planetwars-matchrunner/src/docker_runner.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/planetwars-matchrunner/src/docker_runner.rs b/planetwars-matchrunner/src/docker_runner.rs index d563d60..6e73e08 100644 --- a/planetwars-matchrunner/src/docker_runner.rs +++ b/planetwars-matchrunner/src/docker_runner.rs @@ -85,16 +85,35 @@ async fn spawn_docker_process( .await?; Ok(ContainerProcess { + docker, + container_id, stdin: input, output, }) } struct ContainerProcess { + docker: Docker, + container_id: String, stdin: Pin<Box<dyn AsyncWrite + Send>>, output: Pin<Box<dyn Stream<Item = Result<LogOutput, bollard::errors::Error>> + Send>>, } +impl ContainerProcess { + // &mut is required here to make terminate().await Sync + async fn terminate(&mut self) -> Result<(), bollard::errors::Error> { + self.docker + .remove_container( + &self.container_id, + Some(bollard::container::RemoveContainerOptions { + force: true, + ..Default::default() + }), + ) + .await + } +} + fn create_docker_bot( process: ContainerProcess, player_id: u32, @@ -151,6 +170,11 @@ impl DockerBotRunner { .unwrap() .resolve_request(request_id, request_response); } + + self.process + .terminate() + .await + .expect("could not terminate process"); } pub async fn communicate(&mut self, input: &[u8]) -> io::Result<Bytes> { |