Skip to content

Commit

Permalink
update docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
pasberth authored and eldesh committed Jan 30, 2019
1 parent 3bf9efb commit 59614c1
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 130 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
build:
working_directory: /tmp/dockworker
docker:
- image: eldesh/rust:1.26.0
- image: eldesh/rust:1.31.1
environment:
DOCKER_VERSION: 18.03.1-ce
steps:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
key: cache-cargo-target-{{ .Environment.CIRCLE_JOB }}-{{ .Environment.CIRCLECI_CACHE_VERSION }}-{{ checksum "/tmp/build-dep" }}
- run:
name: Checking source code style
command: cargo fmt -- --write-mode "diff"
command: cargo fmt -- --check
- run:
name: Build project
command: |
Expand Down
2 changes: 1 addition & 1 deletion examples/attach-container.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate dockworker;
extern crate hyper;

use dockworker::{ContainerCreateOptions, ContainerHostConfig, Docker, container::AttachContainer};
use dockworker::{container::AttachContainer, ContainerCreateOptions, ContainerHostConfig, Docker};
use std::io::{BufRead, BufReader};

fn main() {
Expand Down
3 changes: 2 additions & 1 deletion examples/build-image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ fn main() {
.write_all(
r#"FROM alpine:edge
RUN echo Hi mum
"#.as_bytes(),
"#
.as_bytes(),
)
.unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/containers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate dockworker;

use dockworker::{Docker, container::ContainerFilters};
use dockworker::{container::ContainerFilters, Docker};

fn main() {
let docker = Docker::connect_with_defaults().unwrap();
Expand Down
8 changes: 5 additions & 3 deletions examples/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ fn main() {

println!("History:");
match history {
Ok(changes) => for change in changes {
println!("{:#?}", change);
},
Ok(changes) => {
for change in changes {
println!("{:#?}", change);
}
}
Err(e) => {
println!("Error {}", e);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/prune-image.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate dockworker;

use dockworker::{Docker, container::ContainerFilters};
use dockworker::{container::ContainerFilters, Docker};

fn main() {
let docker = Docker::connect_with_defaults().unwrap();
Expand Down
5 changes: 4 additions & 1 deletion examples/push.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
extern crate dockworker;
extern crate hyper;

use dockworker::{Docker, credentials::{Credential, UserPassword}};
use dockworker::{
credentials::{Credential, UserPassword},
Docker,
};

fn main() {
let mut docker = Docker::connect_with_defaults().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.26.0
1.31.1
177 changes: 75 additions & 102 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use std::result;
use std::time::Duration;
use url;

use container::{AttachResponse, Container, ContainerFilters, ContainerInfo, ExecInfo, ExitStatus,
LogResponse};
use container::{
AttachResponse, Container, ContainerFilters, ContainerInfo, ExecInfo, ExitStatus, LogResponse,
};
pub use credentials::{Credential, UserPassword};
use errors::*;
use filesystem::FilesystemChange;
Expand Down Expand Up @@ -169,7 +170,8 @@ impl Docker {
&cert_path.join("key.pem"),
&cert_path.join("cert.pem"),
&cert_path.join("ca.pem"),
).chain_err(&mkerr)
)
.chain_err(&mkerr)
} else {
Docker::connect_with_http(&host).chain_err(&mkerr)
}
Expand Down Expand Up @@ -456,7 +458,8 @@ impl Docker {

pub fn processes(&self, container: &Container) -> Result<Vec<Process>> {
let top = self.container_top(container)?;
Ok(top.Processes
Ok(top
.Processes
.iter()
.map(|process| {
let mut p = Process::default();
Expand Down Expand Up @@ -773,9 +776,11 @@ impl Docker {
let mut headers = self.headers().clone();
let application_tar: mime::Mime = "application/x-tar".parse()?;
headers.set::<ContentType>(ContentType(application_tar));
let res =
self.http_client()
.post_file(&headers, &format!("/images/load?quiet={}", quiet), path)?;
let res = self.http_client().post_file(
&headers,
&format!("/images/load?quiet={}", quiet),
path,
)?;
if !res.status.is_success() {
return Err(serde_json::from_reader::<_, DockerError>(res)?.into());
}
Expand All @@ -791,7 +796,8 @@ impl Docker {
// looking for file name like XXXXXXXXXXXXXX.json
if path.extension() == Some(OsStr::new("json")) && path != Path::new("manifest.json") {
let stem = path.file_stem().unwrap(); // contains .json
let id = stem.to_str()
let id = stem
.to_str()
.ok_or(ErrorKind::Unknown(format!("convert to String: {:?}", stem)))?;
return Ok(ImageId::new(id.to_string()));
}
Expand Down Expand Up @@ -1007,53 +1013,41 @@ mod tests {
.create_image(name, tag)
.map(|sts| sts.for_each(|st| assert!(st.is_ok())));
assert!(sts.is_ok());
assert!(
docker
.remove_image(&format!("{}:{}", name, tag), None, None)
.is_ok()
);
assert!(docker
.remove_image(&format!("{}:{}", name, tag), None, None)
.is_ok());
}

#[test]
fn create_remove_container() {
let docker = Docker::connect_with_defaults().unwrap();
let (name, tag) = ("hello-world", "linux");
assert!(
docker
.create_image(name, tag)
.map(|sts| sts.for_each(|st| println!("{:?}", st)))
.is_ok()
);
assert!(docker
.create_image(name, tag)
.map(|sts| sts.for_each(|st| println!("{:?}", st)))
.is_ok());
let mut create = ContainerCreateOptions::new(&format!("{}:{}", name, tag));
create.host_config(ContainerHostConfig::new());

assert!(
docker
.create_container(Some("dockworker_test"), &create)
.is_ok()
);
assert!(
docker
.remove_container("dockworker_test", None, None, None)
.is_ok()
);
assert!(
docker
.remove_image(&format!("{}:{}", name, tag), None, None)
.is_ok()
);
assert!(docker
.create_container(Some("dockworker_test"), &create)
.is_ok());
assert!(docker
.remove_container("dockworker_test", None, None, None)
.is_ok());
assert!(docker
.remove_image(&format!("{}:{}", name, tag), None, None)
.is_ok());
}

#[test]
fn auto_remove_container() {
let docker = Docker::connect_with_defaults().unwrap();
let (name, tag) = ("alpine", "3.7");
assert!(
docker
.create_image(name, tag)
.map(|sts| sts.for_each(|st| println!("{:?}", st)))
.is_ok()
);
assert!(docker
.create_image(name, tag)
.map(|sts| sts.for_each(|st| println!("{:?}", st)))
.is_ok());
let mut host_config = ContainerHostConfig::new();
host_config.auto_remove(true);
let mut create = ContainerCreateOptions::new(&format!("{}:{}", name, tag));
Expand All @@ -1069,20 +1063,16 @@ mod tests {
.remove_container("dockworker_auto_remove_container", None, None, None)
.is_err() // 'no such container' or 'removel container in progress'
);
assert!(
docker
.remove_image(&format!("{}:{}", name, tag), Some(true), None)
.is_ok()
);
assert!(docker
.remove_image(&format!("{}:{}", name, tag), Some(true), None)
.is_ok());
}

fn pull_image(docker: &Docker, name: &str, tag: &str) {
assert!(
docker
.create_image(name, tag)
.map(|sts| sts.for_each(|st| println!("{:?}", st)))
.is_ok()
);
assert!(docker
.create_image(name, tag)
.map(|sts| sts.for_each(|st| println!("{:?}", st)))
.is_ok());
}

#[test]
Expand All @@ -1097,11 +1087,9 @@ mod tests {
}

assert!(docker.remove_image("alpine:latest", None, None).is_ok());
assert!(
docker
.load_image(false, Path::new("dockworker_test_alpine.tar"))
.is_ok()
);
assert!(docker
.load_image(false, Path::new("dockworker_test_alpine.tar"))
.is_ok());
assert!(remove_file("dockworker_test_alpine.tar").is_ok());
}

Expand All @@ -1111,11 +1099,9 @@ mod tests {
{
pull_image(&docker, name, tag);
f(name, tag);
assert!(
docker
.remove_image(&format!("{}:{}", name, tag), None, None)
.is_ok()
);
assert!(docker
.remove_image(&format!("{}:{}", name, tag), None, None)
.is_ok());
}

#[test]
Expand All @@ -1126,20 +1112,16 @@ mod tests {
with_image(&docker, name, tag, |name, tag| {
let mut create = ContainerCreateOptions::new(&format!("{}:{}", name, tag));
create.cmd("ls".to_string());
assert!(
docker
.create_container(Some(container_name), &create)
.is_ok()
);
assert!(docker
.create_container(Some(container_name), &create)
.is_ok());
assert_eq!(
docker.wait_container(container_name).unwrap(),
ExitStatus::new(0)
);
assert!(
docker
.remove_container(container_name, None, None, None)
.is_ok()
);
assert!(docker
.remove_container(container_name, None, None, None)
.is_ok());
})
}

Expand Down Expand Up @@ -1259,7 +1241,8 @@ mod tests {
let container = docker.create_container(None, &create_options).unwrap();
docker.start_container(&container.id).unwrap();
let mut log = docker.log_container(&container.id, &log_options).unwrap();
let once = log.output()
let once = log
.output()
.unwrap()
.replace(|c| c == '\r' || c == '\n', "")
.to_owned();
Expand Down Expand Up @@ -1306,18 +1289,14 @@ mod tests {
let exp_stdout = File::open(root.join(exps[0])).unwrap();
let exp_stderr = File::open(root.join(exps[1])).unwrap();

assert!(
exp_stdout
.bytes()
.map(|e| e.ok())
.eq(cont.stdout.bytes().map(|e| e.ok()))
);
assert!(
exp_stderr
.bytes()
.map(|e| e.ok())
.eq(cont.stderr.bytes().map(|e| e.ok()))
);
assert!(exp_stdout
.bytes()
.map(|e| e.ok())
.eq(cont.stdout.bytes().map(|e| e.ok())));
assert!(exp_stderr
.bytes()
.map(|e| e.ok())
.eq(cont.stderr.bytes().map(|e| e.ok())));

docker.wait_container(&container.id).unwrap();
docker
Expand Down Expand Up @@ -1363,18 +1342,14 @@ mod tests {
let exp_stdout = File::open(root.join(exps[0])).unwrap();
let exp_stderr = File::open(root.join(exps[1])).unwrap();

assert!(
exp_stdout
.bytes()
.map(|e| e.ok())
.eq(cont.stdout.bytes().map(|e| e.ok()))
);
assert!(
exp_stderr
.bytes()
.map(|e| e.ok())
.eq(cont.stderr.bytes().map(|e| e.ok()))
);
assert!(exp_stdout
.bytes()
.map(|e| e.ok())
.eq(cont.stdout.bytes().map(|e| e.ok())));
assert!(exp_stderr
.bytes()
.map(|e| e.ok())
.eq(cont.stderr.bytes().map(|e| e.ok())));

let exec_inspect = docker.exec_inspect(&exec_instance.id).unwrap();

Expand Down Expand Up @@ -1422,12 +1397,10 @@ mod tests {
});

let stdout_buffer = BufReader::new(cont.stdout);
assert!(
stdout_buffer
.lines()
.map(|line| line.unwrap())
.eq(signalstrs)
);
assert!(stdout_buffer
.lines()
.map(|line| line.unwrap())
.eq(signalstrs));

trace!("wait");
assert_eq!(
Expand Down
Loading

0 comments on commit 59614c1

Please sign in to comment.