Skip to content

dockerfile: support SOURCE_DATE_EPOCH=context #6602

Open
tonistiigi wants to merge 2 commits intomoby:masterfrom
tonistiigi:epoch-arg-context
Open

dockerfile: support SOURCE_DATE_EPOCH=context #6602
tonistiigi wants to merge 2 commits intomoby:masterfrom
tonistiigi:epoch-arg-context

Conversation

@tonistiigi
Copy link
Copy Markdown
Member

Resolve SOURCE_DATE_EPOCH=context in the Dockerfile frontend from the
main build context and pass the resolved numeric epoch through normal
ARG handling and exporter metadata.

Use git commit time for git contexts, HTTP Last-Modified when present,
and newest archive entry mtime for HTTP archives. Leave local contexts
unset.

depends on #6601

@Inonameraja
Copy link
Copy Markdown

Inonameraja commented Mar 24, 2026 via email

@tonistiigi tonistiigi marked this pull request as ready for review March 24, 2026 22:53
@tonistiigi
Copy link
Copy Markdown
Member Author

Added another commit to also support SOURCE_DATE_EPOCH=named-context. This can be used to turn remote Git/HTTP URL used inside the Dockerfile as a epoch source.

I'm not sure if we should take this into v0.29 . It's turned out to be a big PR and I don't want to force it close to the release window if anyone still wants to discuss.


- git context: commit time
- HTTP context: `Last-Modified`, or the newest archive entry mtime when building from an archive without `Last-Modified`
- local context: ignored, leaving `SOURCE_DATE_EPOCH` unset
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any reason not to use mtime of the context dir?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think the local context files will ever have a stable meaningful mtime. Also question would be how many files we need to transfer to establish that? Git and HTTP are complete sources with immutable metadata, while local dirs are files pulled based on the ADD/COPY commands.

Resolve SOURCE_DATE_EPOCH=context in the Dockerfile frontend from the
main build context and pass the resolved numeric epoch through normal
ARG handling and exporter metadata.

Use git commit time for git contexts, HTTP Last-Modified when present,
and newest archive entry mtime for HTTP archives. Leave local contexts
unset.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Extend SOURCE_DATE_EPOCH resolution to accept a stage name
or named context in addition to numeric and "context" values.
A referenced stage must be FROM scratch with a single remote
ADD (HTTP or Git), from which the epoch timestamp is derived.

Refactor resolution logic from dockerui/context.go into a
dedicated epoch.go file. Remove buildContext fields that were
only needed for epoch resolution and expose GatewayClient()
on dockerui.Client for direct source metadata access.

Also align HTTP named context to use Filename("context"),
matching the existing DetectHTTPContext behavior.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants