Skip to content
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

Add comprehensive support for remote docker. #785

Merged
merged 4 commits into from
Jun 23, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #803 - added `CROSS_CUSTOM_TOOLCHAIN` to disable automatic installation of components for use with tools like `cargo-bisect-rustc`
- #795 - added images for additional toolchains maintained by cross-rs.
- #792 - added `CROSS_CONTAINER_IN_CONTAINER` environment variable to replace `CROSS_DOCKER_IN_DOCKER`.
- #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.
- #782 - added `build-std` config option, which builds the rust standard library from source if enabled.
- #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.
- #678 - Add `target.{target}.pre-build` config for running commands before building the image.
Expand Down
111 changes: 111 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ serde_json = "1"
serde_ignored = "0.1.2"
shell-words = "1.1.0"
const-sha1 = "0.2.0"
ctrlc = { version = "3.2.2", features = ["termination"] }
directories = "4.0.1"
walkdir = { version = "2", optional = true }
tempfile = "3.3.0"

[target.'cfg(not(windows))'.dependencies]
nix = { version = "0.24", default-features = false, features = ["user"] }
Expand Down
77 changes: 77 additions & 0 deletions src/bin/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use std::fs;

use super::containers::*;
use super::images::*;
use clap::Args;

#[derive(Args, Debug)]
pub struct Clean {
/// Provide verbose diagnostic output.
#[clap(short, long)]
pub verbose: bool,
/// Force removal of images.
#[clap(short, long)]
pub force: bool,
/// Remove local (development) images.
#[clap(short, long)]
pub local: bool,
/// Remove images. Default is a dry run.
#[clap(short, long)]
pub execute: bool,
Alexhuszagh marked this conversation as resolved.
Show resolved Hide resolved
/// Container engine (such as docker or podman).
#[clap(long)]
pub engine: Option<String>,
}

impl Clean {
pub fn run(self, engine: cross::docker::Engine) -> cross::Result<()> {
let tempdir = cross::temp::dir()?;
match self.execute {
true => {
if tempdir.exists() {
fs::remove_dir_all(tempdir)?;
}
}
false => println!(
"fs::remove_dir_all({})",
cross::pretty_path(&tempdir, |_| false)
),
}

// containers -> images -> volumes -> prune to ensure no conflicts.
let remove_containers = RemoveAllContainers {
verbose: self.verbose,
force: self.force,
execute: self.execute,
engine: None,
};
remove_containers.run(engine.clone())?;

let remove_images = RemoveImages {
targets: vec![],
verbose: self.verbose,
force: self.force,
local: self.local,
execute: self.execute,
engine: None,
};
remove_images.run(engine.clone())?;

let remove_volumes = RemoveAllVolumes {
verbose: self.verbose,
force: self.force,
execute: self.execute,
engine: None,
};
remove_volumes.run(engine.clone())?;

let prune_volumes = PruneVolumes {
verbose: self.verbose,
execute: self.execute,
engine: None,
};
prune_volumes.run(engine)?;

Ok(())
}
}
Loading