forked from fussybeaver/bollard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_dockerfile.rs
36 lines (28 loc) · 977 Bytes
/
post_dockerfile.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
//! Post a dockerfile
//!
//! tar cvf dockerfile.tar Dockerfile
use bollard::image::BuildImageOptions;
use bollard::Docker;
use futures_util::stream::StreamExt;
use hyper::body::Body;
use tokio::fs::File;
use tokio_util::codec::{BytesCodec, FramedRead};
use std::env::args;
#[tokio::main]
async fn main() {
let docker = Docker::connect_with_socket_defaults().unwrap();
let image_options = BuildImageOptions {
dockerfile: "Dockerfile",
t: "rust-test",
rm: true,
..Default::default()
};
let filename = &args().nth(1).expect("needs first argument");
let archive = File::open(filename).await.expect("could not open file");
let stream = FramedRead::new(archive, BytesCodec::new());
let body = Body::wrap_stream(stream);
let mut image_build_stream = docker.build_image(image_options, None, Some(body));
while let Some(msg) = image_build_stream.next().await {
println!("Message: {:?}", msg);
}
}