aboutsummaryrefslogtreecommitdiff
path: root/planetwars-matchrunner/src
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-07-24 23:08:51 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-07-24 23:08:51 +0200
commit93c4306b1015594bb6d7e08d03138c12229ac598 (patch)
treebc8de89e4124c2e36957fce315e8bdcf4bc8c1e2 /planetwars-matchrunner/src
parent14b51033fc9ca2188a0140893a56c0a249b3e118 (diff)
downloadplanetwars.dev-93c4306b1015594bb6d7e08d03138c12229ac598.tar.xz
planetwars.dev-93c4306b1015594bb6d7e08d03138c12229ac598.zip
pull docker bots before running them
Diffstat (limited to 'planetwars-matchrunner/src')
-rw-r--r--planetwars-matchrunner/src/docker_runner.rs34
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()),