Skip to content
This repository was archived by the owner on Mar 23, 2021. It is now read-only.

Commit 24481d1

Browse files
da-kamithomaseizinger
authored andcommitted
Make it work on windows AND unix
1 parent 2d04d44 commit 24481d1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/docker/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use http::Uri;
55
use shiplift::{
66
ContainerOptions, Docker, LogsOptions, NetworkCreateOptions, PullOptions, RmContainerOptions,
77
};
8-
use std::{env::VarError, net::Ipv4Addr, path::Path};
8+
use std::{net::Ipv4Addr, path::Path};
99
use tokio::prelude::stream::Stream;
1010

1111
pub mod bitcoin;
@@ -186,16 +186,20 @@ fn parse_ip(uri: String) -> anyhow::Result<Ipv4Addr> {
186186
Ok(ip)
187187
}
188188

189+
#[cfg(feature = "windows")]
189190
fn new_docker_client() -> anyhow::Result<Docker> {
190-
let uri = match std::env::var("DOCKER_HOST") {
191-
Ok(docker_host) => https_docker_host(docker_host)?,
192-
Err(VarError::NotPresent) => Uri::from_static("unix://var/run/docker.sock"),
193-
Err(e) => return Err(anyhow::Error::from(e)),
194-
};
191+
match std::env::var("DOCKER_HOST") {
192+
Ok(docker_host) => Ok(Docker::host(https_docker_host(docker_host)?)),
193+
_ => anyhow::bail!("DOCKER_HOST must be set in windows"),
194+
}
195+
}
195196

196-
Ok(Docker::host(uri))
197+
#[cfg(feature = "unix")]
198+
fn new_docker_client() -> anyhow::Result<Docker> {
199+
Ok(Docker::unix("/var/run/docker.sock"))
197200
}
198201

202+
#[allow(dead_code)]
199203
// In order for to communicate with docker on windows, we need to patch the content of the
200204
// DOCKER_HOST variable to use `https` as the scheme because hyper-openssl otherwise does not
201205
// establish a TLS connection.

0 commit comments

Comments
 (0)