-
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
Make image builds reproducible #4142
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
jib-core/src/main/java/com/google/cloud/tools/jib/image/ReproducibleLayerBuilder.java
Outdated
Show resolved
Hide resolved
jib-core/src/main/java/com/google/cloud/tools/jib/image/ReproducibleLayerBuilder.java
Show resolved
Hide resolved
Just so you know, I am not one of the maintainers of this repo. |
I think this also fixes #4131 |
I don't suppose anybody has published a build with this PR in it somewhere? We really need this in order to use Jib and are having trouble pinning commons-compress in our Gradle build. |
jib-core/src/test/java/com/google/cloud/tools/jib/image/ReproducibleLayerBuilderTest.java
Outdated
Show resolved
Hide resolved
@bjornbugge Thanks so much for this fix! It appears that the test jobs are failing with the following error:
Removing the extra space in the import statements in |
Co-authored-by: Mridula <[email protected]>
Logging stacktrace:
|
return new FileEntry( | ||
source, | ||
destination, | ||
FileEntriesLayer.DEFAULT_FILE_PERMISSIONS_PROVIDER.get(source, destination), | ||
FileEntriesLayer.DEFAULT_MODIFICATION_TIME); | ||
Files.getLastModifiedTime(source).toInstant()); |
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.
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.
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.
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.
@mpeddada1 Thanks for taking a look at this. I've fixed the three tests that failed -- I thought I'd run the entire test suite locally, but clearly I had forgot :P (I guess I was in a hurry to make a local version of jib that we can use in our internal tooling) |
// Here we make sure to use the actual modification-time here because that's what would happen in | ||
// regular use when copying the file from disk into the layer. |
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.
No, the regular use is to force setting the file timestamp to epoch+1 by default. The only other alternative for the user is to set a static time. Jib never sets the original timestamp of the source file.
From the Jib plugin doc:
The value should either be
EPOCH_PLUS_SECOND
to set the timestamps to Epoch + 1 second (default behavior), or an ISO 8601 date-time parsable with DateTimeFormatter.ISO_DATE_TIME such as 2019-07-15T10:15:30+09:00 or 2011-12-03T22:42:05Z.
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.
Yes, I can see my comment was a bit unclear. What I meant was that in normal use, Jib reads in files from disk and they have some "real" modification time. Then Jib is supposed to reset this, but that didn't happen (or at least didn't happen "enough" because there were still PAX headers with the timestamps in them).
Because the test helper created test files where the modtime was already reset, this issue wasn't visible in the test suite.
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.
Then Jib is supposed to reset this, but that didn't happen (or at least didn't happen "enough" because there were still PAX headers with the timestamps in them).
This does happen. To clarify, the ordinary modification time is correctly set to epoch+1. It's just that the newer apache compress library added or set some new PAX headers with timestamp values. AFAICT, the mod time and the time values in PAX headers are independent. Everything worked fine without this PR, except that the new headers had dynamic values hence affected reproducibility. As long as we set the ordinary mod time to epoch+1, I think it shouldn't matter what time you set for the PAX headers. So ideally, I think what we need to test is these two:
- Verify that Jib continues to set the ordinary mod time to epoch+1 by default.
- Verify that Jib wipes out the time PAX headers. I think the value doesn't matter, as long as people don't complain.
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.
Ad 1: The PAX headers take precedence it seems, so I'll set them to 1 and try to switch the ordering like you suggested below 👍
Ad 2: I believe that testing the wiping of the headers is captured in the existing test case testToBlob_reproducibility
, as it compares the raw bytes. This test would fail after I updated the helper function here, hence my point with the old version of this helper "hiding" the issue with PAX headers.
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.
- They're set to 1 now and it's asserted (again).
- If I disable the PAX header reset then the test
testToBlob_reproducibility
fails because of mismatched byte arrays. So I'd argue that this is covered as well :)
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.
Ah, yes of course, I forgot that it's user-configurable 👍
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.
Although - I'm a bit at a loss as to where the modTime is supposed to be reset. In line 79 and 167 in ReproducibleLayerBuilder.kt
there are calls to .setModTime
. In the former case, for directories, it's always set to EPOCH+1 regardless of any user settings. In the latter case, for files, it's always set to the file's real value on disk, which is not reproducible. Are there any other places in the code base where the modification time could've been reset?
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.
167 is the user-configured value. Just set both the PAX headers and setModTime()
to the same timestamp. For the (Jib-created) directiories, it is not customizable and always set to epoch+1.
To recap, just set the same value as Jib does now.
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.
Hi @chanseokoh - I've been away from this work for a while due to other things. I've read the code more carefully now and I'll now understand that I was confused earlier as to where the responsibility of (re)setting the datetime lies. I'll set the PAX headers to the same timestamp as setModTime 👍
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.
@bjornbugge too bad that you missed the release 3.4.1.
jib-core/src/test/java/com/google/cloud/tools/jib/image/ReproducibleLayerBuilderTest.java
Show resolved
Hide resolved
Looks like the format check is failing
Please see https://github.com/google/google-java-format |
Thanks for the observation @diegomarquezp! @bjornbugge try running Additionally, to @chanseokoh's suggestion in #4142 (comment), we haven't heard back from you on this so to reiterate - We learned that clearing the PAX header isn't sufficient and since the |
Could someone review this, please? Having reproducible builds again after 3+ months would be nice. |
@izogfif it has been reviewed. It's waiting on the PR author. |
@chanseokoh I see, this "Review required" message at the bottom of this issue page on GitHub made me misunderstand what's happening. Previously in this comment you wrote:
Where "167" is the number of line in
and pass this value into method private static void clearTimeHeaders(TarArchiveEntry entry) {
entry.setModTime(FileEntriesLayer.DEFAULT_MODIFICATION_TIME.toEpochMilli());
entry.addPaxHeader("mtime", "1");
entry.addPaxHeader("atime", "1");
entry.addPaxHeader("ctime", "1");
entry.addPaxHeader("LIBARCHIVE.creationtime", "1");
} to this: private static void clearTimeHeaders(TarArchiveEntry entry, Instant modTime) {
entry.setModTime(modTime.toEpochMilli());
// PAX headers use <seconds>.<nanoseconds> format
String headerTime = Long.toString(modTime.getEpochSecond());
final long nanos = modTime.getNano();
if (nanos > 0) {
headerTime += "." + nanos;
}
entry.addPaxHeader("mtime", headerTime);
entry.addPaxHeader("atime", headerTime);
entry.addPaxHeader("ctime", headerTime);
entry.addPaxHeader("LIBARCHIVE.creationtime", headerTime);
} ?
|
@izogfif I cannot confirm the correctness of the implementation details of yours, but you got the right idea. |
@chanseokoh I've made some changes and created a pull request with one extra commit. Please take a look here. |
This PR is obsolete in favor of #4204. |
Closing in favor of #4204. Thanks for getting us started with this fix! |
Thanks for taking this over for me, @izogfif. Looking forward to a new release with this included :) |
Fixes #4141 🛠️