Skip to content

Commit d6511b7

Browse files
bors[bot]vaffeine
andauthored
Merge #1325
1325: create CACHEDIR.TAG during custom docker build r=Emilgardis a=vaffeine Closes #1324. Co-authored-by: Vladyslav Aleksashyn <[email protected]>
2 parents a599f20 + 49111e6 commit d6511b7

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

.changes/1325.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"description": "create CACHEDIR.TAG during custom docker build",
3+
"type": "fixed",
4+
"issues": [1324]
5+
}

src/docker/custom.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use crate::shell::MessageInfo;
77
use crate::{errors::*, file, CommandExt, ToUtf8};
88
use crate::{CargoMetadata, TargetTriple};
99

10-
use super::{get_image_name, path_hash, BuildCommandExt, BuildResultExt, Engine, ImagePlatform};
10+
use super::{
11+
create_target_dir, get_image_name, path_hash, BuildCommandExt, BuildResultExt, Engine,
12+
ImagePlatform,
13+
};
1114

1215
pub const CROSS_CUSTOM_DOCKERFILE_IMAGE_PREFIX: &str = "localhost/cross-rs/cross-custom-";
1316

@@ -119,11 +122,12 @@ impl<'a> Dockerfile<'a> {
119122
let path = match self {
120123
Dockerfile::File { path, .. } => PathBuf::from(path),
121124
Dockerfile::Custom { content, .. } => {
122-
let path = paths
125+
let target_dir = paths
123126
.metadata
124127
.target_directory
125-
.join(options.target.to_string())
126-
.join(format!("Dockerfile.{}-custom", &options.target));
128+
.join(options.target.to_string());
129+
create_target_dir(&target_dir)?;
130+
let path = target_dir.join(format!("Dockerfile.{}-custom", &options.target));
127131
{
128132
let mut file = file::write_file(&path, true)?;
129133
file.write_all(content.as_bytes())?;

src/docker/shared.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ const CACHEDIR_TAG: &str = "Signature: 8a477f597d28d172789f06886806bc55
819819
# This file is a cache directory tag created by cross.
820820
# For information about cache directory tags see https://bford.info/cachedir/";
821821

822-
fn create_target_dir(path: &Path) -> Result<()> {
822+
pub fn create_target_dir(path: &Path) -> Result<()> {
823823
// cargo creates all paths to the target directory, and writes
824824
// a cache dir tag only if the path doesn't previously exist.
825825
if !path.exists() {

0 commit comments

Comments
 (0)