mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 17:27:49 +08:00
Merge pull request #1569 from tonistiigi/v0.10.2-picks
[v0.10] cherry-picks for v0.10.2
This commit is contained in:
commit
00ed17df6d
@ -144,6 +144,9 @@ func ReadTargets(ctx context.Context, files []File, targets, overrides []string,
|
|||||||
// The logic is purposely duplicated from `build/build`.go for keeping this visible in `bake --print`.
|
// The logic is purposely duplicated from `build/build`.go for keeping this visible in `bake --print`.
|
||||||
if v := os.Getenv("SOURCE_DATE_EPOCH"); v != "" {
|
if v := os.Getenv("SOURCE_DATE_EPOCH"); v != "" {
|
||||||
for _, f := range m {
|
for _, f := range m {
|
||||||
|
if f.Args == nil {
|
||||||
|
f.Args = make(map[string]*string)
|
||||||
|
}
|
||||||
if _, ok := f.Args["SOURCE_DATE_EPOCH"]; !ok {
|
if _, ok := f.Args["SOURCE_DATE_EPOCH"]; !ok {
|
||||||
f.Args["SOURCE_DATE_EPOCH"] = &v
|
f.Args["SOURCE_DATE_EPOCH"] = &v
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
_ "crypto/sha256" // ensure digests can be computed
|
_ "crypto/sha256" // ensure digests can be computed
|
||||||
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -1157,7 +1158,24 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
descs := make([]specs.Descriptor, 0, len(res))
|
descs := make([]specs.Descriptor, 0, len(res))
|
||||||
|
|
||||||
for _, r := range res {
|
for _, r := range res {
|
||||||
s, ok := r.ExporterResponse[exptypes.ExporterImageDigestKey]
|
s, ok := r.ExporterResponse[exptypes.ExporterImageDescriptorKey]
|
||||||
|
if ok {
|
||||||
|
dt, err := base64.StdEncoding.DecodeString(s)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var desc specs.Descriptor
|
||||||
|
if err := json.Unmarshal(dt, &desc); err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to unmarshal descriptor %s", s)
|
||||||
|
}
|
||||||
|
descs = append(descs, desc)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// This is fallback for some very old buildkit versions.
|
||||||
|
// Note that the mediatype isn't really correct as most of the time it is image manifest and
|
||||||
|
// not manifest list but actually both are handled because for Docker mediatypes the
|
||||||
|
// mediatype value in the Accpet header does not seem to matter.
|
||||||
|
s, ok = r.ExporterResponse[exptypes.ExporterImageDigestKey]
|
||||||
if ok {
|
if ok {
|
||||||
descs = append(descs, specs.Descriptor{
|
descs = append(descs, specs.Descriptor{
|
||||||
Digest: digest.Digest(s),
|
Digest: digest.Digest(s),
|
||||||
|
12
build/git.go
12
build/git.go
@ -52,20 +52,20 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
|
|||||||
gitc, err := gitutil.New(gitutil.WithContext(ctx), gitutil.WithWorkingDir(wd))
|
gitc, err := gitutil.New(gitutil.WithContext(ctx), gitutil.WithWorkingDir(wd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() {
|
if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() {
|
||||||
return res, errors.New("git was not found in the system. Current commit information was not captured by the build")
|
return res, errors.New("buildx: git was not found in the system. Current commit information was not captured by the build")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !gitc.IsInsideWorkTree() {
|
if !gitc.IsInsideWorkTree() {
|
||||||
if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() {
|
if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() {
|
||||||
return res, errors.New("failed to read current commit information with git rev-parse --is-inside-work-tree")
|
return res, errors.New("buildx: failed to read current commit information with git rev-parse --is-inside-work-tree")
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if sha, err := gitc.FullCommit(); err != nil {
|
if sha, err := gitc.FullCommit(); err != nil {
|
||||||
return res, errors.Wrapf(err, "failed to get git commit")
|
return res, errors.Wrapf(err, "buildx: failed to get git commit")
|
||||||
} else if sha != "" {
|
} else if sha != "" {
|
||||||
if gitc.IsDirty() {
|
if gitc.IsDirty() {
|
||||||
sha += "-dirty"
|
sha += "-dirty"
|
||||||
@ -78,9 +78,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if rurl, err := gitc.RemoteURL(); err != nil {
|
if rurl, err := gitc.RemoteURL(); err == nil && rurl != "" {
|
||||||
return res, errors.Wrapf(err, "failed to get git remote url")
|
|
||||||
} else if rurl != "" {
|
|
||||||
if setGitLabels {
|
if setGitLabels {
|
||||||
res["label:"+specs.AnnotationSource] = rurl
|
res["label:"+specs.AnnotationSource] = rurl
|
||||||
}
|
}
|
||||||
@ -91,7 +89,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
|
|||||||
|
|
||||||
if setGitLabels {
|
if setGitLabels {
|
||||||
if root, err := gitc.RootDir(); err != nil {
|
if root, err := gitc.RootDir(); err != nil {
|
||||||
return res, errors.Wrapf(err, "failed to get git root dir")
|
return res, errors.Wrapf(err, "buildx: failed to get git root dir")
|
||||||
} else if root != "" {
|
} else if root != "" {
|
||||||
if dockerfilePath == "" {
|
if dockerfilePath == "" {
|
||||||
dockerfilePath = filepath.Join(wd, "Dockerfile")
|
dockerfilePath = filepath.Join(wd, "Dockerfile")
|
||||||
|
@ -62,6 +62,7 @@ func (b *Builder) LoadNodes(ctx context.Context, withData bool) (_ []Node, err e
|
|||||||
node := Node{
|
node := Node{
|
||||||
Node: n,
|
Node: n,
|
||||||
ProxyConfig: storeutil.GetProxyConfig(b.opts.dockerCli),
|
ProxyConfig: storeutil.GetProxyConfig(b.opts.dockerCli),
|
||||||
|
Platforms: n.Platforms,
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
b.nodes[i] = node
|
b.nodes[i] = node
|
||||||
|
Loading…
x
Reference in New Issue
Block a user