From aa40461f9be0c1d777e025c8edec7d155e6aa924 Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Tue, 14 Jun 2022 11:01:06 -0500 Subject: [PATCH] Fix `docker_read_mount_paths` to support podman. 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. --- README.md | 6 +++--- src/cli.rs | 17 ++++++++++++++--- src/docker.rs | 18 ++++++++---------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 763265f36..c4a6600ba 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/cli.rs b/src/cli.rs index e8b5ac0cb..ad8d6fa6a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -133,9 +133,20 @@ pub fn parse(target_list: &TargetList) -> Result { } } - 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(); diff --git a/src/docker.rs b/src/docker.rs index 9b33f87c4..36c4a7609 100644 --- a/src/docker.rs +++ b/src/docker.rs @@ -131,8 +131,13 @@ pub fn run( docker_in_docker: bool, cwd: &Path, ) -> Result { + 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() }; @@ -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)? { @@ -408,13 +408,11 @@ fn wslpath(path: &Path, verbose: bool) -> Result { .map(|s| s.trim().into()) } -fn docker_read_mount_paths() -> Result> { +fn docker_read_mount_paths(engine: &Path) -> Result> { 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 };