Skip to content

Commit

Permalink
Merge pull request #18 from fussybeaver/v0.2.2
Browse files Browse the repository at this point in the history
Network API
  • Loading branch information
Niel Drummond authored May 31, 2019
2 parents 1c559d5 + 9701943 commit 3d6430e
Show file tree
Hide file tree
Showing 9 changed files with 1,669 additions and 46 deletions.
12 changes: 7 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ jobs:
- setup_remote_docker
- run: docker create -v /certs --name certs alpine:3.4 /bin/true
- run: docker run --rm -e SSL_SUBJECT=test.example.com --volumes-from certs paulczar/omgwtfssl
- run: docker run --rm -h test.example.com --volumes-from certs -d --privileged --name test-docker-daemon docker:stable-dind --storage-driver=overlay --tlsverify --tlscacert=/certs/ca.pem --tlscert=/certs/cert.pem --tlskey=/certs/key.pem
- run: docker run -h test.example.com --volumes-from certs -d --privileged --name test-docker-daemon docker:stable-dind --storage-driver=overlay --tlsverify --tlscacert=/certs/ca.pem --tlscert=/certs/cert.pem --tlskey=/certs/key.pem
- run: docker run --rm --volumes-from certs --privileged --rm --entrypoint=chmod docker:stable-dind 644 /certs/key.pem /certs/ca-key.pem
- run: docker build -t bollard .
- 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
- run: docker run -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.1
Expand All @@ -22,9 +23,10 @@ jobs:
- run: docker run --rm -e SSL_SUBJECT=test.example.com --volumes-from certs paulczar/omgwtfssl
- run: |
docker run -ti --volumes-from certs -w /certs frapsoft/openssl pkcs12 -export -out identity.pfx -inkey key.pem -in cert.pem -certfile ca.pem -passout pass:
- run: docker run --rm -h test.example.com --volumes-from certs -d --privileged --name test-docker-daemon docker:stable-dind --storage-driver=overlay --tlsverify --tlscacert=/certs/ca.pem --tlscert=/certs/cert.pem --tlskey=/certs/key.pem
- run: docker run -h test.example.com --volumes-from certs -d --privileged --name test-docker-daemon docker:stable-dind --storage-driver=overlay --tlsverify --tlscacert=/certs/ca.pem --tlscert=/certs/cert.pem --tlskey=/certs/key.pem
- run: docker run --rm --volumes-from certs --privileged --rm --entrypoint=chmod docker:stable-dind 644 /certs/key.pem /certs/ca-key.pem
- run: docker build -t bollard .
- 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
- run: docker run -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.1
Expand All @@ -49,7 +51,7 @@ jobs:
- checkout
- setup_remote_docker
- run: docker build -t bollard .
- run: docker run -ti --rm bollard cargo test --target x86_64-unknown-linux-gnu --doc --all-features
- run: docker run -ti --rm bollard cargo test --doc --all-features

