Skip to content

Commit b59cc91

Browse files
committed
Add comprehensive support for remote docker.
This supports the volume-based structure, and uses some nice optimizations to ensure that only the desired toolchain and cargo items are copied over. It also uses drops to ensure scoped deletion of resources, to avoid complex logic ensuring their cleanup. It also supports persistent data volumes, through `cross-util`. In order to setup a persistent data volume, use: ```bash cross-util volumes create ``` This will create a persistent data volume specific for your current toolchain, and will be shared by all targets. This volume is specific for the toolchain version and channel, so a new volume will be created for each toolchain. Make sure you provide your `DOCKER_HOST` or correct engine type to ensure these are being made on the remote host. Then, run your command as before: ```bash CROSS_REMOTE=1 cross build --target arm-unknown-linux-gnueabihf ``` Finally, you can clean up the generated volume using: ```bash cross-util volumes remove ``` A few other utilities are present in `cross-util`: - `volumes list`: list all volumes created by cross. - `volumes remove`: remove all volumes created by cross. - `volumes prune`: prune all volumes unassociated with a container. - `containers list`: list all active containers created by cross. - `containers remove`: remove all active containers created by cross. - `clean`: clean all temporary data (images, containers, volumes, temp data) created by cross. The initial implementation was done by Marc Schreiber, schrieveslaach. A few more environment variables exist to fine-tune performance, as well as handle private dependencies. - `CROSS_REMOTE_COPY_REGISTRY`: copy the cargo registry - `CROSS_REMOTE_COPY_CACHE`: copy cache directories, including the target directory. Both of these generally lead to substantial performance penalties, but can enable the use of private SSH dependencies. In either case, the use of persistent data volumes is highly recommended. Fixes cross-rs#248. Fixes cross-rs#273. Closes cross-rs#449.
1 parent a8358b6 commit b59cc91

21 files changed

+1541
-130
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1212
- #803 - added `CROSS_CUSTOM_TOOLCHAIN` to disable automatic installation of components for use with tools like `cargo-bisect-rustc`
1313
- #795 - added images for additional toolchains maintained by cross-rs.
1414
- #792 - added `CROSS_CONTAINER_IN_CONTAINER` environment variable to replace `CROSS_DOCKER_IN_DOCKER`.
15+
- #785 - added support for remote container engines through data volumes through setting the `CROSS_REMOTE` environment variable. also adds in utility commands to create and remove persistent data volumes.
1516
- #782 - added `build-std` config option, which builds the rust standard library from source if enabled.
1617
- #678 - Add optional `target.{target}.dockerfile[.file]`, `target.{target}.dockerfile.context` and `target.{target}.dockerfile.build-args` to invoke docker/podman build before using an image.
1718
- #678 - Add `target.{target}.pre-build` config for running commands before building the image.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ shell-words = "1.1.0"
4545
const-sha1 = "0.2.0"
4646
ctrlc = { version = "3.2.2", features = ["termination"] }
4747
directories = "4.0.1"
48+
walkdir = { version = "2", optional = true }
4849
tempfile = "3.3.0"
4950

5051
[target.'cfg(not(windows))'.dependencies]

src/bin/commands/clean.rs

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fs;
22

3-
use super::images::RemoveImages;
3+
use super::containers::*;
4+
use super::images::*;
45
use clap::Args;
56

67
#[derive(Args, Debug)]
@@ -31,9 +32,21 @@ impl Clean {
3132
fs::remove_dir_all(tempdir)?;
3233
}
3334
}
34-
false => println!("fs::remove_dir_all({})", tempdir.display()),
35+
false => println!(
36+
"fs::remove_dir_all({})",
37+
cross::pretty_path(&tempdir, |_| false)
38+
),
3539
}
3640

41+
// containers -> images -> volumes -> prune to ensure no conflicts.
42+
let remove_containers = RemoveAllContainers {
43+
verbose: self.verbose,
44+
force: self.force,
45+
execute: self.execute,
46+
engine: None,
47+
};
48+
remove_containers.run(engine.clone())?;
49+
3750
let remove_images = RemoveImages {
3851
targets: vec![],
3952
verbose: self.verbose,
@@ -42,7 +55,22 @@ impl Clean {
4255
execute: self.execute,
4356
engine: None,
4457
};
45-
remove_images.run(engine)?;
58+
remove_images.run(engine.clone())?;
59+
60+
let remove_volumes = RemoveAllVolumes {
61+
verbose: self.verbose,
62+
force: self.force,
63+
execute: self.execute,
64+
engine: None,
65+
};
66+
remove_volumes.run(engine.clone())?;
67+
68+
let prune_volumes = PruneVolumes {
69+
verbose: self.verbose,
70+
execute: self.execute,
71+
engine: None,
72+
};
73+
prune_volumes.run(engine)?;
4674

4775
Ok(())
4876
}

0 commit comments

Comments
 (0)