Skip to content

Commit 683f1db

Browse files
Merge #1054
1054: Allow Persistent Data Volume to be Created Outside of Package r=Emilgardis a=Alexhuszagh This changes the unique container IDs to be based off the toolchain ID, the host target name, the hash of the current working directory, the system time. This means it will be fully unique at the millisecond resolution. This also separated package and toolchain directories. Toolchain directories are the only ones required when creating persistent data volumes, while running cross requires both. There are no backwards incompatible changes, since the persistent data volumes stay the same. Closes #1045. Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
2 parents a11fd20 + 172fc85 commit 683f1db

File tree

5 files changed

+286
-164
lines changed

5 files changed

+286
-164
lines changed

.changes/1054.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "internal",
3+
"description": "change the unique container ID to be unique based off the toolchain and system time."
4+
}

src/bin/commands/containers.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,10 @@ pub fn create_persistent_volume(
395395
if let Some(channel) = channel {
396396
toolchain.channel = channel.channel.clone();
397397
};
398-
let (dirs, metadata) = docker::get_package_info(engine, toolchain.clone(), msg_info)?;
399-
let container =
400-
docker::remote::unique_container_identifier(&toolchain.host().target, &metadata, &dirs)?;
401-
let volume = dirs.toolchain.unique_toolchain_identifier()?;
398+
let mount_finder = docker::MountFinder::create(engine)?;
399+
let dirs = docker::ToolchainDirectories::assemble(&mount_finder, toolchain.clone())?;
400+
let container = dirs.unique_container_identifier(&toolchain.host().target)?;
401+
let volume = dirs.unique_toolchain_identifier()?;
402402

403403
if docker::remote::volume_exists(engine, &volume, msg_info)? {
404404
eyre::bail!("Error: volume {volume} already exists.");
@@ -482,8 +482,9 @@ pub fn remove_persistent_volume(
482482
if let Some(channel) = channel {
483483
toolchain.channel = channel.channel.clone();
484484
};
485-
let (dirs, _) = docker::get_package_info(engine, toolchain, msg_info)?;
486-
let volume = dirs.toolchain.unique_toolchain_identifier()?;
485+
let mount_finder = docker::MountFinder::create(engine)?;
486+
let dirs = docker::ToolchainDirectories::assemble(&mount_finder, toolchain)?;
487+
let volume = dirs.unique_toolchain_identifier()?;
487488

488489
if !docker::remote::volume_exists(engine, &volume, msg_info)? {
489490
eyre::bail!("Error: volume {volume} does not exist.");

src/docker/local.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ pub(crate) fn run(
2626
msg_info: &mut MessageInfo,
2727
) -> Result<ExitStatus> {
2828
let engine = &options.engine;
29-
let dirs = &paths.directories;
29+
let toolchain_dirs = paths.directories.toolchain_directories();
30+
let package_dirs = paths.directories.package_directories();
3031

3132
let mut cmd = cargo_safe_command(options.cargo_variant);
3233
cmd.args(args);
@@ -38,7 +39,7 @@ pub(crate) fn run(
3839
.image
3940
.platform
4041
.specify_platform(&options.engine, &mut docker);
41-
docker_envvars(&mut docker, &options, dirs, msg_info)?;
42+
docker_envvars(&mut docker, &options, toolchain_dirs, msg_info)?;
4243

4344
docker_mount(
4445
&mut docker,
@@ -57,33 +58,48 @@ pub(crate) fn run(
5758
docker
5859
.args([
5960
"-v",
60-
&format!("{}:{}:z", dirs.xargo.to_utf8()?, dirs.xargo_mount_path()),
61+
&format!(
62+
"{}:{}:z",
63+
toolchain_dirs.xargo_host_path()?,
64+
toolchain_dirs.xargo_mount_path()
65+
),
6166
])
6267
.args([
6368
"-v",
64-
&format!("{}:{}:z", dirs.cargo.to_utf8()?, dirs.cargo_mount_path()),
69+
&format!(
70+
"{}:{}:z",
71+
toolchain_dirs.cargo_host_path()?,
72+
toolchain_dirs.cargo_mount_path()
73+
),
6574
])
6675
// Prevent `bin` from being mounted inside the Docker container.
67-
.args(["-v", &format!("{}/bin", dirs.cargo_mount_path())]);
76+
.args(["-v", &format!("{}/bin", toolchain_dirs.cargo_mount_path())]);
6877
docker.args([
6978
"-v",
70-
&format!("{}:{}:z", dirs.host_root.to_utf8()?, dirs.mount_root),
79+
&format!(
80+
"{}:{}:z",
81+
package_dirs.host_root().to_utf8()?,
82+
package_dirs.mount_root()
83+
),
7184
]);
7285
docker
7386
.args([
7487
"-v",
7588
&format!(
7689
"{}:{}:z,ro",
77-
dirs.get_sysroot().to_utf8()?,
78-
dirs.sysroot_mount_path()
90+
toolchain_dirs.get_sysroot().to_utf8()?,
91+
toolchain_dirs.sysroot_mount_path()
7992
),
8093
])
81-
.args(["-v", &format!("{}:/target:z", dirs.target.to_utf8()?)]);
94+
.args([
95+
"-v",
96+
&format!("{}:/target:z", package_dirs.target().to_utf8()?),
97+
]);
8298
docker_cwd(&mut docker, &paths)?;
8399

84100
// When running inside NixOS or using Nix packaging we need to add the Nix
85101
// Store to the running container so it can load the needed binaries.
86-
if let Some(ref nix_store) = dirs.nix_store {
102+
if let Some(nix_store) = toolchain_dirs.nix_store() {
87103
docker.args([
88104
"-v",
89105
&format!(
@@ -106,7 +122,7 @@ pub(crate) fn run(
106122

107123
docker
108124
.arg(&image_name)
109-
.args(["sh", "-c", &build_command(dirs, &cmd)])
125+
.args(["sh", "-c", &build_command(toolchain_dirs, &cmd)])
110126
.run_and_get_status(msg_info, false)
111127
.map_err(Into::into)
112128
}

0 commit comments

Comments
 (0)