Honour SOURCE_DATE_EPOCH for reproducible builds#176
Open
krishnapermi wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
I was trying to build a reproducible OCI image - same source, same digest every time - and noticed that containertool always writes 0 as the tar entry mtime and
Date(timeIntervalSince1970: 0)as the image creation timestamp, regardless of any environment variables. TheSOURCE_DATE_EPOCHconvention is the standard way to communicate a canonical build time to tools like this, and issue #41 tracks exactly this gap.Because tar entry mtimes feed into layer digest computation and the image timestamp is baked into the image config digest, both need to use the same epoch value for the build to be truly reproducible.
Modifications
mtime: Int = 0parameter (defaulting to 0, so existing behaviour is unchanged) toArchive.appendFile,Archive.appendDirectory,Archive.appendingFile,Archive.appendingDirectory, and all the recursive helpers inArchive+appending.swift.RegistryClient+publish.swift, readSOURCE_DATE_EPOCHfrom the environment once at the start of the publish call and thread it through to allArchivecalls and the image config timestamp.Plugins/ContainerImageBuilder/main.swift, extend the env-var filter (which already allowlistsCONTAINERTOOL_-prefixed vars) to also forwardSOURCE_DATE_EPOCHto thecontainertoolsubprocess.Result
When
SOURCE_DATE_EPOCHis set, containertool uses that value for all tar entry mtimes and the image creation timestamp, making layer and config digests deterministic across builds from the same source. When the variable is absent, behaviour is identical to before (mtime = 0, Unix epoch timestamp).Test Plan