Skip to content

Commit 83f487e

Browse files
committed
Allow Persistent Data Volume to be Created Outside of Package
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.
1 parent ba06b09 commit 83f487e

File tree

5 files changed

+304
-145
lines changed

5 files changed

+304
-145
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ pub(crate) fn run(
5757
docker
5858
.args([
5959
"-v",
60-
&format!("{}:{}:z", dirs.xargo.to_utf8()?, dirs.xargo_mount_path()),
60+
&format!("{}:{}:z", dirs.xargo_host_path()?, dirs.xargo_mount_path()),
6161
])
6262
.args([
6363
"-v",
64-
&format!("{}:{}:z", dirs.cargo.to_utf8()?, dirs.cargo_mount_path()),
64+
&format!("{}:{}:z", dirs.cargo_host_path()?, dirs.cargo_mount_path()),
6565
])
6666
// Prevent `bin` from being mounted inside the Docker container.
6767
.args(["-v", &format!("{}/bin", dirs.cargo_mount_path())]);
6868
docker.args([
6969
"-v",
70-
&format!("{}:{}:z", dirs.host_root.to_utf8()?, dirs.mount_root),
70+
&format!("{}:{}:z", dirs.host_root().to_utf8()?, dirs.mount_root()),
7171
]);
7272
docker
7373
.args([
@@ -78,12 +78,12 @@ pub(crate) fn run(
7878
dirs.sysroot_mount_path()
7979
),
8080
])
81-
.args(["-v", &format!("{}:/target:z", dirs.target.to_utf8()?)]);
81+
.args(["-v", &format!("{}:/target:z", dirs.target().to_utf8()?)]);
8282
docker_cwd(&mut docker, &paths)?;
8383

8484
// When running inside NixOS or using Nix packaging we need to add the Nix
8585
// Store to the running container so it can load the needed binaries.
86-
if let Some(ref nix_store) = dirs.nix_store {
86+
if let Some(nix_store) = dirs.nix_store() {
8787
docker.args([
8888
"-v",
8989
&format!(

0 commit comments

Comments
 (0)