Skip to content

Commit

Permalink
Fix docker_read_mount_paths to support podman.
Browse files Browse the repository at this point in the history
Used to hard-code a search for docker, which is now removed to use the
path of the located engine. Also adds the `CROSS_CONTAINER_IN_CONTAINER`
environment variables, which overrides the `CROSS_DOCKER_IN_DOCKER`
variable.
  • Loading branch information
Alexhuszagh committed Jun 14, 2022
1 parent 5fe2145 commit aa40461
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ container used for cross compilation. This includes the original project directo
well as the root path of the parent container to give access to the rust build
tools.

To inform `cross` that it is running inside a container set `CROSS_DOCKER_IN_DOCKER=true`.
To inform `cross` that it is running inside a container set `CROSS_CONTAINER_IN_CONTAINER=true`.

A development or CI container can be created like this:

```
FROM rust:1
# set CROSS_DOCKER_IN_DOCKER to inform `cross` that it is executed from within a container
ENV CROSS_DOCKER_IN_DOCKER=true
# set CROSS_CONTAINER_IN_CONTAINER to inform `cross` that it is executed from within a container
ENV CROSS_CONTAINER_IN_CONTAINER=true
# install `cross`
RUN cargo install cross
Expand Down
17 changes: 14 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,20 @@ pub fn parse(target_list: &TargetList) -> Result<Args> {
}
}

let docker_in_docker = env::var("CROSS_DOCKER_IN_DOCKER")
.map(|s| bool_from_envvar(&s))
.unwrap_or_default();
let docker_in_docker = if let Ok(value) = env::var("CROSS_CONTAINER_IN_CONTAINER") {
if env::var("CROSS_DOCKER_IN_DOCKER").is_ok() {
eprintln!(
"Warning: using both `CROSS_CONTAINER_IN_CONTAINER` and `CROSS_DOCKER_IN_DOCKER`."
);
}
bool_from_envvar(&value)
} else if let Ok(value) = env::var("CROSS_DOCKER_IN_DOCKER") {
// FIXME: remove this when we deprecate CROSS_DOCKER_IN_DOCKER.
bool_from_envvar(&value)
} else {
false
};

let enable_doctests = env::var("CROSS_UNSTABLE_ENABLE_DOCTESTS")
.map(|s| bool_from_envvar(&s))
.unwrap_or_default();
Expand Down
18 changes: 8 additions & 10 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ pub fn run(
docker_in_docker: bool,
cwd: &Path,
) -> Result<ExitStatus> {
let engine = get_container_engine()
.map_err(|_| eyre::eyre!("no container engine found"))
.with_suggestion(|| "is docker or podman installed?")?;
let engine_type = get_engine_type(&engine, verbose)?;

let mount_finder = if docker_in_docker {
MountFinder::new(docker_read_mount_paths()?)
MountFinder::new(docker_read_mount_paths(&engine)?)
} else {
MountFinder::default()
};
Expand Down Expand Up @@ -193,11 +198,6 @@ pub fn run(

let runner = config.runner(target)?;

let engine = get_container_engine()
.map_err(|_| eyre::eyre!("no container engine found"))
.with_suggestion(|| "is docker or podman installed?")?;
let engine_type = get_engine_type(&engine, verbose)?;

let mut docker = docker_command(&engine, "run")?;

for ref var in config.env_passthrough(target)? {
Expand Down Expand Up @@ -408,13 +408,11 @@ fn wslpath(path: &Path, verbose: bool) -> Result<PathBuf> {
.map(|s| s.trim().into())
}

fn docker_read_mount_paths() -> Result<Vec<MountDetail>> {
fn docker_read_mount_paths(engine: &Path) -> Result<Vec<MountDetail>> {
let hostname = env::var("HOSTNAME").wrap_err("HOSTNAME environment variable not found")?;

let docker_path = which::which(DOCKER)?;
let mut docker: Command = {
let mut command = Command::new(docker_path);
command.arg("inspect");
let mut command = docker_command(engine, "inspect")?;
command.arg(hostname);
command
};
Expand Down

0 comments on commit aa40461

Please sign in to comment.