moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
https://github.com/moby/moby/issues/34227
Apache License 2.0
8.21k stars 1.16k forks source link

Provide way to initialize SOURCE_DATE_EPOCH with git commit timestamp #3565

Open tonistiigi opened 1 year ago

tonistiigi commented 1 year ago

When building from Git URL directly there shouldn't be a need to pass --build-arg SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) manually. There should be a simple opt-in for BuildKit to do that initialization automatically, or maybe it should even be enabled by default(this does change the image creation time to commit time, but maybe that is for the better).

cc @AkihiroSuda

AkihiroSuda commented 1 year ago

I'm not sure how this is implementable.

The controller parses the build arg before it calls the solver to invoke the frontend, which creates LLB git state: https://github.com/moby/buildkit/blob/915d245f67dc0521ef04a09c867c4581713a1e3c/control/control.go#L346-L354 https://github.com/moby/buildkit/blob/915d245f67dc0521ef04a09c867c4581713a1e3c/frontend/dockerui/context.go#L143-L159

tonistiigi commented 1 year ago

The frontend could return the epoch with the result metadata. New code is needed to actually read the timestamp with the commit. In another issue we were discussing making ResolveImageConfig work with all sources so maybe that would be to place to attach timestamp info if a source supports it. Potentially it could be used for other sources as well like images and maybe by reading headers for HTTP sources.

tonistiigi commented 1 year ago

maybe that would be to place to attach timestamp info if a source supports it

Otoh going through LLB would allow avoiding extra progress messages.