workflows:
version: 2
Expand Down
42 changes: 21 additions & 21 deletions 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.3.0"
version = "0.3.1"
authors = ["Graham Lee <[email protected]>",
"Toby Lawrence <[email protected]>",
"Eric Kidd <[email protected]>",
Expand All @@ -24,41 +24,41 @@ test_tls = []
[dependencies]
arrayvec = "0.4.10"
base64 = "0.10.0"
bytes = "0.4.11"
bytes = "0.4.12"
chrono = { version = "0.4.6", features = ["serde"] }
dirs = "1.0.4"
env_logger = "0.6.0"
dirs = "1.0.5"
env_logger = "0.6.1"
failure = "0.1.5"
futures = "0.1.25"
futures = "0.1.27"
hex = "0.3.2"
http = "0.1.15"
hyper = { version = "0.12.23" }
hyper-openssl = { version = "0.7.0", optional = true }
hyper-tls = "0.3.1"
http = "0.1.17"
hyper = { version = "0.12.28" }
hyper-openssl = { version = "0.7.1", optional = true }
hyper-tls = "0.3.2"
log = "0.4.6"
mio = "0.6.16"
native-tls = "0.2.2"
openssl = { version = "0.10.16", optional = true }
serde = "1.0.85"
serde_derive = "1.0.85"
serde_json = "1.0.37"
tokio = "0.1.11"
native-tls = "0.2.3"
openssl = { version = "0.10.22", optional = true }
serde = "1.0.91"
serde_derive = "1.0.91"
serde_json = "1.0.39"
tokio = "0.1.19"
tokio-codec = "0.1.1"
tokio-io = "0.1.11"
tokio-reactor = "0.1.8"
tokio-timer = "0.2.9"
tokio-reactor = "0.1.9"
tokio-timer = "0.2.10"
url = "1.7.2"

[dev-dependencies]
tokio-executor = "0.1.6"
tokio-threadpool = "0.1.11"
tokio-executor = "0.1.7"
tokio-threadpool = "0.1.14"
flate2 = "1.0"
tar = "0.4.20"
yup-hyper-mock = "3.14.0"
yup-hyper-mock = "3.15.0"

[target.'cfg(unix)'.dependencies]
hyperlocal = "0.6.0"

[target.'cfg(windows)'.dependencies]
mio-named-pipes = "0.1.6"
winapi = "0.3.6"
winapi = "0.3.7"
12 changes: 8 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ install:
- cargo -V

build_script:
- ps: Get-VMNetworkAdapter -VMName *
- ps: Get-VMNetworkAdapter -All
- ps: Get-VMNetworkAdapter -VMName MobyLinuxVM | Set-VMNetworkAdapter -MacAddressSpoofing On
- ps: Get-NetAdapter
- ps: |
$ipv4 = (Test-Connection -ComputerName $env:ComputerName -Count 1).IPV4Address.IPAddressToString
Set-Item -path env:HOST_IP -value $ipv4
Expand All @@ -20,12 +24,12 @@ build_script:
docker build -t stefanscherer/registry-windows -f Dockerfile .
cd ../../../
- docker run -d -p 5000:5000 --restart=always --name registry stefanscherer/registry-windows
- docker pull hello-world:nanoserver
- docker pull hello-world:nanoserver-sac2016
- docker pull nanoserver/iis
- docker pull microsoft/nanoserver
- docker tag hello-world:nanoserver localhost:5000/hello-world:nanoserver
- docker pull microsoft/nanoserver@sha256:8f78a4a7da4464973a5cd239732626141aec97e69ba3e4023357628630bc1ee2
- docker tag hello-world:nanoserver-sac2016 localhost:5000/hello-world:nanoserver
- docker tag nanoserver/iis localhost:5000/nanoserver/iis
- docker tag microsoft/nanoserver localhost:5000/microsoft/nanoserver
- docker tag microsoft/nanoserver@sha256:8f78a4a7da4464973a5cd239732626141aec97e69ba3e4023357628630bc1ee2 localhost:5000/microsoft/nanoserver
- docker push localhost:5000/hello-world:nanoserver
- docker push localhost:5000/nanoserver/iis
- docker push localhost:5000/microsoft/nanoserver
Expand Down
43 changes: 28 additions & 15 deletions src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::hash::Hash;
use super::{Docker, DockerChain};
use docker::{FALSE_STR, TRUE_STR};
use either::EitherStream;
use network::EndpointIPAMConfig;

/// Parameters used in the [List Container API](../struct.Docker.html#method.list_containers)
///
Expand Down Expand Up @@ -89,8 +90,8 @@ where
fn into_array(self) -> Result<ArrayVec<[(K, V); 4]>, Error>;
}

impl<'a, T: AsRef<str> + ::std::cmp::Eq + ::std::hash::Hash>
ListContainersQueryParams<&'a str, String> for ListContainersOptions<T>
impl<'a, T: AsRef<str> + Eq + Hash> ListContainersQueryParams<&'a str, String>
for ListContainersOptions<T>
where
T: ::serde::Serialize,
{
Expand Down Expand Up @@ -314,6 +315,7 @@ where
pub io_maximum_bandwidth: Option<u64>,
pub masked_paths: Option<Vec<T>>,
pub readonly_paths: Option<Vec<T>>,
pub sysctls: Option<HashMap<T, T>>,
}

/// Storage driver name and configuration.
Expand Down Expand Up @@ -373,24 +375,13 @@ pub struct NetworkingConfig {
pub endpoints_config: HashMap<String, ContainerNetwork>,
}

/// EndpointIPAMConfig represents an endpoint's IPAM configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
#[allow(missing_docs)]
pub struct EndpointIPAMConfig {
#[serde(rename = "IPV4Address")]
pub ipv4_address: String,
#[serde(rename = "IPV6Address")]
pub ipv6_address: String,
}

