-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbusybox.rs
68 lines (47 loc) · 1.71 KB
/
busybox.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#[path = "example_utils/lib.rs"]
mod example_utils;
use std::iter::FromIterator;
use std::process::ExitCode;
use log::*;
use passivized_docker_engine_client::DockerEngineClient;
use passivized_docker_engine_client::requests::{CreateContainerRequest, WaitCondition};
use passivized_test_support::cli;
use example_utils::errors::ExampleError;
const IMAGE_NAME: &str = "busybox";
#[tokio::main]
async fn main() -> ExitCode {
cli::run(run).await
}
/// Run the BusyBox container with a file listing command, and get the file listing.
async fn run() -> Result<(), ExampleError> {
let dec = DockerEngineClient::new()?;
info!("Connecting to {}", dec);
info!("Pulling image");
let pull_result = dec.images().pull_if_not_present(IMAGE_NAME, "latest")
.await?;
info!("Pull result: {}", pull_result);
let create_request = CreateContainerRequest::default()
.image(IMAGE_NAME)
.cmd(vec!["ls", "-l"]);
info!("Creating container");
let container = dec.containers().create(create_request)
.await?;
info!("Created container with id {}", container.id);
for w in &container.warnings {
info!("Container warning: {}", w)
}
dec.container(&container.id).start()
.await?;
info!("Waiting for container {} to stop", container.id);
dec.container(&container.id).wait(WaitCondition::NotRunning)
.await?;
info!("Getting logs of {}", container.id);
let logs = dec.container(&container.id).logs()
.await?;
let log = String::from_iter(logs.iter().map(|entry| entry.text.clone()));
info!("\n{}", log);
info!("Removing container {}", container.id);
dec.container(&container.id).remove()
.await?;
Ok(())
}