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

Disable named pipes, upgrade tokio to 1.0 #140

Merged
merged 9 commits into from
Feb 25, 2021
Merged
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
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,40 @@ ssl = ["hyper-rustls", "rustls", "rustls-native-certs", "webpki-roots"]
[dependencies]
base64 = "0.12.3"
bollard-stubs = { version = "1.40.6" }
bytes = "0.5.5"
bytes = "1"
chrono = { version = "0.4.11", features = ["serde"] }
ct-logs = "0.7.0"
dirs-next = "1.0.2"
futures-core = "0.3.4"
futures-util = "0.3.4"
hex = "0.4.2"
http = "0.2.1"
hyper = "0.13.6"
hyper-rustls = { version = "0.21.0", optional = true }
hyper = { version = "0.14.2", features = ["client", "tcp", "http1", "http2", "stream"] }
hyper-rustls = { version = "0.22.1", optional = true }
log = "0.4.8"
pin-project = "0.4.22"
rustls = { version = "0.18.0", optional = true }
rustls-native-certs = { version = "0.4.0", optional = true }
pin-project = "1.0.2"
rustls = { version = "0.19", optional = true }
rustls-native-certs = { version = "0.5.0", optional = true }
serde = "1.0.114"
serde_derive = "1.0.114"
serde_json = "1.0.55"
serde_urlencoded = "0.6.1"
tokio = { version = "0.2.17", features = ["time", "fs"] }
tokio = { version = "1.0", features = ["time", "fs", "net", "rt", "rt-multi-thread"] }
thiserror = "1.0"
tokio-util = { version = "0.3.1", features = ["codec"] }
tokio-util = { version = "0.6.2", features = ["codec"] }
url = "2.1.1"
webpki-roots = { version = "0.20.0", optional = true }

[dev-dependencies]
env_logger = "0.7.1"
flate2 = "1.0.14"
tar = "0.4.29"
tokio = { version = "1.0", features = ["time", "fs", "net", "rt", "rt-multi-thread", "macros"] }

[target.'cfg(unix)'.dependencies]
hyperlocal = { version = "0.1.5", package = "hyper-unix-connector" }
hyperlocal = { version = "0.2.2", package = "hyper-unix-connector" }

[target.'cfg(windows)'.dependencies]
mio-named-pipes = "0.1.6"
winapi = "0.3.9"

