Skip to content

Commit c8bb213

Browse files
Merge #934
934: Add support for pre-build hooks with remote docker. r=Emilgardis a=Alexhuszagh Closes #928. Co-authored-by: Alex Huszagh <[email protected]>
2 parents 635bd70 + 0ffbff7 commit c8bb213

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

.changes/934.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "added",
3+
"description": "add support for pre-build hooks with remote docker",
4+
"issues": [928]
5+
}

src/docker/remote.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,14 @@ pub(crate) fn run(
943943
docker.arg("-t");
944944
}
945945

946-
docker.arg(&image_name(&options.config, target)?);
946+
let mut image = options.image_name()?;
947+
if options.needs_custom_image() {
948+
image = options
949+
.custom_image_build(&paths, msg_info)
950+
.wrap_err("when building custom image")?;
951+
}
952+
953+
docker.arg(&image);
947954
if !is_tty {
948955
// ensure the process never exits until we stop it
949956
// we only need this infinite loop if we don't allocate

src/docker/shared.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl DockerOptions {
7474
paths: &DockerPaths,
7575
msg_info: &mut MessageInfo,
7676
) -> Result<String> {
77-
let mut image = image_name(&self.config, &self.target)?;
77+
let mut image = self.image_name()?;
7878

7979
if let Some(path) = self.config.dockerfile(&self.target)? {
8080
let context = self.config.dockerfile_context(&self.target)?;
@@ -167,28 +167,7 @@ impl DockerOptions {
167167
}
168168

169169
pub(crate) fn image_name(&self) -> Result<String> {
170-
if let Some(image) = self.config.image(&self.target)? {
171-
return Ok(image);
172-
}
173-
174-
if !DOCKER_IMAGES.contains(&self.target.triple()) {
175-
eyre::bail!(
176-
"`cross` does not provide a Docker image for target {target}, \
177-
specify a custom image in `Cross.toml`.",
178-
target = self.target
179-
);
180-
}
181-
182-
let version = if include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt")).is_empty() {
183-
env!("CARGO_PKG_VERSION")
184-
} else {
185-
"main"
186-
};
187-
188-
Ok(format!(
189-
"{CROSS_IMAGE}/{target}:{version}",
190-
target = self.target
191-
))
170+
image_name(&self.config, &self.target)
192171
}
193172
}
194173

0 commit comments

Comments
 (0)