Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Add support for autostart of Docker containers. (#241)
Browse files Browse the repository at this point in the history
Add support for autostart of Docker containers.
  • Loading branch information
marmistrz authored and prekucki committed Jul 18, 2019
1 parent 15978f6 commit 953089d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions gu-model/src/dockerman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub struct CreateOptions {
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub net: Option<NetDef>,
#[serde(default)] // default is false
pub autostart: bool,
}

impl CreateOptions {
Expand Down
14 changes: 11 additions & 3 deletions gu-provider/src/dockerman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,23 @@ impl Handler<CreateSession<CreateOptions>> 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,
};
let maybe_start = if msg.options.autostart {
info!("Autostarting the container");
let autostart_future =
deploy.do_start().map_err(Error::Error).map(|_| ());
fut::Either::A(fut::wrap_future(autostart_future))
} else {
fut::Either::B(fut::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())))
}
},
))
Expand Down

0 comments on commit 953089d

Please sign in to comment.