Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hyper #191

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 0.6.0

* async-await support [#191](https://github.com/softprops/shiplift/pull/191)
* add chrono as an optional feature [#190](https://github.com/softprops/shiplift/pull/190)

# 0.5.0
Expand Down
46 changes: 24 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "shiplift"
version = "0.5.1"
version = "0.6.0"
authors = ["softprops <d.tangren@gmail.com>"]
description = "A Rust interface for maneuvering Docker containers"
documentation = "https://docs.rs/shiplift"
Expand All @@ -18,29 +18,31 @@ coveralls = { repository = "softprops/shipflit" }
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"
http = "0.1"
hyper = "0.12"
hyper-openssl = { version = "0.7", 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"
url = "1.7"
base64 = "0.11.0"
bytes = "0.4.12"
chrono = { version = "0.4.9", optional = true, features = ["serde"] }
flate2 = "1.0.13"
http = "0.1.19"
hyper = "0.13.0-alpha.4"
hyper-openssl = { version = "0.8.0-alpha.4", optional = true }
hyperlocal = { git="https://github.com/danieleades/hyperlocal", branch="update-hyper", optional = true }
log = "0.4.8"
mime = "0.3.14"
openssl = { version = "0.10.25", optional = true, features = ["vendored"] }
serde = { version = "1.0.102", features = ["derive"] }
danieleades marked this conversation as resolved.
Show resolved Hide resolved
serde_json = "1.0.41"
tar = "0.4.26"
url = "2.1.0"
futures_codec = "0.3.1"
futures-util = "0.3.1"
pin-project = "0.4.6"
tokio-io = "0.2.0-alpha.6"


[dev-dependencies]
env_logger = "0.6"
env_logger = "0.7.1"
futures = "0.3.1"
tokio = "0.2.0-alpha.6"

[features]
default = ["chrono", "unix-socket", "tls"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Add the following to your `Cargo.toml` file

```toml
[dependencies]
shiplift = "0.5"
shiplift = "0.6"
```

## usage
Expand Down
32 changes: 32 additions & 0 deletions examples/attach.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use futures::StreamExt;
use shiplift::{tty::TtyChunk, Docker};
use std::env;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let docker = Docker::new();
let id = env::args()
.nth(1)
.expect("You need to specify a container id");

let tty_multiplexer = docker.containers().get(&id).attach().await?;

let (mut reader, _writer) = tty_multiplexer.split();

while let Some(tty_result) = reader.next().await {
match tty_result {
Ok(chunk) => print_chunk(chunk),
Err(e) => eprintln!("Error: {}", e),
}
}

Ok(())
}

fn print_chunk(chunk: TtyChunk) {
match chunk {
TtyChunk::StdOut(bytes) => println!("Stdout: {}", std::str::from_utf8(&bytes).unwrap()),
TtyChunk::StdErr(bytes) => eprintln!("Stdout: {}", std::str::from_utf8(&bytes).unwrap()),
TtyChunk::StdIn(_) => unreachable!(),
}
}
25 changes: 13 additions & 12 deletions examples/containercopyfrom.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
use futures::TryStreamExt;
use shiplift::Docker;
use std::{env, path};
use tokio::prelude::{Future, Stream};
use tar::Archive;

fn main() {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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

let bytes = 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()?)?;
Ok(())
})
.map_err(|e| eprintln!("Error: {}", e));
tokio::run(fut);
.try_concat()
.await?;

let mut archive = Archive::new(&bytes[..]);
archive.unpack(env::current_dir()?)?;

Ok(())
}
18 changes: 9 additions & 9 deletions examples/containercopyinto.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use shiplift::Docker;
use std::env;
use tokio::prelude::Future;
use std::{env, fs::File, io::Read};

