dockerfile: support SOURCE_DATE_EPOCH=context

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>
This commit is contained in:
Tonis Tiigi
2026-03-23 17:08:41 -07:00
parent a243ce438a
commit 4e1c8acd57
11 changed files with 526 additions and 44 deletions

View File

@@ -51,6 +51,13 @@ ARG SOURCE_DATE_EPOCH=1704067200
FROM alpine
```
The Dockerfile frontend also supports the special value `SOURCE_DATE_EPOCH=context`.
This resolves the main build context to a numeric Unix timestamp before the build:
- 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
```console
buildctl build --frontend dockerfile.v0 --opt build-arg:SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) ...
```