/// Configuration for a network endpoint.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase", deny_unknown_fields)]
#[allow(missing_docs)]
pub struct ContainerNetwork {
#[serde(rename = "IPAMConfig")]
pub ipam_config: Option<EndpointIPAMConfig>,
pub ipam_config: Option<EndpointIPAMConfig<String>>,
pub links: Option<Vec<String>>,
pub aliases: Option<Vec<String>>,
pub mac_address: String,
Expand Down Expand Up @@ -465,6 +456,27 @@ pub struct Mount {
pub propagation: String,
}

/// Log of the health of a running container.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase", deny_unknown_fields)]
#[allow(missing_docs)]
pub struct LogStateHealth {
pub start: DateTime<Utc>,
pub end: DateTime<Utc>,
pub exit_code: u16,
pub output: String,
}

/// Health of a running container.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase", deny_unknown_fields)]
#[allow(missing_docs)]
pub struct StateHealth {
pub status: String,
pub failing_streak: u64,
pub log: Vec<LogStateHealth>,
}

/// Runtime status of the container.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase", deny_unknown_fields)]
Expand All @@ -482,6 +494,7 @@ pub struct State {
pub error: String,
pub started_at: DateTime<Utc>,
pub finished_at: DateTime<Utc>,
pub health: Option<StateHealth>,
}

/// Maps internal container port to external host port.
Expand Down Expand Up @@ -3701,7 +3714,7 @@ mod tests {

connector.m.insert(
format!("{}://5f", if cfg!(windows) { "net.pipe" } else { "unix" }),
"HTTP/1.1 200 OK\r\nServer: mock1\r\nContent-Type: application/json\r\nContent-Length: 2596\r\n\r\n{\"Id\":\"156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7\",\"Created\":\"2018-10-06T15:15:43.525300512Z\",\"Path\":\"/usr/sbin/run_uhttpd\",\"Args\":[],\"State\":{\"Status\":\"running\",\"Running\":true,\"Paused\":false,\"Restarting\":false,\"OOMKilled\":false,\"Dead\":false,\"Pid\":28837,\"ExitCode\":0,\"Error\":\"\",\"StartedAt\":\"2018-10-06T15:15:54.444625149Z\",\"FinishedAt\":\"2018-10-06T15:15:53.958358249Z\"},\"Image\":\"sha256:df0db1779d4d71e169756bbcc7757f3d3d8b99032f4022c44509bf9b8f297997\",\"ResolvConfPath\":\"/home/docker/containers/156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7/resolv.conf\",\"HostnamePath\":\"/home/docker/containers/156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7/hostname\",\"HostsPath\":\"/home/docker/containers/156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7/hosts\",\"LogPath\":\"/home/docker/containers/156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7/156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7-json.log\",\"Name\":\"/integration_test_restart_container\",\"RestartCount\":0,\"Driver\":\"overlay2\",\"Platform\":\"linux\",\"MountLabel\":\"\",\"ProcessLabel\":\"\",\"AppArmorProfile\":\"docker-default\",\"ExecIDs\":null,\"HostConfig\":{},\"GraphDriver\":{\"Data\":null,\"Name\":\"overlay2\"},\"Mounts\":[],\"Config\":{\"Hostname\":\"156ffa6b4233\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"ExposedPorts\":{\"80/tcp\":{}},\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[],\"Cmd\":null,\"Image\":\"fnichol/uhttpd\",\"Volumes\":{\"/www\":{}},\"WorkingDir\":\"\",\"Entrypoint\":[\"/usr/sbin/run_uhttpd\",\"-f\",\"-p\",\"80\",\"-h\",\"/www\"],\"OnBuild\":null,\"Labels\":{}},\"NetworkSettings\":{\"Bridge\":\"\",\"SandboxID\":\"20cd513ef83bc14934be89953d22aab5a54c7769b07c8e93e90f0227d0aba96b\",\"HairpinMode\":false,\"LinkLocalIPv6Address\":\"\",\"LinkLocalIPv6PrefixLen\":0,\"Ports\":{\"80/tcp\":null},\"SandboxKey\":\"/var/run/docker/netns/20cd513ef83b\",\"SecondaryIPAddresses\":null,\"SecondaryIPv6Addresses\":null,\"EndpointID\":\"992f7e94fd721f627d9d1611c27b477d39b959c209286c38426215ea764f6d63\",\"Gateway\":\"172.17.0.1\",\"GlobalIPv6Address\":\"\",\"GlobalIPv6PrefixLen\":0,\"IPAddress\":\"172.17.0.3\",\"IPPrefixLen\":16,\"IPv6Gateway\":\"\",\"MacAddress\":\"02:42:ac:11:00:03\",\"Networks\":{\"bridge\":{\"IPAMConfig\":null,\"Links\":null,\"Aliases\":null,\"NetworkID\":\"424a1638d72f8984c670bc8bf269102360f24bd356188635ab359cb0b0792b20\",\"EndpointID\":\"992f7e94fd721f627d9d1611c27b477d39b959c209286c38426215ea764f6d63\",\"Gateway\":\"172.17.0.1\",\"IPAddress\":\"172.17.0.3\",\"IPPrefixLen\":16,\"IPv6Gateway\":\"\",\"GlobalIPv6Address\":\"\",\"GlobalIPv6PrefixLen\":0,\"MacAddress\":\"02:42:ac:11:00:03\",\"DriverOpts\":null}}}}\r\n\r\n".to_string()
"HTTP/1.1 200 OK\r\nServer: mock1\r\nContent-Type: application/json\r\nContent-Length: 2759\r\n\r\n{\"Id\":\"156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7\",\"Created\":\"2018-10-06T15:15:43.525300512Z\",\"Path\":\"/usr/sbin/run_uhttpd\",\"Args\":[],\"State\":{\"Status\":\"running\",\"Running\":true,\"Paused\":false,\"Restarting\":false,\"OOMKilled\":false,\"Dead\":false,\"Pid\":28837,\"ExitCode\":0,\"Error\":\"\",\"StartedAt\":\"2018-10-06T15:15:54.444625149Z\",\"FinishedAt\":\"2018-10-06T15:15:53.958358249Z\",\"Health\":{\"Status\":\"healthy\",\"FailingStreak\":0,\"Log\":[{\"Start\":\"2019-05-03T15:19:37.238626547Z\",\"End\":\"2019-05-03T15:19:37.362289957Z\",\"ExitCode\":0,\"Output\":\"\"}]}},\"Image\":\"sha256:df0db1779d4d71e169756bbcc7757f3d3d8b99032f4022c44509bf9b8f297997\",\"ResolvConfPath\":\"/home/docker/containers/156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7/resolv.conf\",\"HostnamePath\":\"/home/docker/containers/156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7/hostname\",\"HostsPath\":\"/home/docker/containers/156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7/hosts\",\"LogPath\":\"/home/docker/containers/156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7/156ffa6b4233d93b91dc3185b9de7225c22350d55a6db250549039a7e53efda7-json.log\",\"Name\":\"/integration_test_restart_container\",\"RestartCount\":0,\"Driver\":\"overlay2\",\"Platform\":\"linux\",\"MountLabel\":\"\",\"ProcessLabel\":\"\",\"AppArmorProfile\":\"docker-default\",\"ExecIDs\":null,\"HostConfig\":{},\"GraphDriver\":{\"Data\":null,\"Name\":\"overlay2\"},\"Mounts\":[],\"Config\":{\"Hostname\":\"156ffa6b4233\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"ExposedPorts\":{\"80/tcp\":{}},\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[],\"Cmd\":null,\"Image\":\"fnichol/uhttpd\",\"Volumes\":{\"/www\":{}},\"WorkingDir\":\"\",\"Entrypoint\":[\"/usr/sbin/run_uhttpd\",\"-f\",\"-p\",\"80\",\"-h\",\"/www\"],\"OnBuild\":null,\"Labels\":{}},\"NetworkSettings\":{\"Bridge\":\"\",\"SandboxID\":\"20cd513ef83bc14934be89953d22aab5a54c7769b07c8e93e90f0227d0aba96b\",\"HairpinMode\":false,\"LinkLocalIPv6Address\":\"\",\"LinkLocalIPv6PrefixLen\":0,\"Ports\":{\"80/tcp\":null},\"SandboxKey\":\"/var/run/docker/netns/20cd513ef83b\",\"SecondaryIPAddresses\":null,\"SecondaryIPv6Addresses\":null,\"EndpointID\":\"992f7e94fd721f627d9d1611c27b477d39b959c209286c38426215ea764f6d63\",\"Gateway\":\"172.17.0.1\",\"GlobalIPv6Address\":\"\",\"GlobalIPv6PrefixLen\":0,\"IPAddress\":\"172.17.0.3\",\"IPPrefixLen\":16,\"IPv6Gateway\":\"\",\"MacAddress\":\"02:42:ac:11:00:03\",\"Networks\":{\"bridge\":{\"IPAMConfig\":null,\"Links\":null,\"Aliases\":null,\"NetworkID\":\"424a1638d72f8984c670bc8bf269102360f24bd356188635ab359cb0b0792b20\",\"EndpointID\":\"992f7e94fd721f627d9d1611c27b477d39b959c209286c38426215ea764f6d63\",\"Gateway\":\"172.17.0.1\",\"IPAddress\":\"172.17.0.3\",\"IPPrefixLen\":16,\"IPv6Gateway\":\"\",\"GlobalIPv6Address\":\"\",\"GlobalIPv6PrefixLen\":0,\"MacAddress\":\"02:42:ac:11:00:03\",\"DriverOpts\":null}}}}\r\n\r\n".to_string()
);

let docker = Docker::connect_with_host_to_reply(connector, "_".to_string(), 5).unwrap();
Expand Down
1 change: 0 additions & 1 deletion src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ mod tests {
let results = docker.inspect_exec("68099c450e6a");

let future = results.map(|result| {
println!(":::{:?}", result);
assert_eq!(
"/etc/config/uhttpd".to_string(),
result.process_config.arguments[0]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ pub mod errors;
pub mod exec;
pub mod image;
mod named_pipe;
pub mod network;
mod options;
mod read;
pub mod system;
Expand Down
Loading

0 comments on commit 3d6430e

Please sign in to comment.