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

Commit

Permalink
Support ExecOptions in dockerman.
Browse files Browse the repository at this point in the history
  • Loading branch information
marmistrz committed Jul 18, 2019
1 parent 15978f6 commit caae085
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
7 changes: 7 additions & 0 deletions gu-model/src/envman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,20 @@ impl Default for ResourceFormat {
}
}

#[derive(Clone, Serialize, Deserialize, Default, Hash, Eq, PartialEq, Debug)]
pub struct ExecOptions {
pub user: Option<String>,
pub working_dir: Option<String>,
}

#[derive(Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Debug)]
#[serde(rename_all = "camelCase")]
pub enum Command {
Exec {
// return cmd output
executable: String,
args: Vec<String>,
options: ExecOptions,
},
Open,
Close,
Expand Down
23 changes: 17 additions & 6 deletions gu-provider/src/dockerman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,23 @@ impl DockerSession {
&mut self,
executable: String,
mut args: Vec<String>,
options: ExecOptions,
) -> impl Future<Item = String, Error = String> {
args.insert(0, executable);
let cfg = {
use async_docker::models::*;

ExecConfig::new()
let mut config = ExecConfig::new()
.with_attach_stdout(true)
.with_attach_stderr(true)
.with_cmd(args)
.with_cmd(args);
if let Some(user) = options.user {
config.set_user(user)
}
if let Some(working_dir) = options.working_dir {
config.set_working_dir(working_dir)
}
config
};

self.container
Expand Down Expand Up @@ -469,10 +477,13 @@ fn run_command(
match command {
Command::Open => docker_man.run_for_deployment(session_id, DockerSession::do_open),
Command::Close => docker_man.run_for_deployment(session_id, DockerSession::do_close),
Command::Exec { executable, args } => docker_man
.run_for_deployment(session_id, |deployment| {
deployment.do_exec(executable, args)
}),
Command::Exec {
executable,
args,
options,
} => docker_man.run_for_deployment(session_id, |deployment| {
deployment.do_exec(executable, args, options)
}),
// TODO: FIXME @destruktiv: same as Exec but async
Command::Start {
executable: _,
Expand Down
11 changes: 9 additions & 2 deletions gu-provider/src/hdman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{

use actix::{fut, prelude::*};
use futures::{future, prelude::*};
use log::{debug, error, info};
use log::{debug, error, info, warn};
use serde::{Deserialize, Serialize};

use gu_actix::prelude::*;
Expand Down Expand Up @@ -295,7 +295,14 @@ fn run_command(
match command {
Command::Open => Box::new(fut::ok("Open mock".to_string())),
Command::Close => Box::new(fut::ok("Close mock".to_string())),
Command::Exec { executable, args } => {
Command::Exec {
executable,
args,
options,
} => {
if options != Default::default() {
warn!("ExecOptions unimplemented in hdman");
}
let executable = session.get_session_exec_path(&executable);
let session_id = session_id.clone();
let session_dir = session.workspace.path().to_owned();
Expand Down

0 comments on commit caae085

Please sign in to comment.