Skip to content

Commit 90e44e6

Browse files
Merge #785
785: Add comprehensive support for remote docker. r=Emilgardis a=Alexhuszagh 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 #248. Fixes #273. Closes #449. Co-authored-by: Alex Huszagh <[email protected]>
2 parents 7d5a8b2 + 18011f5 commit 90e44e6

26 files changed

+2142
-137
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.lock

+111
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ serde_json = "1"
4343
serde_ignored = "0.1.2"
4444
shell-words = "1.1.0"
4545
const-sha1 = "0.2.0"
46+
ctrlc = { version = "3.2.2", features = ["termination"] }
47+
directories = "4.0.1"
48+
walkdir = { version = "2", optional = true }
49+
tempfile = "3.3.0"
4650

4751
[target.'cfg(not(windows))'.dependencies]
4852
nix = { version = "0.24", default-features = false, features = ["user"] }

src/bin/commands/clean.rs

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use std::fs;
2+
3+
use super::containers::*;
4+
use super::images::*;
5+
use clap::Args;
6+
7+
#[derive(Args, Debug)]
8+
pub struct Clean {
9+
/// Provide verbose diagnostic output.
10+
#[clap(short, long)]
11+
pub verbose: bool,
12+
/// Force removal of images.
13+
#[clap(short, long)]
14+
pub force: bool,
15+
/// Remove local (development) images.
16+
#[clap(short, long)]
17+
pub local: bool,
18+
/// Remove images. Default is a dry run.
19+
#[clap(short, long)]
20+
pub execute: bool,
21+
/// Container engine (such as docker or podman).
22+
#[clap(long)]
23+
pub engine: Option<String>,
24+
}
25+
26+
impl Clean {
27+
pub fn run(self, engine: cross::docker::Engine) -> cross::Result<()> {
28+
let tempdir = cross::temp::dir()?;
29+
match self.execute {
30+
true => {
31+
if tempdir.exists() {
32+
fs::remove_dir_all(tempdir)?;
33+
}
34+
}
35+
false => println!(
36+
"fs::remove_dir_all({})",
37+
cross::pretty_path(&tempdir, |_| false)
38+
),
39+
}
40+
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+
50+
let remove_images = RemoveImages {
51+
targets: vec![],
52+
verbose: self.verbose,
53+
force: self.force,
54+
local: self.local,
55+
execute: self.execute,
56+
engine: None,
57+
};
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)?;
74+
75+
Ok(())
76+
}
77+
}

0 commit comments

Comments
 (0)