diff options
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> { |