Skip to content

Commit

Permalink
Merge #1325
Browse files Browse the repository at this point in the history
1325: create CACHEDIR.TAG during custom docker build r=Emilgardis a=vaffeine

Closes #1324.

Co-authored-by: Vladyslav Aleksashyn <vaffeine@users.noreply.github.com>
  • Loading branch information
bors[bot] and vaffeine committed Sep 8, 2023
2 parents a599f20 + 49111e6 commit d6511b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/1325.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "create CACHEDIR.TAG during custom docker build",
"type": "fixed",
"issues": [1324]
}
12 changes: 8 additions & 4 deletions src/docker/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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-";

Expand Down Expand Up @@ -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())?;
Expand Down
2 changes: 1 addition & 1 deletion src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit d6511b7

Please sign in to comment.