-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_image.rs
More file actions
64 lines (51 loc) · 1.82 KB
/
Copy pathcustom_image.rs
File metadata and controls
64 lines (51 loc) · 1.82 KB
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
//! cargo run --example custom_image
use holm::bundle::{DESKTOP, Extras};
use holm::{Computer, ImageSource, ProfileBuilder, X11Profile};
use std::path::Path;
use std::process::Command;
use std::sync::Arc;
const TAG: &str = "acme-desktop:1";
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("making sure the base image is here …");
let base = Computer::launch().await?;
let base_tag = DESKTOP.tag_with(&Extras::none());
base.shutdown().await?;
let context = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/images/acme");
println!("building {TAG} on {base_tag} …");
let built = Command::new("docker")
.args(["build", "--build-arg"])
.arg(format!("BASE={base_tag}"))
.args(["--tag", TAG])
.arg(&context)
.status()?;
if !built.success() {
return Err("the image did not build".into());
}
let profile = ProfileBuilder::new(X11Profile)
.image(ImageSource::Registry(TAG.to_string()))
.build();
let computer = Computer::builder()
.profile(Arc::new(profile))
.launch()
.await?;
println!("{} is up", computer.name());
if let Some(url) = computer.viewer_url() {
println!(" watch it {url}");
}
let carried = computer.exec(["cat", "/opt/acme/README"]).await?;
println!(" /opt/acme/README: {}", carried.stdout_utf8().trim());
let tools = computer
.exec([
"sh",
"-c",
"for t in htop jq; do printf '%s=%s ' \"$t\" \"$(command -v $t || echo missing)\"; done",
])
.await?;
println!(" tools: {}", tools.stdout_utf8().trim());
let frame = computer.screenshot().await?;
println!(" screenshot: {} bytes", frame.len());
computer.shutdown().await?;
println!("gone");
Ok(())
}