From b5ea79e27777ac8429de07e778c651649c4e0aaa Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 27 Jan 2023 19:38:54 +0100 Subject: [PATCH 1/5] build: fix preferred platform not taken account Signed-off-by: CrazyMax (cherry picked from commit 49b3c0dba5143966f997f2ecd29bc7adc3d95d1a) --- builder/node.go | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/node.go b/builder/node.go index f565738d..459dd282 100644 --- a/builder/node.go +++ b/builder/node.go @@ -62,6 +62,7 @@ func (b *Builder) LoadNodes(ctx context.Context, withData bool) (_ []Node, err e node := Node{ Node: n, ProxyConfig: storeutil.GetProxyConfig(b.opts.dockerCli), + Platforms: n.Platforms, } defer func() { b.nodes[i] = node From 5a4f80f3ced707762ad3ca62cc11e6a36d0e84e6 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Sun, 29 Jan 2023 08:42:47 +0900 Subject: [PATCH 2/5] bake: SOURCE_DATE_EPOCH: fix `panic: assignment to entry in nil map` Fix issue 1562 Signed-off-by: Akihiro Suda (cherry picked from commit 1f56f5174027a91c7c58e1751870abd141b68908) --- bake/bake.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bake/bake.go b/bake/bake.go index 3494b1e1..ab680ad9 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -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`. if v := os.Getenv("SOURCE_DATE_EPOCH"); v != "" { for _, f := range m { + if f.Args == nil { + f.Args = make(map[string]*string) + } if _, ok := f.Args["SOURCE_DATE_EPOCH"]; !ok { f.Args["SOURCE_DATE_EPOCH"] = &v } From 7776652a4d25deac97e62372ec191580f4e3e692 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Sun, 29 Jan 2023 22:45:45 -0800 Subject: [PATCH 3/5] build: fix multi-node merge to read descriptor from result Signed-off-by: Tonis Tiigi (cherry picked from commit c33b310b48a6b0467f25f89aa941ec4e453460d4) --- build/build.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/build/build.go b/build/build.go index 876245e0..67acb8d1 100644 --- a/build/build.go +++ b/build/build.go @@ -6,6 +6,7 @@ import ( "context" "crypto/rand" _ "crypto/sha256" // ensure digests can be computed + "encoding/base64" "encoding/hex" "encoding/json" "fmt" @@ -1157,7 +1158,24 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s descs := make([]specs.Descriptor, 0, len(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 { descs = append(descs, specs.Descriptor{ Digest: digest.Digest(s), From f62342768bafa97e5b693feaf4ee2a67d6e83a66 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 30 Jan 2023 14:33:16 +0100 Subject: [PATCH 4/5] build: silently fail if git remote not found Signed-off-by: CrazyMax (cherry picked from commit 4789d2219c43f28f98f2ead0d44bb3be40d87e32) --- build/git.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build/git.go b/build/git.go index 93325269..60b52936 100644 --- a/build/git.go +++ b/build/git.go @@ -78,9 +78,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st } } - if rurl, err := gitc.RemoteURL(); err != nil { - return res, errors.Wrapf(err, "failed to get git remote url") - } else if rurl != "" { + if rurl, err := gitc.RemoteURL(); err == nil && rurl != "" { if setGitLabels { res["label:"+specs.AnnotationSource] = rurl } From cfb71fab977cfd9f2da5925191ee37db834c0528 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 30 Jan 2023 14:54:07 +0100 Subject: [PATCH 5/5] build: better message output for git provenance Signed-off-by: CrazyMax (cherry picked from commit 6db696748b7141d44c6bbacb91e42b2cd6513431) --- build/git.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/git.go b/build/git.go index 60b52936..47f3fc1c 100644 --- a/build/git.go +++ b/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)) if err != nil { 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 } if !gitc.IsInsideWorkTree() { 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 } 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 != "" { if gitc.IsDirty() { sha += "-dirty" @@ -89,7 +89,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st if setGitLabels { 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 != "" { if dockerfilePath == "" { dockerfilePath = filepath.Join(wd, "Dockerfile")