Skip to content

commit: add --source-date-epoch and --rewrite-timestamp flags #6189

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

Merged

Conversation

nalind
Copy link
Member

@nalind nalind commented May 29, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

Add a --source-date-epoch flag, defaulting to $SOURCE_DATE_EPOCH if set, which sets the created-on date and the timestamp for the new history entries, but does not default to modifying the timestamps on contents in new layers.

Add a --rewrite-timestamp flag, which "clamps" timestamps in the new layers to not be later than the --source-date-epoch value if both the --rewrite-timestamp and --source-date-epoch flags were set.

How to verify it

New integration tests!

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

Does this PR introduce a user-facing change?

`buildah commit` now recognizes `--source-date-epoch` and `--rewrite-timestamp` flags, which affect the dates recorded in the new image's configuration and the timestamps on the contents of the new layer.

@openshift-ci openshift-ci bot added kind/feature Categorizes issue or PR as related to a new feature. approved labels May 29, 2025
@nalind nalind force-pushed the commit-source-date-epoch branch 6 times, most recently from 8507637 to 1c201ea Compare June 3, 2025 21:05
@@ -327,6 +348,9 @@ func commitCmd(c *cobra.Command, args []string, iopts commitInputOptions) error
timestamp := time.Unix(0, 0).UTC()
options.HistoryTimestamp = &timestamp
}
if exclusiveFlags > 1 {
return errors.New("can not use more then one timestamp option at at time")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return errors.New("can not use more then one timestamp option at at time")
return errors.New("cannot use more then one timestamp option at at time")

nit

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

run_buildah add --add-history "$cid" $TEST_SCRATCH_DIR/context/* /context
# commit using defaults
run_buildah commit "$cid" oci:$TEST_SCRATCH_DIR/default
# commit with an implicity-provided timestamp
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# commit with an implicity-provided timestamp
# commit with an implicitly-provided timestamp

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

@@ -1229,9 +1212,40 @@ func (i *containerImageRef) makeExtraImageContentDiff(includeFooter bool) (_ str
return diff.Name(), digester.Digest(), counter.Count, nil
}

func makeFilteredLayerWriteCloser(wc io.WriteCloser, layerModTime, layerLatestModTime *time.Time) io.WriteCloser {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: A small comment about this function will be helpful documenting precedence order between layerModTime and layerLatestModTime ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

PR LGTM just small nits and one question.

@nalind nalind force-pushed the commit-source-date-epoch branch from 1c201ea to a013447 Compare June 4, 2025 17:01
Add a --source-date-epoch flag, defaulting to $SOURCE_DATE_EPOCH if set,
which sets the created-on date and the timestamp for the new history
entries, but does not default to modifying the timestamps on contents in
new layers.

Add a --rewrite-timestamp flag, which "clamps" timestamps in the new
layers to not be later than the --source-date-epoch value if both
the --rewrite-timestamp and --source-date-epoch flags were set.

Signed-off-by: Nalin Dahyabhai <[email protected]>
@nalind nalind force-pushed the commit-source-date-epoch branch from a013447 to 6c82e7e Compare June 4, 2025 17:02
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

openshift-ci bot commented Jun 4, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc, nalind

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@flouthoc
Copy link
Collaborator

flouthoc commented Jun 4, 2025

@TomSweeneyRedHat @rhatdan PTAL

@TomSweeneyRedHat
Copy link
Member

LGTM

@TomSweeneyRedHat
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Jun 4, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit b8d8cc3 into containers:main Jun 4, 2025
37 checks passed
@nalind nalind deleted the commit-source-date-epoch branch June 4, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved kind/feature Categorizes issue or PR as related to a new feature. lgtm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants