From 49111e62037359a97c6ea92a7dc8206d776ecc3c Mon Sep 17 00:00:00 2001 From: Vladyslav Aleksashyn Date: Thu, 31 Aug 2023 11:52:24 +0200 Subject: [PATCH] create CACHEDIR.TAG during custom docker build --- .changes/1325.json | 5 +++++ src/docker/custom.rs | 12 ++++++++---- src/docker/shared.rs | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 .changes/1325.json diff --git a/.changes/1325.json b/.changes/1325.json new file mode 100644 index 000000000..5c00fa8ad --- /dev/null +++ b/.changes/1325.json @@ -0,0 +1,5 @@ +{ + "description": "create CACHEDIR.TAG during custom docker build", + "type": "fixed", + "issues": [1324] +} diff --git a/src/docker/custom.rs b/src/docker/custom.rs index d71825710..a58b2370c 100644 --- a/src/docker/custom.rs +++ b/src/docker/custom.rs @@ -7,7 +7,10 @@ use crate::shell::MessageInfo; use crate::{errors::*, file, CommandExt, ToUtf8}; use crate::{CargoMetadata, TargetTriple}; -use super::{get_image_name, path_hash, BuildCommandExt, BuildResultExt, Engine, ImagePlatform}; +use super::{ + create_target_dir, get_image_name, path_hash, BuildCommandExt, BuildResultExt, Engine, + ImagePlatform, +}; pub const CROSS_CUSTOM_DOCKERFILE_IMAGE_PREFIX: &str = "localhost/cross-rs/cross-custom-"; @@ -119,11 +122,12 @@ impl<'a> Dockerfile<'a> { let path = match self { Dockerfile::File { path, .. } => PathBuf::from(path), Dockerfile::Custom { content, .. } => { - let path = paths + let target_dir = paths .metadata .target_directory - .join(options.target.to_string()) - .join(format!("Dockerfile.{}-custom", &options.target)); + .join(options.target.to_string()); + create_target_dir(&target_dir)?; + let path = target_dir.join(format!("Dockerfile.{}-custom", &options.target)); { let mut file = file::write_file(&path, true)?; file.write_all(content.as_bytes())?; diff --git a/src/docker/shared.rs b/src/docker/shared.rs index 83ec3bfc9..efe1e332e 100644 --- a/src/docker/shared.rs +++ b/src/docker/shared.rs @@ -819,7 +819,7 @@ const CACHEDIR_TAG: &str = "Signature: 8a477f597d28d172789f06886806bc55 # This file is a cache directory tag created by cross. # For information about cache directory tags see https://bford.info/cachedir/"; -fn create_target_dir(path: &Path) -> Result<()> { +pub fn create_target_dir(path: &Path) -> Result<()> { // cargo creates all paths to the target directory, and writes // a cache dir tag only if the path doesn't previously exist. if !path.exists() {