-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update apache-commons to 1.26.0 and set PAX headers to address build reproducibility issue #4204
Conversation
This is a copy of this pull request with an extra commit that fixes the formatting, test, and modification time set by JIB issues. |
// In this particular place we have to use default modification time (1 second past epoch) | ||
// instead the modification time user might've set in JIB settings. That's because we have | ||
// no way to find out the modification time user might've set in JIB settings here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true. Jib intentionally doesn't allow setting the mod time of directories. Let's just remove the comment.
/** | ||
* Verifies that the modification time has been reset in the PAX headers. | ||
* | ||
* @param entry The archive entry in the layer. | ||
*/ | ||
private static void verifyThatModificationTimeIsReset(ArchiveEntry entry) { | ||
assertThat(entry.getLastModifiedDate().toInstant()) | ||
.isEqualTo(FileEntriesLayer.DEFAULT_MODIFICATION_TIME); | ||
} | ||
|
||
private static FileEntry layerEntry( | ||
Path source, AbsoluteUnixPath destination, FilePermissions permissions, String ownership) | ||
throws IOException { | ||
return new FileEntry( | ||
source, | ||
destination, | ||
FileEntriesLayer.DEFAULT_FILE_PERMISSIONS_PROVIDER.get(source, destination), | ||
FileEntriesLayer.DEFAULT_MODIFICATION_TIME); | ||
permissions, | ||
// Here we make sure to use a default modification time | ||
// since JIB will set modification time for all files to | ||
// the one set in JIB settings by a user. In case user | ||
// hasn't set it, JIB will use default modification time, | ||
// i.e. 1 second past January 1st, 1970 (1 second past epoch). | ||
FileEntriesLayer.DEFAULT_MODIFICATION_TIME, | ||
ownership); | ||
} | ||
|
||
private static FileEntry layerEntry( | ||
Path source, AbsoluteUnixPath destination, FilePermissions permissions) throws IOException { | ||
return layerEntry(source, destination, permissions, ""); | ||
} | ||
|
||
private static FileEntry layerEntry(Path source, AbsoluteUnixPath destination) | ||
throws IOException { | ||
return layerEntry( | ||
source, | ||
destination, | ||
FileEntriesLayer.DEFAULT_FILE_PERMISSIONS_PROVIDER.get(source, destination)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just revert this file back to its original state. The original author misunderstood this part. The PR shouldn't touch this file, and the existing tests will verify the correctness of your changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, upgrade the apache-commons-compress (#3964) to verify if it's working correctly.
@chanseokoh done. I had to update TarExtractorTest since it was failing now. Probably, newer version of apache-commons-compress (I used 1.26.0 instead of 1.23.0 from #3964) extracts modification timetamp with millisecond precision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally you should update jib-core/CHANGELOG
, jib-maven-plugin/CHANGELOG
and jib-gradle-plugin/CHANGELOG
about what is fixed.
BTW, I'm not the maintainer of this repo.
entry.setModTime(modTime.toEpochMilli()); | ||
|
||
String headerTime = Long.toString(modTime.getEpochSecond()); | ||
final long nanos = modTime.getNano(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with the PAX headers, so just asking: does it have to be the nanosecond precision? Like, what if someone decides to go with milli or microseconds? Is it possible? Not that I care as long as nano works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a post I was able to find:
This is important for example with the tarfile module with the pax tar format. The POSIX tar standard mandates storing the mtime in the extended header (if it is not an integer) with as much precision as is available in the underlying file system, and likewise to restore this time properly upon extraction.
So I'd say that it's better to store time with nanosecond precision. File systems that don't support this precision won't fail upon extraction: they'll simply truncate values.
CHANGELOG files were updated. |
Rebased on master. |
Co-authored-by: Mridula <[email protected]>
…s now used for PAX headers. Some parts of test were reverted. Code reformat.
…omment was removed. ReproducibleLayerBuilderTest.java was reverted to its original state.
…rieved with higher precision.
Rebased on master (2). |
// We have to use millisecond precision here. Taken from Instant.parse. | ||
final DateTimeFormatter parser = | ||
new DateTimeFormatterBuilder().parseCaseInsensitive().appendInstant(3).toFormatter(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@izogfif Is there is a reason we're testing with millisecond precision here? Curious since we opted for nanosecond precision above (ReproducibleLayerBuilder)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpeddada1 For some reason, the code below can't extract micro- and nanoseconds, it's limited to milliseconds (at least on Windows machine with NTFS).
In one of the methods below I had to add centiseconds and avoided having to use the same DateTimeFormatter since, conveniently, truncation to milliseconds yielded "0" as the third digit, and Instant.parse can parse centiseconds.
Pasting stacktrace of failing checks below: kokoro-macos:
kokoro-ubuntu
|
How can I check that current OS is macOS? It seems that storing files with millisecond precision on macOS is not supported. It seems that this is what's happening:
Possible solutions:
About these failures: if I update values ("expected") with new ones ("but was"), it should fix Ubuntu build. But won't this fail Windows build? |
…odification time with millisecond precision.
@mpeddada1 I finally found the contributor guide and was able to run tests on Ubuntu via:
but then
Apparently, I'm unable to make Jetty container start in Docker. Please re-run those workflows / kokoro-xxx tests on your end. |
I also noticed the Jetty failure locally. Don't know why. It is the test in
|
Thanks for looking into this! It is interesting that macos only goes to seconds precision. It is possible that the job still uses the old HFS+ format drive. That being said, I think verifying seconds precision should be sufficient. Re |
Yes, I think that PAX header changed checksums. I was expecting tests to fail on all OS (Windows, macOS, Ubuntu), but, apparently, before I fixed checksum checks, kokoro-windows tests were successful. No idea why. The tests have passed this time, too. |
Ah our coverage on Windows is fairly limited at the moment as we run integration tests only in ubuntu and MacOS. That's probably why we weren't able to see the failure in windows. |
So, about this pull request, what are the next steps? Is there something I need to do in order for it to be accepted (and a new build of JIB to be released)? |
No further action need, I'll go ahead and merge the PR. Thanks for your contribution @izogfif! |
Thanks for everyone who worked on this! Looking forward to seeing this get into a release! |
Fixes #4141 🛠️