diff --git a/Cargo.toml b/Cargo.toml index db098c2c..60f2bfeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "shiplift" -version = "0.3.2" +version = "0.4.0" authors = ["softprops "] description = "A Rust interface for maneuvering Docker containers" documentation = "https://docs.rs/shiplift" @@ -9,6 +9,7 @@ homepage = "https://github.com/softprops/shiplift" repository = "https://github.com/softprops/shiplift" keywords = ["docker", "unix", "containers", "hyper", "ship"] license = "MIT" +edition = "2018" [dependencies] byteorder = "1" diff --git a/README.md b/README.md index d0592e30..358e378a 100644 --- a/README.md +++ b/README.md @@ -20,20 +20,15 @@ Some small example programs can be found in this repository's [examples director ### communicating with hosts To use shiplift, you must first have a docker daemon readily accessible. Typically this daemon processs -is resolvable via a url specified by an env var named `DOCKER_HOST`. If you are using osx, [docker-machine](https://docs.docker.com/machine/) typically -will have already set up every thing you need to get started when you run `docker-machine env {envid}`. +is resolvable via a url specified by an env var named `DOCKER_HOST`. ```rust -extern crate shiplift; let docker = shiplift::Docker::new(); ``` If you wish to be more explicit you can provide a host in the form of a `url.Url`. ```rust -extern crate shiplift; -extern crate url; - use shiplift::Docker; use url::Url; @@ -45,8 +40,6 @@ let docker = Docker::host(Url::parse("http://yourhost").unwrap()); If you are interacting with docker containers, chances are you will also need to interact with docker image information. You can interact docker images with `docker.images()`. ```rust -extern crate shiplift; - use shiplift::Docker; let docker = Docker.new(); @@ -127,8 +120,6 @@ println!("- {:?}", img.delete().unwrap()); Containers are instances of images. To gain access to this interface use `docker.containers()` ```rust -extern crate shiplift; - use shiplift::Docker; let docker = Docker.new(); diff --git a/examples/containercreate.rs b/examples/containercreate.rs index f5baf39c..d061f702 100644 --- a/examples/containercreate.rs +++ b/examples/containercreate.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::{ContainerOptions, Docker}; use std::env; use tokio::prelude::Future; diff --git a/examples/containerdelete.rs b/examples/containerdelete.rs index cc2e9b73..e3c20368 100644 --- a/examples/containerdelete.rs +++ b/examples/containerdelete.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use std::env; use tokio::prelude::Future; diff --git a/examples/containerexec.rs b/examples/containerexec.rs index 0bfd640b..7f12f884 100644 --- a/examples/containerexec.rs +++ b/examples/containerexec.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::{tty::StreamType, Docker, ExecContainerOptions}; use std::env; use tokio::prelude::{Future, Stream}; diff --git a/examples/containerinspect.rs b/examples/containerinspect.rs index ebd37ef7..0f853bc6 100644 --- a/examples/containerinspect.rs +++ b/examples/containerinspect.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use std::env; use tokio::prelude::Future; diff --git a/examples/containers.rs b/examples/containers.rs index 71da705f..0eb51af5 100644 --- a/examples/containers.rs +++ b/examples/containers.rs @@ -1,7 +1,3 @@ -extern crate env_logger; -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use tokio::prelude::Future; diff --git a/examples/events.rs b/examples/events.rs index ced2f29d..0e35860c 100644 --- a/examples/events.rs +++ b/examples/events.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use tokio::prelude::{Future, Stream}; diff --git a/examples/export.rs b/examples/export.rs index b8d8eafd..55d1b7b5 100644 --- a/examples/export.rs +++ b/examples/export.rs @@ -1,10 +1,5 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::{errors::Error, Docker}; -use std::env; -use std::fs::OpenOptions; -use std::io::Write; +use std::{env, fs::OpenOptions, io::Write}; use tokio::prelude::{Future, Stream}; fn main() { diff --git a/examples/imagebuild.rs b/examples/imagebuild.rs index 4b672191..6dbea78e 100644 --- a/examples/imagebuild.rs +++ b/examples/imagebuild.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::{BuildOptions, Docker}; use std::env; use tokio::prelude::{Future, Stream}; diff --git a/examples/imagedelete.rs b/examples/imagedelete.rs index 5e507a20..efa763c2 100644 --- a/examples/imagedelete.rs +++ b/examples/imagedelete.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use std::env; use tokio::prelude::Future; diff --git a/examples/imageinspect.rs b/examples/imageinspect.rs index 0cd84505..494480a1 100644 --- a/examples/imageinspect.rs +++ b/examples/imageinspect.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use std::env; use tokio::prelude::Future; diff --git a/examples/imagepull.rs b/examples/imagepull.rs index 1039080d..a9c5b36f 100644 --- a/examples/imagepull.rs +++ b/examples/imagepull.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::{Docker, PullOptions}; use std::env; use tokio::prelude::{Future, Stream}; diff --git a/examples/images.rs b/examples/images.rs index b3e80a88..e68c9bb5 100644 --- a/examples/images.rs +++ b/examples/images.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use tokio::prelude::Future; diff --git a/examples/info.rs b/examples/info.rs index b608818d..05fdeded 100644 --- a/examples/info.rs +++ b/examples/info.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use tokio::prelude::Future; diff --git a/examples/logs.rs b/examples/logs.rs index 6fad7d6a..57f12be9 100644 --- a/examples/logs.rs +++ b/examples/logs.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::{tty::StreamType, Docker, LogsOptions}; use std::env; use tokio::prelude::{Future, Stream}; diff --git a/examples/networkconnect.rs b/examples/networkconnect.rs index 3960b8f7..0cfc8fc0 100644 --- a/examples/networkconnect.rs +++ b/examples/networkconnect.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::{ContainerConnectionOptions, Docker}; use std::env; use tokio::prelude::Future; diff --git a/examples/networkcreate.rs b/examples/networkcreate.rs index a7b76626..30bb41cc 100644 --- a/examples/networkcreate.rs +++ b/examples/networkcreate.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::{Docker, NetworkCreateOptions}; use std::env; use tokio::prelude::Future; diff --git a/examples/networkdelete.rs b/examples/networkdelete.rs index 8f1cdca5..16fc4ab6 100644 --- a/examples/networkdelete.rs +++ b/examples/networkdelete.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use std::env; use tokio::prelude::Future; diff --git a/examples/networkdisconnect.rs b/examples/networkdisconnect.rs index e3885137..9588ecc9 100644 --- a/examples/networkdisconnect.rs +++ b/examples/networkdisconnect.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::{ContainerConnectionOptions, Docker}; use std::env; use tokio::prelude::Future; diff --git a/examples/networkinspect.rs b/examples/networkinspect.rs index 37992a58..86a076b0 100644 --- a/examples/networkinspect.rs +++ b/examples/networkinspect.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use std::env; use tokio::prelude::Future; diff --git a/examples/networks.rs b/examples/networks.rs index 57cd5664..9ceea99a 100644 --- a/examples/networks.rs +++ b/examples/networks.rs @@ -1,7 +1,3 @@ -extern crate env_logger; -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use tokio::prelude::Future; diff --git a/examples/stats.rs b/examples/stats.rs index f1363263..5e03f204 100644 --- a/examples/stats.rs +++ b/examples/stats.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use std::env; use tokio::prelude::{Future, Stream}; diff --git a/examples/top.rs b/examples/top.rs index 1bdf6ca2..5fc42297 100644 --- a/examples/top.rs +++ b/examples/top.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use std::env; use tokio::prelude::Future; diff --git a/examples/volumecreate.rs b/examples/volumecreate.rs index d955abeb..83f50458 100644 --- a/examples/volumecreate.rs +++ b/examples/volumecreate.rs @@ -1,10 +1,5 @@ -extern crate shiplift; -extern crate tokio; - -use shiplift::builder::VolumeCreateOptions; -use shiplift::Docker; -use std::collections::HashMap; -use std::env; +use shiplift::{builder::VolumeCreateOptions, Docker}; +use std::{collections::HashMap, env}; use tokio::prelude::Future; fn main() { diff --git a/examples/volumedelete.rs b/examples/volumedelete.rs index 86895891..3800d22a 100644 --- a/examples/volumedelete.rs +++ b/examples/volumedelete.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use std::env; use tokio::prelude::Future; diff --git a/examples/volumes.rs b/examples/volumes.rs index 59c7b65e..ea577a75 100644 --- a/examples/volumes.rs +++ b/examples/volumes.rs @@ -1,6 +1,3 @@ -extern crate shiplift; -extern crate tokio; - use shiplift::Docker; use tokio::prelude::Future; diff --git a/rustfmt.toml b/rustfmt.toml index ecbc0a63..3eb534eb 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,4 @@ -# style function arg lists consistently -fn_args_density = "Vertical" \ No newline at end of file +# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#fn_args_density +fn_args_density = "Vertical" +# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#merge_imports +merge_imports = true \ No newline at end of file diff --git a/src/builder.rs b/src/builder.rs index cd086ca6..bf7500f7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,21 +1,17 @@ //! Interfaces for building various structures -// Std lib -use std::cmp::Eq; -use std::collections::{BTreeMap, HashMap}; -use std::hash::Hash; -use std::iter::IntoIterator; -use std::iter::Peekable; - -// Third party +use crate::{errors::Error, Result}; use serde::Serialize; -use serde_json::{self, map::Map, Value}; +use serde_derive::Serialize; +use serde_json::{self, json, map::Map, Value}; +use std::{ + cmp::Eq, + collections::{BTreeMap, HashMap}, + hash::Hash, + iter::{IntoIterator, Peekable}, +}; use url::form_urlencoded; -// Ours -use errors::Error; -use Result; - #[derive(Default)] pub struct PullOptions { params: HashMap<&'static str, String>, diff --git a/src/errors.rs b/src/errors.rs index 83929710..f363ffde 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -3,10 +3,7 @@ use http; use hyper::{self, StatusCode}; use serde_json::Error as SerdeError; -use std::error::Error as StdError; -use std::fmt; -use std::io::Error as IoError; -use std::string::FromUtf8Error; +use std::{error::Error as StdError, fmt, io::Error as IoError, string::FromUtf8Error}; #[derive(Debug)] pub enum Error { diff --git a/src/lib.rs b/src/lib.rs index 11a4653f..1b36404a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,9 +3,6 @@ //! # examples //! //! ```no_run -//! extern crate shiplift; -//! extern crate tokio; -//! //! use tokio::prelude::Future; //! //! let docker = shiplift::Docker::new(); @@ -19,30 +16,6 @@ //! tokio::run(fut); //! ``` -#[macro_use] -extern crate log; -extern crate byteorder; -extern crate bytes; -extern crate flate2; -extern crate futures; -extern crate http; -extern crate hyper; -extern crate hyper_openssl; -#[cfg(feature = "unix-socket")] -extern crate hyperlocal; -extern crate mime; -extern crate openssl; -extern crate tar; -extern crate url; -#[macro_use] -extern crate serde_derive; -extern crate serde; -#[macro_use] -extern crate serde_json; -extern crate tokio; -extern crate tokio_codec; -extern crate tokio_io; - pub mod builder; pub mod errors; pub mod read; @@ -52,37 +25,36 @@ pub mod tty; mod tarball; -pub use builder::{ - BuildOptions, ContainerConnectionOptions, ContainerFilter, ContainerListOptions, - ContainerOptions, EventsOptions, ExecContainerOptions, ImageFilter, ImageListOptions, - LogsOptions, NetworkCreateOptions, NetworkListOptions, PullOptions, RmContainerOptions, - VolumeCreateOptions, +pub use crate::{ + builder::{ + BuildOptions, ContainerConnectionOptions, ContainerFilter, ContainerListOptions, + ContainerOptions, EventsOptions, ExecContainerOptions, ImageFilter, ImageListOptions, + LogsOptions, NetworkCreateOptions, NetworkListOptions, PullOptions, RmContainerOptions, + VolumeCreateOptions, + }, + errors::Error, +}; +use crate::{ + read::StreamReader, + rep::{ + Change, Container as ContainerRep, ContainerCreateInfo, ContainerDetails, Event, Exit, + History, Image as ImageRep, ImageDetails, Info, NetworkCreateInfo, + NetworkDetails as NetworkInfo, SearchResult, Stats, Status, Top, Version, + Volume as VolumeRep, VolumeCreateInfo, Volumes as VolumesRep, + }, + transport::{tar, Transport}, + tty::TtyDecoder, }; -pub use errors::Error; use futures::{future::Either, Future, IntoFuture, Stream}; -use hyper::client::HttpConnector; -use hyper::Body; -use hyper::{Client, Method, Uri}; +use hyper::{client::HttpConnector, Body, Client, Method, Uri}; use hyper_openssl::HttpsConnector; #[cfg(feature = "unix-socket")] use hyperlocal::UnixConnector; use mime::Mime; use openssl::ssl::{SslConnector, SslFiletype, SslMethod}; -use read::StreamReader; -use rep::{ - Change, Container as ContainerRep, ContainerCreateInfo, ContainerDetails, Event, Exit, History, - Image as ImageRep, ImageDetails, Info, NetworkCreateInfo, NetworkDetails as NetworkInfo, - SearchResult, Stats, Status, Top, Version, Volume as VolumeRep, VolumeCreateInfo, - Volumes as VolumesRep, -}; use serde_json::Value; -use std::borrow::Cow; -use std::env; -use std::path::Path; -use std::time::Duration; +use std::{borrow::Cow, env, path::Path, time::Duration}; use tokio_codec::{FramedRead, LinesCodec}; -use transport::{tar, Transport}; -use tty::TtyDecoder; use url::form_urlencoded; /// Represents the result of all docker operations @@ -769,7 +741,7 @@ impl<'a, 'b> Volume<'a, 'b> { } } -// https://docs.docker.com/reference/api/docker_remote_api_v1.17/ +// https://docs.docker.com/reference/api/ impl Docker { /// constructs a new Docker instance for a docker host listening at a url specified by an env var `DOCKER_HOST`, /// falling back on unix:///var/run/docker.sock diff --git a/src/read.rs b/src/read.rs index 847ee21c..b9dc5ef9 100644 --- a/src/read.rs +++ b/src/read.rs @@ -1,8 +1,10 @@ -use errors::Error; +use crate::errors::Error; use futures::{Async, Stream}; use hyper::Chunk; -use std::cmp; -use std::io::{self, Read}; +use std::{ + cmp, + io::{self, Read}, +}; use tokio_io::AsyncRead; /* diff --git a/src/rep.rs b/src/rep.rs index 5317d83e..097ae9e3 100644 --- a/src/rep.rs +++ b/src/rep.rs @@ -1,5 +1,6 @@ //! Rust representations of docker json structures +use serde_derive::{Deserialize, Serialize}; use std::collections::HashMap; #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/src/tarball.rs b/src/tarball.rs index acbe47a9..06a03627 100644 --- a/src/tarball.rs +++ b/src/tarball.rs @@ -1,8 +1,9 @@ -use flate2::write::GzEncoder; -use flate2::Compression; -use std::fs::{self, File}; -use std::io::{self, Write}; -use std::path::{Path, MAIN_SEPARATOR}; +use flate2::{write::GzEncoder, Compression}; +use std::{ + fs::{self, File}, + io::{self, Write}, + path::{Path, MAIN_SEPARATOR}, +}; use tar::Builder; // todo: this is pretty involved. (re)factor this into its own crate diff --git a/src/transport.rs b/src/transport.rs index 41d86944..432c5df8 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -1,6 +1,6 @@ //! Transports for communicating with the docker daemon -use self::super::{Error, Result}; +use crate::{Error, Result}; use futures::{ future::{self, Either}, Future, IntoFuture, Stream, @@ -14,7 +14,9 @@ use hyper_openssl::HttpsConnector; use hyperlocal::UnixConnector; #[cfg(feature = "unix-socket")] use hyperlocal::Uri as DomainUri; +use log::debug; use mime::Mime; +use serde_derive::{Deserialize, Serialize}; use serde_json; use std::fmt; use tokio_io::{AsyncRead, AsyncWrite}; @@ -226,12 +228,12 @@ impl Transport { method: Method, endpoint: &str, body: Option<(B, Mime)>, - ) -> impl Future + ) -> impl Future where B: Into + 'static, { self.stream_upgrade(method, endpoint, body) - .map(|u| ::tty::Multiplexed::new(u)) + .map(|u| crate::tty::Multiplexed::new(u)) } /// Extract the error message content from an HTTP response that diff --git a/src/tty.rs b/src/tty.rs index c30a0388..038fde0a 100644 --- a/src/tty.rs +++ b/src/tty.rs @@ -1,12 +1,11 @@ +use crate::errors::Error; use byteorder::{BigEndian, ByteOrder, ReadBytesExt}; use bytes::BytesMut; -use errors::Error; -use std::io::Cursor; -use tokio_codec::Decoder; - use futures::{self, Async}; use hyper::rt::{Future, Stream}; -use std::io; +use log::trace; +use std::io::{self, Cursor}; +use tokio_codec::Decoder; use tokio_io::{AsyncRead, AsyncWrite}; #[derive(Debug)] @@ -25,12 +24,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 @@ -164,17 +163,17 @@ impl Multiplexed { impl futures::Stream for Multiplexed { type Item = Chunk; - type Error = ::Error; + type Error = crate::Error; - fn poll(&mut self) -> Result>, ::Error> { + fn poll(&mut self) -> Result>, crate::Error> { self.chunks.poll() } } impl Iterator for MultiplexedBlocking { - type Item = Result; + type Item = Result; - fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { self.chunks.next() } } @@ -199,7 +198,7 @@ macro_rules! delegate_io_write { delegate_io_write!(Multiplexed); delegate_io_write!(MultiplexedBlocking); -pub fn chunks(stream: S) -> impl futures::Stream +pub fn chunks(stream: S) -> impl futures::Stream where S: AsyncRead, { @@ -227,7 +226,7 @@ where }); util::stop_on_err(stream, |e| e.kind() != io::ErrorKind::UnexpectedEof) - .map_err(|e| ::Error::from(e)) + .map_err(|e| crate::Error::from(e)) } mod util {