Skip to content

Commit 2f27653

Browse files
authored
Merge pull request moby#3485 from AkihiroSuda/docs-timestamps
docs/build-repro.md: add the SOURCE_DATE_EPOCH section
2 parents 1427437 + 984bcf9 commit 2f27653

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

docs/build-repro.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,55 @@ An example `policy.json`:
166166
```
167167

168168
Any source type is supported, but how to pin a source depends on the type.
169+
170+
## `SOURCE_DATE_EPOCH`
171+
[`SOURCE_DATE_EPOCH`](https://reproducible-builds.org/docs/source-date-epoch/) is the convention for pinning timestamps to a specific value.
172+
173+
The Dockerfile frontend supports consuming the `SOURCE_DATE_EPOCH` value as a special build arg, since BuildKit 0.11.
174+
Minimal support is also available on older BuildKit when using Dockerfile 1.5 frontend.
175+
176+
```console
177+
buildctl build --frontend dockerfile.v0 --opt build-arg:SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) ...
178+
```
179+
180+
The `buildctl` CLI does not automatically propagate the `$SOURCE_DATE_EPOCH` environment value from the client host to the `SOURCE_DATE_EPOCH` build arg.
181+
However, higher level build tools, such as Docker Buildx (>= 0.10), may automatically capture the environment value.
182+
183+
The build arg value is used for:
184+
- the `created` timestamp in the [OCI Image Config](https://github.com/opencontainers/image-spec/blob/main/config.md#properties)
185+
- the `created` timestamp in the `history` objects in the [OCI Image Config](https://github.com/opencontainers/image-spec/blob/main/config.md#properties)
186+
- the `org.opencontainers.image.created` annotation in the [OCI Image Index](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys)
187+
- the timestamp of the files exported with the `local` exporter
188+
- the timestamp of the files exported with the `tar` exporter
189+
190+
The build arg value is not used for the timestamps of the files inside the image currently ([Caveats](#caveats)).
191+
192+
See also the [documentation](/frontend/dockerfile/docs/reference.md#buildkit-built-in-build-args) of the Dockerfile frontend.
193+
194+
## Caveats
195+
### Timestamps of the files inside the image
196+
Currently, the `SOURCE_DATE_EPOCH` value is not used for the timestamps of the files inside the image.
197+
198+
Workaround:
199+
```dockerfile
200+
# Limit the timestamp upper bound to SOURCE_DATE_EPOCH.
201+
# Workaround for https://github.com/moby/buildkit/issues/3180
202+
ARG SOURCE_DATE_EPOCH
203+
RUN find $( ls / | grep -E -v "^(dev|mnt|proc|sys)$" ) -newermt "@${SOURCE_DATE_EPOCH}" -writable -xdev | xargs touch --date="@${SOURCE_DATE_EPOCH}" --no-dereference
204+
```
205+
206+
The `touch` command above is [not effective](https://github.com/moby/buildkit/issues/3309) for mount point directories.
207+
A workaround is to create mount point directories below `/dev` (tmpfs) so that the mount points will not be included in the image layer.
208+
209+
### Timestamps of whiteouts
210+
Currently, the `SOURCE_DATE_EPOCH` value is not used for the timestamps of "whiteouts" that are created on removing files.
211+
212+
Workaround:
213+
```dockerfile
214+
# Squash the entire stage for resetting the whiteout timestamps.
215+
# Workaround for https://github.com/moby/buildkit/issues/3168
216+
FROM scratch
217+
COPY --from=0 / /
218+
```
219+
220+
The timestamps of the regular files in the original stage are maintained in the squashed stage, so you do not need to touch the files after this `COPY` instruction.

0 commit comments

Comments
 (0)