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

Add support for autostart of Docker containers. #241

Merged
merged 3 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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