From 846b69eac815942d6eff2dc2ac52db8065d8eef7 Mon Sep 17 00:00:00 2001 From: doug tangren Date: Sun, 23 Dec 2018 01:15:02 +0900 Subject: update travis build (#140) * update travis build * notes on fmting * remove quotes * comment below * rouge quote * first host.port usage * fix deprecation warning --- .travis.yml | 38 +++++++++++++++------------ CONTRIBUTING.md | 4 +-- src/builder.rs | 26 +++++++++++++------ src/errors.rs | 5 +++- src/lib.rs | 19 +++++++++----- src/tarball.rs | 2 +- src/transport.rs | 30 +++++++++++----------- src/tty.rs | 78 +++++++++++++++++++++++++++++++++----------------------- 8 files changed, 120 insertions(+), 82 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1916096..3c63f85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ -# true because of tarpaulin dependency -sudo: true +# required because of tarpaulin dependency +sudo: required language: rust @@ -16,20 +16,20 @@ matrix: - rust: nightly - rust: beta - rust: stable - allow_failures: - - rust: nightly install: | - # should only be necessary until rustfmt produces consistent results in stable/nightly - # see also https://github.com/xd009642/tarpaulin/issues/150 for tarpaulin nightly dependency - rustup toolchain install nightly - rustup component add rustfmt-preview --toolchain nightly - if [[ "$TRAVIS_RUST_VERSION" == stable ]]; then - `RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo +nightly install --force cargo-tarpaulin` + if [[ "$TRAVIS_RUST_VERSION" == nightly ]]; then + # see also https://github.com/xd009642/tarpaulin/issues/150 for tarpaulin nightly dependency + RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install cargo-tarpaulin -f + # should only be necessary until rustfmt produces consistent results in stable/nightly + rustup component add rustfmt fi script: -- cargo +nightly fmt --all -- --check +- | + if [[ "$TRAVIS_RUST_VERSION" == nightly ]]; then + cargo fmt --all -- --check + fi - cargo test # Cache `cargo install`ed tools, but don't cache the project's `target` @@ -61,8 +61,14 @@ after_success: [ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && cargo doc --no-deps && - echo "" > target/doc/index.html && - pip install --user ghp-import && - /home/travis/.local/bin/ghp-import -n target/doc && - git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages && - echo "documented"' \ No newline at end of file + echo "" > target/doc/index.html' + +deploy: + provider: pages + skip-cleanup: true + github-token: $GH_TOKEN + local-dir: target/doc + keep-history: false + on: + branch: master + condition: $TRAVIS_RUST_VERSION = stable diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f8796ee..f4a6702 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,7 +49,7 @@ $ rustup toolchain install nightly Install the most recent version of `rustfmt` using this command: ```sh -$ rustup component add rustfmt-preview --toolchain nightly +$ rustup component add rustfmt --toolchain nightly ``` **3. Running rustfmt** @@ -57,7 +57,7 @@ $ rustup component add rustfmt-preview --toolchain nightly To run `rustfmt`, use this command: ```sh -$ cargo +nightly fmt +$ cargo +nightly fmt --all ``` [rustfmt]: https://github.com/rust-lang-nursery/rustfmt diff --git a/src/builder.rs b/src/builder.rs index bee4c6e..cd086ca 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -515,26 +515,38 @@ impl ContainerOptionsBuilder { } /// Whether to attach to `stdin`. - pub fn attach_stdin(&mut self, attach: bool) -> &mut Self { + pub fn attach_stdin( + &mut self, + attach: bool, + ) -> &mut Self { self.params.insert("AttachStdin", json!(attach)); self.params.insert("OpenStdin", json!(attach)); self } /// Whether to attach to `stdout`. - pub fn attach_stdout(&mut self, attach: bool) -> &mut Self { + pub fn attach_stdout( + &mut self, + attach: bool, + ) -> &mut Self { self.params.insert("AttachStdout", json!(attach)); self } /// Whether to attach to `stderr`. - pub fn attach_stderr(&mut self, attach: bool) -> &mut Self { + pub fn attach_stderr( + &mut self, + attach: bool, + ) -> &mut Self { self.params.insert("AttachStderr", json!(attach)); self } /// Whether standard streams should be attached to a TTY. - pub fn tty(&mut self, tty: bool) -> &mut Self { + pub fn tty( + &mut self, + tty: bool, + ) -> &mut Self { self.params.insert("Tty", json!(tty)); self } @@ -1171,9 +1183,7 @@ impl NetworkCreateOptionsBuilder { pub(crate) fn new(name: &str) -> Self { let mut params = HashMap::new(); params.insert("Name", json!(name)); - NetworkCreateOptionsBuilder { - params - } + NetworkCreateOptionsBuilder { params } } pub fn driver( @@ -1253,7 +1263,7 @@ impl ContainerConnectionOptionsBuilder { aliases: Vec<&str>, ) -> &mut Self { self.params - .insert("EndpointConfig", json!({"Aliases": json!(aliases)})); + .insert("EndpointConfig", json!({ "Aliases": json!(aliases) })); self } diff --git a/src/errors.rs b/src/errors.rs index fa408c2..8392971 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -60,7 +60,10 @@ impl fmt::Display for Error { write!(f, "Response doesn't have the expected format: {}", cause) } Error::Fault { code, .. } => write!(f, "{}", code), - Error::ConnectionNotUpgraded => write!(f, "expected the docker host to upgrade the HTTP connection but it did not"), + Error::ConnectionNotUpgraded => write!( + f, + "expected the docker host to upgrade the HTTP connection but it did not" + ), } } } diff --git a/src/lib.rs b/src/lib.rs index 0932994..11a4653 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -310,11 +310,14 @@ impl<'a, 'b> Container<'a, 'b> { /// Attaches to a running container, returning a stream that can /// be used to interact with the standard IO streams. - pub fn attach(&self) - -> impl Future { + pub fn attach(&self) -> impl Future { self.docker.stream_post_upgrade_multiplexed::( - &format!("/containers/{}/attach?stream=1&stdout=1&stderr=1&stdin=1", self.id), - None) + &format!( + "/containers/{}/attach?stream=1&stdout=1&stderr=1&stdin=1", + self.id + ), + None, + ) } /// Attaches to a running container, returning a stream that can @@ -804,7 +807,7 @@ impl Docker { "{}://{}:{}", host.scheme_part().map(|s| s.as_str()).unwrap(), host.host().unwrap().to_owned(), - host.port_part().unwrap_or(80) + host.port().unwrap_or(80) ); match host.scheme_part().map(|s| s.as_str()) { @@ -1009,7 +1012,9 @@ impl Docker { body: Option<(B, Mime)>, ) -> impl Future where - B: Into + 'static { - self.transport.stream_upgrade_multiplexed(Method::POST, endpoint, body) + B: Into + 'static, + { + self.transport + .stream_upgrade_multiplexed(Method::POST, endpoint, body) } } diff --git a/src/tarball.rs b/src/tarball.rs index d414620..acbe47a 100644 --- a/src/tarball.rs +++ b/src/tarball.rs @@ -54,7 +54,7 @@ where let relativized = canonical .to_str() .unwrap() - .trim_left_matches(&base_path_str[..]); + .trim_start_matches(&base_path_str[..]); if path.is_dir() { archive.append_dir(Path::new(relativized), &canonical)? } else { diff --git a/src/transport.rs b/src/transport.rs index 55844c3..41d8694 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -143,7 +143,8 @@ impl Transport { f: impl FnOnce(&mut ::http::request::Builder), ) -> Result> where - B: Into { + B: Into, + { let mut builder = Request::builder(); f(&mut builder); @@ -197,28 +198,27 @@ impl Transport { body: Option<(B, Mime)>, ) -> impl Future where - B: Into + B: Into, { match self { Transport::Tcp { .. } | Transport::EncryptedTcp { .. } => (), _ => panic!("connection streaming is only supported over TCP"), }; - let req = self.build_request(method, endpoint, body, |builder| { - builder.header(header::CONNECTION, "Upgrade") - .header(header::UPGRADE, "tcp"); - }).expect("Failed to build request!"); + let req = self + .build_request(method, endpoint, body, |builder| { + builder + .header(header::CONNECTION, "Upgrade") + .header(header::UPGRADE, "tcp"); + }) + .expect("Failed to build request!"); - self.send_request(req).and_then(|res| { - match res.status() { + self.send_request(req) + .and_then(|res| match res.status() { StatusCode::SWITCHING_PROTOCOLS => Ok(res), _ => Err(Error::ConnectionNotUpgraded), - } - }).and_then(|res| { - res.into_body() - .on_upgrade() - .from_err() - }) + }) + .and_then(|res| res.into_body().on_upgrade().from_err()) } pub fn stream_upgrade_multiplexed( @@ -228,7 +228,7 @@ impl Transport { body: Option<(B, Mime)>, ) -> impl Future where - B: Into + 'static + B: Into + 'static, { self.stream_upgrade(method, endpoint, body) .map(|u| ::tty::Multiplexed::new(u)) diff --git a/src/tty.rs b/src/tty.rs index a0c5146..c30a038 100644 --- a/src/tty.rs +++ b/src/tty.rs @@ -5,9 +5,9 @@ use std::io::Cursor; use tokio_codec::Decoder; use futures::{self, Async}; -use hyper::rt::{Stream, Future}; -use tokio_io::{AsyncRead, AsyncWrite}; +use hyper::rt::{Future, Stream}; use std::io; +use tokio_io::{AsyncRead, AsyncWrite}; #[derive(Debug)] pub struct Chunk { @@ -25,12 +25,12 @@ pub enum StreamType { /// A multiplexed stream. pub struct Multiplexed { stdin: Box, - chunks: Box>, + chunks: Box>, } pub struct MultiplexedBlocking { stdin: Box, - chunks: Box>>, + chunks: Box>>, } /// Represent the current state of the decoding of a TTY frame @@ -144,7 +144,9 @@ impl Decoder for TtyDecoder { impl Multiplexed { /// Create a multiplexed stream. pub(crate) fn new(stream: T) -> Multiplexed - where T: AsyncRead + AsyncWrite + 'static { + where + T: AsyncRead + AsyncWrite + 'static, + { let (reader, stdin) = stream.split(); Multiplexed { chunks: Box::new(chunks(reader)), @@ -180,7 +182,10 @@ impl Iterator for MultiplexedBlocking { macro_rules! delegate_io_write { ($ty:ty) => { impl io::Write for $ty { - fn write(&mut self, buf: &[u8]) -> Result { + fn write( + &mut self, + buf: &[u8], + ) -> Result { self.stdin.write(buf) } @@ -194,27 +199,26 @@ macro_rules! delegate_io_write { delegate_io_write!(Multiplexed); delegate_io_write!(MultiplexedBlocking); -pub fn chunks(stream: S) -> impl futures::Stream - where S: AsyncRead { - +pub fn chunks(stream: S) -> impl futures::Stream +where + S: AsyncRead, +{ let stream = futures::stream::unfold(stream, |stream| { let header_future = ::tokio_io::io::read_exact(stream, vec![0; 8]); - let fut = header_future - .and_then(|(stream, header_bytes)| { - let size_bytes = &header_bytes[4..]; - let data_length = BigEndian::read_u32(size_bytes); - let stream_type = match header_bytes[0] { - 0 => StreamType::StdIn, - 1 => StreamType::StdOut, - 2 => StreamType::StdErr, - n => panic!("invalid stream number from docker daemon: '{}'", n) - }; - - ::tokio_io::io::read_exact(stream, vec![0; data_length as usize]).map(move |(stream, data)| { - (Chunk { stream_type, data }, stream) - }) - }); + let fut = header_future.and_then(|(stream, header_bytes)| { + let size_bytes = &header_bytes[4..]; + let data_length = BigEndian::read_u32(size_bytes); + let stream_type = match header_bytes[0] { + 0 => StreamType::StdIn, + 1 => StreamType::StdOut, + 2 => StreamType::StdErr, + n => panic!("invalid stream number from docker daemon: '{}'", n), + }; + + ::tokio_io::io::read_exact(stream, vec![0; data_length as usize]) + .map(move |(stream, data)| (Chunk { stream_type, data }, stream)) + }); // FIXME: when updated to futures 0.2, the future itself returns the Option((Chunk, // stream)). // This is much better because it would allow us to swallow the unexpected eof and @@ -227,33 +231,43 @@ pub fn chunks(stream: S) -> impl futures::Stream } mod util { - use futures::{Stream, Async}; + use futures::{Async, Stream}; pub struct StopOnError { stream: S, f: F, } - pub fn stop_on_err(stream: S, f: F) -> StopOnError - where S: Stream, - F: FnMut(&S::Error) -> bool, + pub fn stop_on_err( + stream: S, + f: F, + ) -> StopOnError + where + S: Stream, + F: FnMut(&S::Error) -> bool, { StopOnError { stream, f } } impl Stream for StopOnError - where S: Stream, - F: FnMut(&S::Error) -> bool, + where + S: Stream, + F: FnMut(&S::Error) -> bool, { type Item = S::Item; type Error = S::Error; fn poll(&mut self) -> Result>, S::Error> { match self.stream.poll() { - Err(e) => if (self.f)(&e) { Err(e) } else { Ok(Async::Ready(None)) }, + Err(e) => { + if (self.f)(&e) { + Err(e) + } else { + Ok(Async::Ready(None)) + } + } a => a, } } } } - -- cgit v1.2.3