Skip to content

Commit

Permalink
it builds!
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Nov 20, 2019
1 parent df9e408 commit 166b398
Show file tree
Hide file tree
Showing 14 changed files with 592 additions and 821 deletions.
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,31 @@ maintenance = { status = "actively-developed" }

[dependencies]
base64 = "0.10"
byteorder = "1.3.1"
bytes = "0.4"
chrono = { version = "0.4", optional = true, features = ["serde"] }
flate2 = "1.0"
futures = "0.1"
futures = "0.3.1"
http = "0.1"
hyper = "0.12"
hyper-openssl = { version = "0.7", optional = true }
hyperlocal = { version = "0.6", optional = true }
hyper = "0.13.0-alpha.4"
hyper-openssl = { version = "0.8.0-alpha.4", optional = true }
#hyperlocal = { version = "0.6", optional = true }
log = "0.4.6"
mime = "0.3.13"
openssl = { version = "0.10", optional = true, features = ["vendored"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tar = "0.4"
tokio = "0.1"
tokio-codec = "0.1"
tokio-io = "0.1"
tokio = "0.2.0-alpha.5"
url = "1.7"
pin-project = "0.4.5"
async-codec = "0.4.0-alpha.2"
futures_codec = "0.3.1"

[dev-dependencies]
env_logger = "0.6"

[features]
default = ["chrono", "unix-socket", "tls"]
unix-socket = ["hyperlocal"]
#default = ["chrono", "unix-socket", "tls"]
default = ["chrono", "tls"]
#unix-socket = ["hyperlocal"]
tls = ["openssl", "hyper-openssl"]
25 changes: 14 additions & 11 deletions examples/containercopyfrom.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
use futures::TryStreamExt;
use shiplift::Docker;
use std::{env, path};
use tokio::prelude::{Future, Stream};

fn main() {
#[tokio::main]
async fn main() {
let docker = Docker::new();
let id = env::args()
.nth(1)
.expect("Usage: cargo run --example containercopyfrom -- <container> <path in container>");
let path = env::args()
.nth(2)
.expect("Usage: cargo run --example containercopyfrom -- <container> <path in container>");
let fut = docker

match docker
.containers()
.get(&id)
.copy_from(path::Path::new(&path))
.collect()
.and_then(|stream| {
let tar = stream.concat();
let mut archive = tar::Archive::new(tar.as_slice());
archive.unpack(env::current_dir()?)?;
.try_concat()
.await
{
Ok(tar) => {
let mut archive = tar::Archive::new(&tar);
archive.unpack(env::current_dir().unwrap()).unwrap();
Ok(())
})
.map_err(|e| eprintln!("Error: {}", e));
tokio::run(fut);
}
Err(e) => eprintln!("Error: {}", e),
}
}
15 changes: 9 additions & 6 deletions examples/containercreate.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use shiplift::{ContainerOptions, Docker};
use std::env;
use tokio::prelude::Future;

fn main() {
#[tokio::main]
async fn main() {
let docker = Docker::new();
let image = env::args()
.nth(1)
.expect("You need to specify an image name");
let fut = docker

match docker
.containers()
.create(&ContainerOptions::builder(image.as_ref()).build())
.map(|info| println!("{:?}", info))
.map_err(|e| eprintln!("Error: {}", e));
tokio::run(fut);
.await
{
Ok(info) => println!("{:?}", info),
Err(e) => eprintln!("Error: {}", e),
}
}
14 changes: 6 additions & 8 deletions examples/containerdelete.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use shiplift::Docker;
use std::env;
use tokio::prelude::Future;

fn main() {
#[tokio::main]
async fn main() {
let docker = Docker::new();
let id = env::args()
.nth(1)
.expect("You need to specify an container id");
let fut = docker
.containers()
.get(&id)
.delete()
.map_err(|e| eprintln!("Error: {}", e));
tokio::run(fut);

if let Err(e) = docker.containers().get(&id).delete().await {
eprintln!("Error: {}", e)
}
}
16 changes: 7 additions & 9 deletions examples/containerinspect.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use shiplift::Docker;
use std::env;
use tokio::prelude::Future;

fn main() {
#[tokio::main]
async fn main() {
let docker = Docker::new();
let id = env::args()
.nth(1)
.expect("Usage: cargo run --example containerinspect -- <container>");
let fut = docker
.containers()
.get(&id)
.inspect()
.map(|container| println!("{:#?}", container))
.map_err(|e| eprintln!("Error: {}", e));
tokio::run(fut);

match docker.containers().get(&id).inspect().await {
Ok(container) => println!("{:#?}", container),
Err(e) => eprintln!("Error: {}", e),
}
}
17 changes: 7 additions & 10 deletions examples/containers.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
use shiplift::Docker;
use tokio::prelude::Future;

fn main() {
#[tokio::main]
async fn main() {
env_logger::init();
let docker = Docker::new();
let fut = docker
.containers()
.list(&Default::default())
.map(|containers| {
match docker.containers().list(&Default::default()).await {
Ok(containers) => {
for c in containers {
println!("container -> {:#?}", c)
}
})
.map_err(|e| eprintln!("Error: {}", e));

tokio::run(fut);
}
Err(e) => eprintln!("Error: {}", e),
}
}
24 changes: 14 additions & 10 deletions examples/imagebuild.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
use futures::StreamExt;
use shiplift::{BuildOptions, Docker};
use std::env;
use tokio::prelude::{Future, Stream};

fn main() {
#[tokio::main]
async fn main() {
let docker = Docker::new();
let path = env::args().nth(1).expect("You need to specify a path");

let fut = docker
match docker
.images()
.build(&BuildOptions::builder(path).tag("shiplift_test").build())
.for_each(|output| {
println!("{:?}", output);
Ok(())
})
.map_err(|e| eprintln!("Error: {}", e));

tokio::run(fut);
{
Ok(output) => {
while let Some(chunk_result) = output.next().await {
match chunk_result {
Ok(output) => println!("{:?}", output),
Err(e) => eprintln!("Error: {}", e),
}
}
}
}
}
17 changes: 7 additions & 10 deletions examples/imagedelete.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
use shiplift::Docker;
use std::env;
use tokio::prelude::Future;

fn main() {
#[tokio::main]
async fn main() {
let docker = Docker::new();
let img = env::args()
.nth(1)
.expect("You need to specify an image name");
let fut = docker
.images()
.get(&img[..])
.delete()
.map(|statuses| {
match docker.images().get(&img).delete().await {
Ok(statuses) => {
for status in statuses {
println!("{:?}", status);
}
})
.map_err(|e| eprintln!("Error: {}", e));
tokio::run(fut);
}
Err(e) => eprintln!("Error: {}", e),
}
}
21 changes: 13 additions & 8 deletions examples/imagepull_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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

fn main() {
#[tokio::main]
async fn main() {
env_logger::init();
let docker = Docker::new();
let img = env::args()
Expand All @@ -16,13 +16,18 @@ fn main() {
.username(username)
.password(password)
.build();
let fut = docker

while let Some(output) = docker
.images()
.pull(&PullOptions::builder().image(img).auth(auth).build())
.for_each(|output| {
println!("{:?}", output);
Ok(())
})
.map_err(|e| eprintln!("Error: {}", e));
.await
{
println!("{:?}", output)
}
.for_each(|output| {
println!("{:?}", output);
Ok(())
})
.map_err(|e| eprintln!("Error: {}", e));
tokio::run(fut);
}
9 changes: 8 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Representations of various client errors

use futures::io::Error as IoError;
use http;
use hyper::{self, StatusCode};
use serde_json::Error as SerdeError;
use std::{error::Error as StdError, fmt, io::Error as IoError, string::FromUtf8Error};
use std::{error::Error as StdError, fmt, string::FromUtf8Error};

#[derive(Debug)]
pub enum Error {
Expand Down Expand Up @@ -41,6 +42,12 @@ impl From<IoError> for Error {
}
}

impl From<FromUtf8Error> for Error {
fn from(error: FromUtf8Error) -> Error {
Error::Encoding(error)
}
}

impl fmt::Display for Error {
fn fmt(
&self,
Expand Down
Loading

0 comments on commit 166b398

Please sign in to comment.