diff options
Diffstat (limited to 'planetwars-matchrunner')
-rw-r--r-- | planetwars-matchrunner/src/docker_runner.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/planetwars-matchrunner/src/docker_runner.rs b/planetwars-matchrunner/src/docker_runner.rs index 2d93273..6de9bb1 100644 --- a/planetwars-matchrunner/src/docker_runner.rs +++ b/planetwars-matchrunner/src/docker_runner.rs @@ -15,12 +15,22 @@ use crate::match_context::{EventBus, PlayerHandle, RequestError, RequestMessage} use crate::match_log::{MatchLogMessage, MatchLogger, StdErrMessage}; use crate::BotSpec; +// TODO: this API needs a better design with respect to pulling +// and general container management #[derive(Clone, Debug)] pub struct DockerBotSpec { pub image: String, pub binds: Option<Vec<String>>, pub argv: Option<Vec<String>>, pub working_dir: Option<String>, + pub pull: bool, + pub credentials: Option<Credentials>, +} + +#[derive(Clone, Debug)] +pub struct Credentials { + pub username: String, + pub password: String, } #[async_trait] @@ -43,6 +53,30 @@ async fn spawn_docker_process( ) -> Result<ContainerProcess, bollard::errors::Error> { let docker = Docker::connect_with_socket_defaults()?; + if params.pull { + let mut create_image_stream = docker.create_image( + Some(bollard::image::CreateImageOptions { + from_image: params.image.as_str(), + ..Default::default() + }), + None, + params + .credentials + .as_ref() + .map(|credentials| bollard::auth::DockerCredentials { + username: Some(credentials.username.clone()), + password: Some(credentials.password.clone()), + ..Default::default() + }), + ); + + while let Some(item) = create_image_stream.next().await { + // just consume the stream for now, + // and make noise when something breaks + let _info = item.expect("hit error in docker pull"); + } + } + let memory_limit = 512 * 1024 * 1024; // 512MB let config = container::Config { image: Some(params.image.clone()), |