Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for worker to bind to local docker socket for testing exports #112

Merged
merged 1 commit into from
Feb 13, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .studiorc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export GITHUB_CLIENT_SECRET
export SSL_CERT_FILE
export GITHUB_APP_ID
export GITHUB_APP_URL
export DEV_MODE

no_install_deps() {
local file="/src/components/${1}/cleanup"
Expand Down Expand Up @@ -311,6 +312,9 @@ DOCS

install-packages

# Forces the worker to use a bound docker socket
DEV_MODE=true

ENV_CONFIG="/src/.secrets/habitat-env"

if [[ -f "${ENV_CONFIG}" ]]; then
Expand Down
23 changes: 17 additions & 6 deletions components/builder-worker/src/runner/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use hab_core::os::process::{self, Pid, Signal};

use error::{Error, Result};
use runner::log_pipe::LogPipe;
use runner::{NONINTERACTIVE_ENVVAR, RUNNER_DEBUG_ENVVAR};
use runner::{DEV_MODE, NONINTERACTIVE_ENVVAR, RUNNER_DEBUG_ENVVAR};
use runner::workspace::Workspace;

lazy_static! {
Expand Down Expand Up @@ -145,7 +145,13 @@ impl<'a> DockerExporter<'a> {
);
cmd.env(DOCKER_HOST_ENVVAR, sock); // Use the job-specific `dockerd`
cmd.stdout(Stdio::piped());
cmd.stderr(Stdio::piped());
//TED: workaround to not pipe error socket in dev mode which causes the worker to die
match env::var_os(DEV_MODE) {
Some(_) => debug!("Not exporting in dev mode"),
None => {
cmd.stderr(Stdio::piped());
}
};

debug!("spawning docker export command");
let mut child = cmd.spawn().map_err(Error::Exporter)?;
Expand Down Expand Up @@ -233,9 +239,14 @@ impl<'a> DockerExporter<'a> {
}

fn dockerd_sock(&self) -> String {
format!(
"unix://{}",
self.dockerd_path().join("var/run/docker.sock").display()
)
match env::var_os(DEV_MODE) {
Some(_) => "unix:///var/run/docker.sock".to_string(),
None => {
format!(
"unix://{}",
self.dockerd_path().join("var/run/docker.sock").display()
)
}
}
}
}
2 changes: 2 additions & 0 deletions components/builder-worker/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const NONINTERACTIVE_ENVVAR: &'static str = "HAB_NONINTERACTIVE";

/// Environment variable to enable or disable debug output in runner's studio
const RUNNER_DEBUG_ENVVAR: &'static str = "BUILDER_RUNNER_DEBUG";
/// Environment variable to enable or disable dev mode.
const DEV_MODE: &'static str = "DEV_MODE";
/// In-memory zmq address of Job RunnerMgr
const INPROC_ADDR: &'static str = "inproc://runner";
/// Protocol message to indicate the Job Runner has received a work request
Expand Down
12 changes: 9 additions & 3 deletions components/builder-worker/src/runner/studio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::os::unix::process::CommandExt;
use std::path::PathBuf;
use std::process::{Command, ExitStatus, Stdio};
use std::sync::Mutex;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};

use hab_core::channel::{BLDR_CHANNEL_ENVVAR, STABLE_CHANNEL};
use hab_core::env;
Expand All @@ -27,7 +27,7 @@ use hab_core::AUTH_TOKEN_ENVVAR;
use error::{Error, Result};
use network::NetworkNamespace;
use runner::log_pipe::LogPipe;
use runner::{NONINTERACTIVE_ENVVAR, RUNNER_DEBUG_ENVVAR};
use runner::{DEV_MODE, NONINTERACTIVE_ENVVAR, RUNNER_DEBUG_ENVVAR};
use runner::workspace::Workspace;

pub static STUDIO_UID: AtomicUsize = ATOMIC_USIZE_INIT;
Expand Down Expand Up @@ -104,7 +104,13 @@ impl<'a> Studio<'a> {
}
}
cmd.stdout(Stdio::piped());
cmd.stderr(Stdio::piped());
//TED: workaround to not pipe error socket in dev mode which causes the worker to die
match env::var_os(DEV_MODE) {
Some(_) => debug!("Studio not displaying stderr"),
None => {
cmd.stderr(Stdio::piped());
}
};
cmd.arg("-k"); // Origin key
cmd.arg(self.workspace.job.origin());
cmd.arg("build");
Expand Down
3 changes: 2 additions & 1 deletion support/linux/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sudo hab install core/busybox-static core/hab-studio
sudo hab install \
core/direnv \
core/wget \
core/docker \
core/curl -b
# shellcheck disable=SC2016
echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
echo 'eval "$(direnv hook bash)"' >> ~/.bashrc