fn main() {
#[tokio::main]
async fn main() {
let docker = Docker::new();
let path = env::args()
.nth(1)
Expand All @@ -11,17 +11,17 @@ fn main() {
.nth(2)
.expect("Usage: cargo run --example containercopyinto -- <local path> <container>");

use std::{fs::File, io::prelude::*};

let mut file = File::open(&path).unwrap();
let mut bytes = Vec::new();
file.read_to_end(&mut bytes)
.expect("Cannot read file on the localhost.");

let fut = docker
if let Err(e) = docker
danieleades marked this conversation as resolved.
Show resolved Hide resolved
.containers()
.get(&id)
.copy_file_into(path, &bytes[..])
.map_err(|e| eprintln!("Error: {}", e));
tokio::run(fut);
.copy_file_into(path, &bytes)
.await
{
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)
}
}
37 changes: 19 additions & 18 deletions examples/containerexec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use shiplift::{tty::StreamType, Docker, ExecContainerOptions};
use std::env;
use tokio::prelude::{Future, Stream};
use futures::StreamExt;
use shiplift::{tty::TtyChunk, Docker, ExecContainerOptions};
use std::{env, str::from_utf8};

fn main() {
#[tokio::main]
async fn main() {
let docker = Docker::new();
let id = env::args()
.nth(1)
Expand All @@ -18,19 +19,19 @@ fn main() {
.attach_stdout(true)
.attach_stderr(true)
.build();
let fut = docker
.containers()
.get(&id)
.exec(&options)
.for_each(|chunk| {
match chunk.stream_type {
StreamType::StdOut => println!("Stdout: {}", chunk.as_string_lossy()),
StreamType::StdErr => eprintln!("Stderr: {}", chunk.as_string_lossy()),
StreamType::StdIn => unreachable!(),
}
Ok(())
})
.map_err(|e| eprintln!("Error: {}", e));

tokio::run(fut);
while let Some(exec_result) = docker.containers().get(&id).exec(&options).next().await {
match exec_result {
Ok(chunk) => print_chunk(chunk),
Err(e) => eprintln!("Error: {}", e),
}
}
}

fn print_chunk(chunk: TtyChunk) {
match chunk {
TtyChunk::StdOut(bytes) => println!("Stdout: {}", from_utf8(&bytes).unwrap()),
TtyChunk::StdErr(bytes) => eprintln!("Stdout: {}", from_utf8(&bytes).unwrap()),
TtyChunk::StdIn(_) => unreachable!(),
}
}
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),
}
}
19 changes: 9 additions & 10 deletions examples/events.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use futures::StreamExt;
use shiplift::Docker;
use tokio::prelude::{Future, Stream};

fn main() {
#[tokio::main]
async fn main() {
let docker = Docker::new();
println!("listening for events");

let fut = docker
.events(&Default::default())
.for_each(|e| {
println!("event -> {:?}", e);
Ok(())
})
.map_err(|e| eprintln!("Error: {}", e));
tokio::run(fut);
while let Some(event_result) = docker.events(&Default::default()).next().await {
match event_result {
Ok(event) => println!("event -> {:?}", event),
Err(e) => eprintln!("Error: {}", e),
}
}
}
23 changes: 10 additions & 13 deletions examples/export.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use futures::StreamExt;
use shiplift::{errors::Error, Docker};
use std::{env, fs::OpenOptions, io::Write};
use tokio::prelude::{Future, Stream};

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

Expand All @@ -11,17 +12,13 @@ fn main() {
.create(true)
.open(format!("{}.tar", &id))
.unwrap();

let images = docker.images();
let fut = images
.get(&id)
.export()
.for_each(move |bytes| {
export_file
.write(&bytes[..])
.map(|n| println!("copied {} bytes", n))
.map_err(Error::IO)
})
.map_err(|e| eprintln!("Error: {}", e));

tokio::run(fut)
while let Some(export_result) = images.get(&id).export().next().await {
match export_result.and_then(|bytes| export_file.write(&bytes).map_err(Error::from)) {
Ok(n) => println!("copied {} bytes", n),
Err(e) => eprintln!("Error: {}", e),
}
}
}
Loading