Skip to content

Commit

Permalink
Merge pull request #16 from fussybeaver/ND-v0.2.1
Browse files Browse the repository at this point in the history
Bollard v0.2.1
  • Loading branch information
Niel Drummond authored Feb 7, 2019
2 parents 1373e6b + 2392982 commit a82aa55
Show file tree
Hide file tree
Showing 12 changed files with 783 additions and 64 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
test_ssl:
docker:
- image: docker:18.09.0
- image: docker:18.09.1
steps:
- checkout
- setup_remote_docker
Expand All @@ -14,7 +14,7 @@ jobs:
- run: docker run -e -ti -e DOCKER_CERT_PATH=/certs -e DOCKER_HOST='tcp://test.example.com:2375' --volumes-from certs --rm --link test-docker-daemon:docker bollard cargo test --features ssl -- --test test_version_ssl
test_tls:
docker:
- image: docker:18.09.0
- image: docker:18.09.1
steps:
- checkout
- setup_remote_docker
Expand All @@ -27,7 +27,7 @@ jobs:
- run: docker run -e -ti -e DOCKER_CERT_PATH=/certs -e DOCKER_HOST='tcp://test.example.com:2375' --volumes-from certs --rm --link test-docker-daemon:docker bollard cargo test -- --test test_version_tls
test_http:
docker:
- image: docker:18.09.0
- image: docker:18.09.1
steps:
- checkout
- setup_remote_docker
Expand All @@ -36,15 +36,15 @@ jobs:
- run: docker run -e -ti -e DOCKER_HOST='tcp://test.example.com:2375' --rm --link test-docker-daemon:docker bollard cargo test --features test_http -- --test test_version_http
test_unix:
docker:
- image: docker:18.09.0
- image: docker:18.09.1
steps:
- checkout
- setup_remote_docker
- run: docker build -t bollard .
- run: dockerfiles/bin/run_integration_tests.sh
test_doc:
docker:
- image: docker:18.09.0
- image: docker:18.09.1
steps:
- checkout
- setup_remote_docker
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bollard"
description = "An asynchronous Docker daemon API"
version = "0.2.0"
version = "0.2.1"
authors = ["Graham Lee <[email protected]>",
"Toby Lawrence <[email protected]>",
"Eric Kidd <[email protected]>",
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![crates.io](https://img.shields.io/crates/v/bollard.svg)](https://crates.io/crates/bollard)
[![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![circle-ci](https://circleci.com/gh/fussybeaver/bollard/tree/master.svg?style=svg)](https://circleci.com/gh/fussybeaver/bollard/tree/master)
[![appveyor](https://ci.appveyor.com/api/projects/status/n5khebyfae0u1sbv?svg=true)](https://ci.appveyor.com/project/fussybeaver/boondock)
[![appveyor](https://ci.appveyor.com/api/projects/status/n5khebyfae0u1sbv/branch/master?svg=true)](https://ci.appveyor.com/project/fussybeaver/boondock)
[![docs](https://docs.rs/bollard/badge.svg?version=0.1.0)](https://docs.rs/bollard/)

## Bollard: an asynchronous rust client library for the docker API
Expand All @@ -19,13 +19,18 @@ Add the following to your `Cargo.toml` file

```nocompile
[dependencies]
bollard = "0.1"
bollard = "0.2"
```

## API documentation
## API
### Documentation

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

### Version

The [Docker API](https://docs.docker.com/engine/api/v1.39/) is pegged at version `1.39`

## Usage

### Connecting with the docker daemon
Expand Down
7 changes: 5 additions & 2 deletions src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ pub struct WaitContainerResultsError {
#[serde(rename_all = "PascalCase", deny_unknown_fields)]
#[allow(missing_docs)]
pub struct WaitContainerResults {
pub status_code: u16,
pub status_code: u64,
pub error: Option<WaitContainerResultsError>,
}

Expand Down Expand Up @@ -1004,6 +1004,7 @@ pub enum LogOutput {
StdErr { message: String },
StdOut { message: String },
StdIn { message: String },
Console { message: String },
}

impl fmt::Display for LogOutput {
Expand All @@ -1012,6 +1013,7 @@ impl fmt::Display for LogOutput {
LogOutput::StdErr { message } => write!(f, "{}", message),
LogOutput::StdOut { message } => write!(f, "{}", message),
LogOutput::StdIn { message } => write!(f, "{}", message),
LogOutput::Console { message } => write!(f, "{}", message),
}
}
}
Expand Down Expand Up @@ -1124,7 +1126,8 @@ pub struct MemoryStats {
pub commit: Option<u64>,
pub commit_peak: Option<u64>,
pub commitbytes: Option<u64>,
pub private_working_set: Option<u64>,
pub commitpeakbytes: Option<u64>,
pub privateworkingset: Option<u64>,
}

/// Process ID statistics for the container.
Expand Down
40 changes: 33 additions & 7 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use errors::{
};
#[cfg(windows)]
use named_pipe::NamedPipeConnector;
use read::{JsonLineDecoder, LineDecoder, StreamReader};
use read::{JsonLineDecoder, NewlineLogOutputDecoder, StreamReader};
use uri::Uri;

use serde::de::DeserializeOwned;
Expand All @@ -61,6 +61,9 @@ const DEFAULT_NUM_THREADS: usize = 1;
/// Default timeout for all requests is 2 minutes.
const DEFAULT_TIMEOUT: u64 = 120;

/// Docker API version
pub(crate) const API_VERSION: &'static str = "v1.39";

pub(crate) const TRUE_STR: &'static str = "true";
pub(crate) const FALSE_STR: &'static str = "false";

Expand Down Expand Up @@ -766,7 +769,17 @@ where
) -> impl Stream<Item = Chunk, Error = Error> {
self.process_request(req)
.into_stream()
.map(|response| response.into_body().map_err(|e| e.into()))
.map(|response| response.into_body().from_err())
.flatten()
}

pub(crate) fn process_upgraded_stream_string(
&self,
req: Result<Request<Body>, Error>,
) -> impl Stream<Item = LogOutput, Error = Error> {
self.process_request(req)
.into_stream()
.map(Docker::<C>::decode_into_upgraded_stream_string)
.flatten()
}

Expand Down Expand Up @@ -812,6 +825,8 @@ where
// Status code 200 - 299
s if s.is_success() => EitherResponse::A(future::ok(response)),

StatusCode::SWITCHING_PROTOCOLS => EitherResponse::G(future::ok(response)),

// Status code 304: Not Modified
StatusCode::NOT_MODIFIED => {
EitherResponse::F(Docker::<C>::decode_into_string(response).and_then(
Expand Down Expand Up @@ -885,8 +900,7 @@ where
) -> impl Future<Item = Response<Body>, Error = Error> {
let now = Instant::now();

Timeout::new_at(client.request(request), now + Duration::from_secs(timeout))
.map_err(|e| e.into())
Timeout::new_at(client.request(request), now + Duration::from_secs(timeout)).from_err()
}

fn decode_into_stream<T>(res: Response<Body>) -> impl Stream<Item = T, Error = Error>
Expand All @@ -904,15 +918,27 @@ where
) -> impl Stream<Item = LogOutput, Error = Error> {
FramedRead::new(
StreamReader::new(res.into_body().from_err()),
LineDecoder::new(),
).map_err(|e| e)
NewlineLogOutputDecoder::new(),
)
.from_err()
}

fn decode_into_upgraded_stream_string(
res: Response<Body>,
) -> impl Stream<Item = LogOutput, Error = Error> {
res.into_body()
.on_upgrade()
.into_stream()
.map(|r| FramedRead::new(r, NewlineLogOutputDecoder::new()))
.map_err::<Error, _>(|e: hyper::Error| e.into())
.flatten()
}

fn decode_into_string(response: Response<Body>) -> impl Future<Item = String, Error = Error> {
response
.into_body()
.concat2()
.map_err(|e| e.into())
.from_err()
.and_then(|body| from_utf8(&body).map(|x| x.to_owned()).map_err(|e| e.into()))
}

Expand Down
7 changes: 5 additions & 2 deletions src/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ where
}

#[derive(Debug)]
pub(crate) enum EitherResponse<B, C, D, E, F> {
pub(crate) enum EitherResponse<B, C, D, E, F, G> {
A(future::FutureResult<Response<Body>, Error>),
B(B),
C(C),
D(D),
E(E),
F(F),
G(G),
}

impl<B, C, D, E, F> Future for EitherResponse<B, C, D, E, F>
impl<B, C, D, E, F, G> Future for EitherResponse<B, C, D, E, F, G>
where
B: Future<Item = Response<Body>, Error = Error>,
C: Future<Item = Response<Body>, Error = Error>,
D: Future<Item = Response<Body>, Error = Error>,
E: Future<Item = Response<Body>, Error = Error>,
F: Future<Item = Response<Body>, Error = Error>,
G: Future<Item = Response<Body>, Error = Error>,
{
type Item = Response<Body>;
type Error = Error;
Expand All @@ -55,6 +57,7 @@ where
EitherResponse::D(ref mut d) => d.poll(),
EitherResponse::E(ref mut e) => e.poll(),
EitherResponse::F(ref mut f) => f.poll(),
EitherResponse::G(ref mut g) => g.poll(),
}
}
}
Loading

0 comments on commit a82aa55

Please sign in to comment.