diff --git a/.changes/934.json b/.changes/934.json new file mode 100644 index 000000000..caf25ade1 --- /dev/null +++ b/.changes/934.json @@ -0,0 +1,5 @@ +{ + "type": "added", + "description": "add support for pre-build hooks with remote docker", + "issues": [928] +} diff --git a/src/docker/remote.rs b/src/docker/remote.rs index b4cc21dc5..c42dd3a72 100644 --- a/src/docker/remote.rs +++ b/src/docker/remote.rs @@ -943,7 +943,14 @@ pub(crate) fn run( docker.arg("-t"); } - docker.arg(&image_name(&options.config, target)?); + let mut image = options.image_name()?; + if options.needs_custom_image() { + image = options + .custom_image_build(&paths, msg_info) + .wrap_err("when building custom image")?; + } + + docker.arg(&image); if !is_tty { // ensure the process never exits until we stop it // we only need this infinite loop if we don't allocate diff --git a/src/docker/shared.rs b/src/docker/shared.rs index be23bb54b..586a0bc59 100644 --- a/src/docker/shared.rs +++ b/src/docker/shared.rs @@ -74,7 +74,7 @@ impl DockerOptions { paths: &DockerPaths, msg_info: &mut MessageInfo, ) -> Result { - let mut image = image_name(&self.config, &self.target)?; + let mut image = self.image_name()?; if let Some(path) = self.config.dockerfile(&self.target)? { let context = self.config.dockerfile_context(&self.target)?; @@ -167,28 +167,7 @@ impl DockerOptions { } pub(crate) fn image_name(&self) -> Result { - if let Some(image) = self.config.image(&self.target)? { - return Ok(image); - } - - if !DOCKER_IMAGES.contains(&self.target.triple()) { - eyre::bail!( - "`cross` does not provide a Docker image for target {target}, \ - specify a custom image in `Cross.toml`.", - target = self.target - ); - } - - let version = if include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt")).is_empty() { - env!("CARGO_PKG_VERSION") - } else { - "main" - }; - - Ok(format!( - "{CROSS_IMAGE}/{target}:{version}", - target = self.target - )) + image_name(&self.config, &self.target) } }