Skip to content

Commit

Permalink
add SandboxBuilder image override
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Nov 24, 2020
1 parent 7a4ef73 commit 4ce5e85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ impl BuildDirectory {
self.workspace.builds_dir().join(&self.name)
}

fn source_dir(&self) -> PathBuf {
/// Get the path to the source code on the host machine (outside the sandbox).
pub fn source_dir(&self) -> PathBuf {
self.build_dir().join("source")
}

Expand Down
17 changes: 16 additions & 1 deletion src/cmd/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::path::{Path, PathBuf};
use std::time::Duration;

/// The Docker image used for sandboxing.
#[derive(Clone)]
pub struct SandboxImage {
name: String,
}
Expand Down Expand Up @@ -146,6 +147,7 @@ pub struct SandboxBuilder {
user: Option<String>,
cmd: Vec<String>,
enable_networking: bool,
image: Option<SandboxImage>,
}

impl SandboxBuilder {
Expand All @@ -160,6 +162,7 @@ impl SandboxBuilder {
user: None,
cmd: Vec::new(),
enable_networking: true,
image: None,
}
}

Expand Down Expand Up @@ -203,6 +206,14 @@ impl SandboxBuilder {
self
}

/// Override the image used for this sandbox.
///
/// By default rustwide will use the image from the `Workspace`.
pub fn image(mut self, image: SandboxImage) -> Self {
self.image = Some(image);
self
}

pub(super) fn env<S1: Into<String>, S2: Into<String>>(mut self, key: S1, value: S2) -> Self {
self.env.push((key.into(), value.into()));
self
Expand Down Expand Up @@ -274,7 +285,11 @@ impl SandboxBuilder {
args.push("--isolation=process".into());
}

args.push(workspace.sandbox_image().name.clone());
if let Some(image) = self.image {
args.push(image.name);
} else {
args.push(workspace.sandbox_image().name.clone());
}

for arg in self.cmd {
args.push(arg);
Expand Down

0 comments on commit 4ce5e85

Please sign in to comment.