-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdind.rs
50 lines (43 loc) · 1.21 KB
/
dind.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
/// Docker-in-docker structures
use anyhow::Error;
use std::path;
use crate::command::{DaemonHandle, DockerCommandBuilder};
use crate::image::{image_exists_locally, pull_image};
pub const DEFAULT_DIND_IMAGE: &str = "docker:dind";
#[derive(Debug)]
pub struct Dind {
command: DockerCommandBuilder,
}
impl Dind {
pub fn new(image: &str, mount: (&path::PathBuf, &path::PathBuf)) -> Self {
Dind {
command: DockerCommandBuilder::new(image)
.add_docker_switch("--privileged")
.add_volume(mount),
}
}
pub fn name(&self) -> &str {
self.command.name()
}
pub fn launch(self) -> Result<DaemonHandle, Error> {
info!(
"Starting docker:dind container with name {}",
self.command.name()
);
let handle = self.command.start_as_daemon(&[
"dockerd",
"--tls=false",
"--host=tcp://0.0.0.0:2375",
])?;
info!("docker:dind launched");
Ok(handle)
}
}
/// Check the docker dind image is available
pub fn dind_preflight(image: &str) -> Result<(), Error> {
if image_exists_locally(image)? {
Ok(())
} else {
pull_image(image)
}
}