[package.metadata.docs.rs]
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Bollard leverages the latest [Hyper](https://github.com/hyperium/hyper) and
[Tokio](https://github.com/tokio-rs/tokio) improvements for an asynchronous API containing
futures, streams and the async/await paradigm.

The library also features Windows support through Named Pipes and HTTPS support through
optional rustls bindings.
The library also features Windows support through Named Pipes (disabled in 0.10, see below) and
HTTPS support through optional rustls bindings.

## Install

Expand All @@ -25,7 +25,11 @@ bollard = "0.9"
## API
### Documentation

[API docs](https://docs.rs/bollard/).
[API docs](crate).

Version 0.10 disables Named Pipe Windows support until the upstream Tokio project re-adds
support for Named Pipes. Please follow the [tracking
issue](https://github.com/tokio-rs/tokio/issues/3511) for updates on this.

As of version 0.6, this project now generates API stubs from the upstream Docker-maintained
[Swagger OpenAPI specification](https://docs.docker.com/engine/api/v1.40.yaml). The generated
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ test_script:
- ps: Set-Item -path env:RUST_BACKTRACE -value 1
- ps: Set-Item -path env:RUST_LOG -value "hyper=trace,bollard=debug"
- ps: Set-Item -path env:REGISTRY_HTTP_ADDR -value localhost:5000
- cargo test --verbose -- --nocapture --test-threads 1
# - cargo test --verbose -- --nocapture --test-threads 1
36 changes: 7 additions & 29 deletions examples/build.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
//! Builds a container with a bunch of extra options for testing

use bollard::image::BuildImageOptions;
use bollard::models::BuildInfo;
use bollard::Docker;

use std::collections::HashMap;

use futures_util::stream::StreamExt;
use futures_util::stream::TryStreamExt;
use tokio::runtime::Runtime;

fn main() {
let mut rt = Runtime::new().unwrap();
#[cfg(unix)]
#[tokio::main]
async fn main() {
let docker = Docker::connect_with_unix_defaults().unwrap();
#[cfg(windows)]
let docker = Docker::connect_with_named_pipe_defaults().unwrap();

let mut build_image_args = HashMap::new();
build_image_args.insert("dummy", "value");
Expand Down Expand Up @@ -49,26 +43,10 @@ fn main() {
platform: "linux/x86_64",
};

let future = run(docker, build_image_options);
let mut image_build_stream = docker
.build_image(build_image_options, None, None);

rt.block_on(future).unwrap();
}

async fn run<'a>(
docker: Docker,
build_image_options: BuildImageOptions<&'a str>,
) -> Result<(), bollard::errors::Error> {
docker
.build_image(build_image_options, None, None)
.map(|v| {
println!("{:?}", v);
v
})
.map_err(|e| {
println!("{:?}", e);
e
})
.collect::<Vec<Result<BuildInfo, bollard::errors::Error>>>()
.await;
Ok(())
while let Some(msg) = image_build_stream.next().await {
println!("Message: {:?}", msg);
}
}
3 changes: 0 additions & 3 deletions examples/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ extern crate bollard;
use bollard::Docker;

fn run() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(unix)]
let _docker1 = Docker::connect_with_unix_defaults()?;
#[cfg(windows)]
let docker1 = Docker::connect_with_named_pipe_defaults()?;

let _env_var = std::env::var("ZOOKEEPER_ADDR")?;

Expand Down
44 changes: 44 additions & 0 deletions examples/hoover.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Removes old docker containers, images, volumes and networks

use bollard::{container::PruneContainersOptions, image::PruneImagesOptions, network::PruneNetworksOptions, volume::PruneVolumesOptions};
use bollard::Docker;
use chrono::{Duration, Utc};

use std::collections::HashMap;

const THRESHOLD_DAYS: i64 = 90;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
let docker = Docker::connect_with_unix_defaults()?;

let date = Utc::now() - Duration::days(THRESHOLD_DAYS);
let timestamp = &date.timestamp().to_string()[..];

let mut prune_filters = HashMap::new();
prune_filters.insert("until", vec![timestamp]);

let prune = docker.prune_containers(Some(PruneContainersOptions {
filters: prune_filters.clone()
})).await?;

println!("{:?}", prune);

let prune = docker.prune_images(Some(PruneImagesOptions {
filters: prune_filters.clone()
})).await?;

println!("{:?}", prune);

let prune = docker.prune_volumes(None::<PruneVolumesOptions<String>>).await?;

println!("{:?}", prune);

let prune = docker.prune_networks(Some(PruneNetworksOptions {
filters: prune_filters.clone()
})).await?;

println!("{:?}", prune);

Ok(())
}
29 changes: 11 additions & 18 deletions examples/image_from_scratch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::env::args;
use std::fs::File;
use std::io::{Read, Result as IOResult};
use std::pin::Pin;
use tokio::runtime::Runtime;

/*
Image file system archives can be very large, so we don't want to load the entire thing
Expand Down Expand Up @@ -49,11 +48,17 @@ impl Stream for FileStreamer {
}
}

async fn run(file: File) -> Result<(), Box<dyn std::error::Error>> {
#[cfg(unix)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
let arguments: Vec<String> = args().collect();
if arguments.len() == 1 || arguments.len() > 2 {
println!("Usage: image_from_scratch <path to tar archive>");
return Ok(());
}

let file = File::open(&arguments[1]).expect("Could not find archive.");

let docker = Docker::connect_with_unix_defaults().unwrap();
#[cfg(windows)]
let docker = Docker::connect_with_named_pipe_defaults().unwrap();

let options = CreateImageOptions {
from_src: "-", // from_src must be "-" when sending the archive in the request body
Expand All @@ -73,18 +78,6 @@ async fn run(file: File) -> Result<(), Box<dyn std::error::Error>> {
.await?;
// If all went well, the ID of the new image will be printed
dbg!(&result[0]);
Ok(())
}

fn main() {
let arguments: Vec<String> = args().collect();
if arguments.len() == 1 || arguments.len() > 2 {
println!("Usage: image_from_scratch <path to tar archive>");
return;
}

let archive = File::open(&arguments[1]).expect("Could not find archive.");

let mut rt = Runtime::new().unwrap();
rt.block_on(run(archive)).unwrap();
Ok(())
}
44 changes: 17 additions & 27 deletions examples/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ use std::default::Default;

use futures_util::stream;
use futures_util::stream::StreamExt;
use tokio::runtime::Runtime;

async fn run() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(unix)]
async fn conc(arg: (Docker, &ContainerSummary)) -> () {
let (docker, container) = arg;
println!(
"{:?}",
docker
.inspect_container(
container.id.as_ref().unwrap(),
None::<InspectContainerOptions>
)
.await
.unwrap()
)
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
let docker = Docker::connect_with_unix_defaults().unwrap();
#[cfg(windows)]
let docker = Docker::connect_with_named_pipe_defaults().unwrap();

let mut list_container_filters = HashMap::new();
list_container_filters.insert("status", vec!["running"]);
Expand All @@ -33,27 +44,6 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
.zip(stream::iter(containers))
.for_each_concurrent(2, conc)
.await;
Ok(())
}

async fn conc(arg: (Docker, &ContainerSummary)) -> () {
let (docker, container) = arg;
println!(
"{:?}",
docker
.inspect_container(
container.id.as_ref().unwrap(),
None::<InspectContainerOptions>
)
.await
.unwrap()
)
}

fn main() {
env_logger::init();

let mut rt = Runtime::new().unwrap();

rt.block_on(run()).unwrap();
Ok(())
}
26 changes: 8 additions & 18 deletions examples/kafka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@ use bollard::models::*;
use bollard::Docker;

use futures_util::stream::select;
use futures_util::stream::StreamExt;
use futures_util::stream::TryStreamExt;
use tokio::runtime::Runtime;

const KAFKA_IMAGE: &'static str = "confluentinc/cp-kafka:5.0.1";
const ZOOKEEPER_IMAGE: &'static str = "confluentinc/cp-zookeeper:5.0.1";

fn main() {
let mut rt = Runtime::new().unwrap();

rt.block_on(run()).unwrap();
}

async fn run() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(unix)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
let docker = Docker::connect_with_unix_defaults().unwrap();
#[cfg(windows)]
let docker = Docker::connect_with_named_pipe_defaults().unwrap();

let sd1 = docker.clone();
let sd2 = docker.clone();

Expand Down Expand Up @@ -157,14 +150,11 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
}),
);

let stream = select(&mut stream1, &mut stream2);
let mut stream = select(&mut stream1, &mut stream2);

stream
.map_err(|e| println!("{:?}", e))
.map_ok(|x| println!("{:?}", x))
.try_collect::<Vec<_>>()
.await
.unwrap();
while let Some(msg) = stream.next().await {
println!("Message: {:?}", msg);
}

Ok(())
}
36 changes: 36 additions & 0 deletions examples/post_dockerfile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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_unix_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);
}
}
Loading