Skip to content
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

Provide way to initialize SOURCE_DATE_EPOCH with git commit timestamp #3565

Open
tonistiigi opened this issue Feb 1, 2023 · 3 comments
Open

Comments

@tonistiigi
Copy link
Member

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
Copy link
Member

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:

buildkit/control/control.go

Lines 346 to 354 in 915d245

// if SOURCE_DATE_EPOCH is set, enable it for the exporter
if v, ok := epoch.ParseBuildArgs(req.FrontendAttrs); ok {
if _, ok := req.ExporterAttrs[string(exptypes.OptKeySourceDateEpoch)]; !ok {
if req.ExporterAttrs == nil {
req.ExporterAttrs = make(map[string]string)
}
req.ExporterAttrs[string(exptypes.OptKeySourceDateEpoch)] = v
}
}

func DetectGitContext(ref string, keepGit bool) (*llb.State, bool) {
g, err := gitutil.ParseGitRef(ref)
if err != nil {
return nil, false
}
commit := g.Commit
if g.SubDir != "" {
commit += ":" + g.SubDir
}
gitOpts := []llb.GitOption{WithInternalName("load git source " + ref)}
if keepGit {
gitOpts = append(gitOpts, llb.KeepGitDir())
}
st := llb.Git(g.Remote, commit, gitOpts...)
return &st, true
}

@tonistiigi
Copy link
Member Author

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
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants