From fcce352e74259505b2b6917b80fb16c820693628 Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Fri, 12 Jul 2019 16:04:57 +0200 Subject: [PATCH 1/3] Add support for autostart of Docker containers. --- gu-model/src/dockerman.rs | 2 ++ gu-provider/src/dockerman.rs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gu-model/src/dockerman.rs b/gu-model/src/dockerman.rs index a5e277461..cf6620863 100644 --- a/gu-model/src/dockerman.rs +++ b/gu-model/src/dockerman.rs @@ -9,6 +9,8 @@ pub struct CreateOptions { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub net: Option, + #[serde(default)] // default is false + pub autostart: bool, } impl CreateOptions { diff --git a/gu-provider/src/dockerman.rs b/gu-provider/src/dockerman.rs index fb82413c9..4c6dc7647 100644 --- a/gu-provider/src/dockerman.rs +++ b/gu-provider/src/dockerman.rs @@ -420,11 +420,15 @@ impl Handler> for DockerMan { ActorResponse::r#async(fut::wrap_future(pull_and_create).and_then( move |id, act: &mut DockerMan, _| { if let Some(ref api) = act.docker_api { - let deploy = DockerSession { + let mut deploy = DockerSession { workspace, container: api.container(Cow::from(id.clone())), status: PeerSessionStatus::CREATED, }; + if msg.options.autostart { + info!("Autostarting the container"); + deploy.do_start(); + } act.deploys.insert_deploy(id.clone(), deploy); fut::ok(id) } else { From c1d1eea41a3bd7024038fc79b40bf462b6991495 Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Mon, 15 Jul 2019 09:57:26 +0200 Subject: [PATCH 2/3] not working try --- gu-provider/src/dockerman.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gu-provider/src/dockerman.rs b/gu-provider/src/dockerman.rs index 4c6dc7647..3e0bf1bb8 100644 --- a/gu-provider/src/dockerman.rs +++ b/gu-provider/src/dockerman.rs @@ -425,14 +425,18 @@ impl Handler> for DockerMan { container: api.container(Cow::from(id.clone())), status: PeerSessionStatus::CREATED, }; - if msg.options.autostart { + let maybe_start = if msg.options.autostart { info!("Autostarting the container"); - deploy.do_start(); - } + let autostart_future = fut::wrap_future(deploy.do_start()); + let x: Box> = Box::new(autostart_future); + fut::Either::A(autostart_future) + } else { + fut::Either::B(future::ok(())) + }; act.deploys.insert_deploy(id.clone(), deploy); - fut::ok(id) + fut::Either::A(maybe_start.and_then(|_| fut::ok(id)); } else { - fut::err(Error::UnknownEnv(msg.env_type.clone())) + fut::Either::B(fut::err(Error::UnknownEnv(msg.env_type.clone()))) } }, )) From da093718c3dbfb2daadc603f50a0aaf2e4cdfa0d Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Mon, 15 Jul 2019 15:36:04 +0200 Subject: [PATCH 3/3] Fix autostart --- gu-provider/src/dockerman.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gu-provider/src/dockerman.rs b/gu-provider/src/dockerman.rs index 3e0bf1bb8..bd56812d3 100644 --- a/gu-provider/src/dockerman.rs +++ b/gu-provider/src/dockerman.rs @@ -427,14 +427,14 @@ impl Handler> for DockerMan { }; let maybe_start = if msg.options.autostart { info!("Autostarting the container"); - let autostart_future = fut::wrap_future(deploy.do_start()); - let x: Box> = Box::new(autostart_future); - fut::Either::A(autostart_future) + let autostart_future = + deploy.do_start().map_err(Error::Error).map(|_| ()); + fut::Either::A(fut::wrap_future(autostart_future)) } else { - fut::Either::B(future::ok(())) + fut::Either::B(fut::ok(())) }; act.deploys.insert_deploy(id.clone(), deploy); - fut::Either::A(maybe_start.and_then(|_| fut::ok(id)); + fut::Either::A(maybe_start.and_then(|_, _, _| fut::ok(id))) } else { fut::Either::B(fut::err(Error::UnknownEnv(msg.env_type.clone()))) }