Skip to content

Commit 8bdfd2a

Browse files
author
Pietro Albini
authored
Merge pull request #24 from Nemo157/record-image-hash
2 parents 38fa8c3 + e94972a commit 8bdfd2a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## Unreleased
77

8+
### Changed
9+
10+
- Added logging of exact image hash used during build
11+
812
## [0.7.1] - 2020-05-20
913

1014
### Changed

src/cmd/sandbox.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ impl SandboxImage {
2828
/// This will access the network to download the image from the registry. If pulling fails an
2929
/// error will be returned instead.
3030
pub fn remote(name: &str) -> Result<Self, Error> {
31-
let image = SandboxImage { name: name.into() };
31+
let mut image = SandboxImage { name: name.into() };
3232
info!("pulling image {} from Docker Hub", name);
3333
Command::new_workspaceless("docker")
3434
.args(&["pull", &name])
3535
.run()?;
36+
if let Some(name_with_hash) = image.get_name_with_hash() {
37+
image.name = name_with_hash;
38+
info!("pulled image {}", image.name);
39+
}
3640
image.ensure_exists_locally()?;
3741
Ok(image)
3842
}
@@ -45,6 +49,22 @@ impl SandboxImage {
4549
.run()?;
4650
Ok(())
4751
}
52+
53+
fn get_name_with_hash(&self) -> Option<String> {
54+
Command::new_workspaceless("docker")
55+
.args(&[
56+
"inspect",
57+
&self.name,
58+
"--format",
59+
"{{index .RepoDigests 0}}",
60+
])
61+
.log_output(false)
62+
.run_capture()
63+
.ok()?
64+
.stdout_lines()
65+
.first()
66+
.cloned()
67+
}
4868
}
4969

5070
/// Whether to mount a path in the sandbox with write permissions or not.

0 commit comments

Comments
 (0)