Skip to content

create CACHEDIR.TAG during custom docker build #1325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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