Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make image builds reproducible #4142

Closed
wants to merge 8 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private void add(TarArchiveEntry tarArchiveEntry) throws IOException {
dir.setGroupId(0);
dir.setUserName("");
dir.setGroupName("");
clearTimeHeaders(dir);
add(dir);
}

Expand All @@ -95,6 +96,13 @@ private List<TarArchiveEntry> getSortedEntries() {
}
}

private static void clearTimeHeaders(TarArchiveEntry entry) {
bjornbugge marked this conversation as resolved.
Show resolved Hide resolved
entry.addPaxHeader("mtime", "0");
bjornbugge marked this conversation as resolved.
Show resolved Hide resolved
entry.addPaxHeader("atime", "0");
entry.addPaxHeader("ctime", "0");
entry.addPaxHeader("LIBARCHIVE.creationtime", "0");
}

private static void setUserAndGroup(TarArchiveEntry entry, FileEntry layerEntry) {
entry.setUserId(0);
entry.setGroupId(0);
Expand Down Expand Up @@ -158,6 +166,7 @@ public Blob build() throws IOException {
entry.setMode((entry.getMode() & ~0777) | layerEntry.getPermissions().getPermissionBits());
entry.setModTime(layerEntry.getModificationTime().toEpochMilli());
setUserAndGroup(entry, layerEntry);
clearTimeHeaders(entry);

uniqueTarArchiveEntries.add(entry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ private static void verifyNextTarArchiveEntryIsDirectory(
assertThat(extractionPathEntry.getMode()).isEqualTo(TarArchiveEntry.DEFAULT_DIR_MODE);
}

private static FileEntry defaultLayerEntry(Path source, AbsoluteUnixPath destination) {
private static FileEntry defaultLayerEntry(Path source, AbsoluteUnixPath destination) throws IOException {
return new FileEntry(
source,
destination,
FileEntriesLayer.DEFAULT_FILE_PERMISSIONS_PROVIDER.get(source, destination),
FileEntriesLayer.DEFAULT_MODIFICATION_TIME);
Files.getLastModifiedTime(source).toInstant());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to leave this in as FileEntriesLayer.DEFAULT_MODIFICATION_TIME? I think this helper method was initially meant to create a FileEntry with fixed permissions and modification time for testing purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason that this slipped through the test suite was partly because of this default value, actually. The logic that should reset the modification time header wasn't tested because the tests reset it automatically here. I've added a clarifying comment and also some more helpers to make it easier to add test layers with the actual mod-time of the temp files.

}

@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
Expand Down
Loading