Skip to content

Commit 224de0f

Browse files
committed
Allow use of a smaller environment for local testing
1 parent 83fbda3 commit 224de0f

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ of its output is into the `./work` directory, where it maintains its
4848
own rustup installation, crate mirrors, etc.
4949

5050
```
51-
cd docker && docker build . && cd .. # This takes a while
52-
cargo run -- prepare-local
51+
cargo run -- prepare-local --docker-env mini
5352
cargo run -- define-ex --crate-select=demo stable beta
5453
cargo run -- prepare-ex
5554
cargo run -- run
File renamed without changes.

docker/Dockerfile.mini

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM ubuntu:16.04
2+
3+
ENV LAST_UPDATE=2017-05-25
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
RUN apt-get update
7+
8+
# Tools
9+
RUN apt-get install -y gcc pkg-config cmake
10+
11+
# Native deps
12+
RUN apt-get install -y libssl-dev
13+
14+
WORKDIR /source
15+
16+
# Create a crater user that run.sh will map to the value of the host user via
17+
# the USER_ID environment variable, to make the files the container writes not
18+
# be owned by root, but by the running host user
19+
# re https://github.com/docker/docker/issues/7198#issuecomment-158566258
20+
RUN adduser --no-create-home --disabled-login --gecos "" crater --uid 1000
21+
22+
# Configure the user id, controlled by -e USER_ID, and then
23+
# runs some command, controlled by -e CMD
24+
CMD ["bash", "-c", "usermod -u \"$USER_ID\" crater && exec su crater -c \"/run2.sh $CMD\""]
25+
26+
# sets up the environment for $CMD
27+
COPY run2.sh /run2.sh

src/cli.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ use std::str::FromStr;
3434
#[derive(Debug, Clone)]
3535
pub struct Ex(String);
3636

37+
#[derive(Debug, Clone)]
38+
pub struct DockerEnv(String);
39+
3740
#[derive(Debug, Clone)]
3841
pub struct Dest(PathBuf);
3942

4043
pub trait Cmd {
4144
fn run(&self) -> Result<()>;
4245
}
4346

44-
struct PrepareLocal;
47+
struct PrepareLocal(DockerEnv);
4548
struct DefineEx(Ex, Toolchain, Toolchain, ExMode, ExCrateSelect);
4649
#[derive(StructOpt)]
4750
#[structopt(name = "prepare-ex", about = "prepare shared and local data for experiment")]
@@ -91,9 +94,10 @@ struct Serve;
9194
// Local prep
9295
impl Cmd for PrepareLocal {
9396
fn run(&self) -> Result<()> {
97+
let docker_env = &(self.0).0;
9498
let stable_tc = Toolchain::Dist("stable".into());
9599
stable_tc.prepare()?;
96-
docker::build_container()?;
100+
docker::build_container(docker_env)?;
97101
lists::create_all_lists(false)
98102
}
99103
}
@@ -278,7 +282,7 @@ pub mod conv {
278282
cmd(
279283
"prepare-local",
280284
"acquire toolchains, build containers, build crate lists",
281-
),
285+
).arg(opt("docker-env", "full")),
282286
// List creation
283287
cmd("create-lists", "create all the lists of crates"),
284288
// Master experiment prep
@@ -351,9 +355,13 @@ pub mod conv {
351355
.parse::<ExCrateSelect>()
352356
}
353357

358+
fn docker_env(m: &ArgMatches) -> DockerEnv {
359+
DockerEnv(m.value_of("docker-env").expect("").to_string())
360+
}
361+
354362
Ok(match m.subcommand() {
355363
// Local prep
356-
("prepare-local", _) => Box::new(PrepareLocal),
364+
("prepare-local", Some(m)) => Box::new(PrepareLocal(docker_env(m))),
357365
("create-lists", _) => Box::new(CreateLists),
358366

359367
// Master experiment prep

src/docker.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ static IMAGE_NAME: &'static str = "crater";
1010
/// Builds the docker container image, 'crater', what will be used
1111
/// to isolate builds from each other. This expects the Dockerfile
1212
/// to exist in the `docker` directory, at runtime.
13-
pub fn build_container() -> Result<()> {
14-
run::run("docker", &["build", "-t", IMAGE_NAME, "docker"], &[])
13+
pub fn build_container(docker_env: &str) -> Result<()> {
14+
let dockerfile = format!("docker/Dockerfile.{}", docker_env);
15+
run::run(
16+
"docker",
17+
&["build", "-f", &dockerfile, "-t", IMAGE_NAME, "docker"],
18+
&[],
19+
)
1520
}
1621

1722
#[derive(Copy, Clone)]

0 commit comments

Comments
 (0)