summaryrefslogtreecommitdiffstats
path: root/examples/imagepull_auth.rs
blob: 1c559c79cf169c8a480b0361e05bf607ce781424 (plain)
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
// cargo run --example imagepull_auth busybox username password

use shiplift::{Docker, PullOptions, RegistryAuth};
use std::env;
use tokio::prelude::{Future, Stream};

fn main() {
    env_logger::init();
    let docker = Docker::new();
    let img = env::args()
        .nth(1)
        .expect("You need to specify an image name");
    let username = env::args().nth(2).expect("You need to specify an username");
    let password = env::args().nth(3).expect("You need to specify a password");
    let auth = RegistryAuth::builder()
        .username(username)
        .password(password)
        .build();
    let fut = docker
        .images()
        .pull(&PullOptions::builder().image(img).auth(auth).build())
        .for_each(|output| {
            println!("{:?}", output);
            Ok(())
        })
        .map_err(|e| eprintln!("Error: {}", e));
    tokio::run(fut);
}