mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 10:03:42 +08:00 
			
		
		
		
	Merge pull request #996 from crazy-max/buildinfo-use-helper
imagetools inspect: use buildinfo helper
This commit is contained in:
		
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							@@ -30,7 +30,7 @@ require (
 | 
				
			|||||||
	github.com/jinzhu/gorm v1.9.2 // indirect
 | 
						github.com/jinzhu/gorm v1.9.2 // indirect
 | 
				
			||||||
	github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a // indirect
 | 
						github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a // indirect
 | 
				
			||||||
	github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
 | 
						github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
 | 
				
			||||||
	github.com/moby/buildkit v0.10.0-rc2.0.20220308185020-fdecd0ae108b
 | 
						github.com/moby/buildkit v0.10.0
 | 
				
			||||||
	github.com/morikuni/aec v1.0.0
 | 
						github.com/morikuni/aec v1.0.0
 | 
				
			||||||
	github.com/opencontainers/go-digest v1.0.0
 | 
						github.com/opencontainers/go-digest v1.0.0
 | 
				
			||||||
	github.com/opencontainers/image-spec v1.0.2-0.20211117181255-693428a734f5
 | 
						github.com/opencontainers/image-spec v1.0.2-0.20211117181255-693428a734f5
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								go.sum
									
									
									
									
									
								
							@@ -970,8 +970,8 @@ github.com/mitchellh/mapstructure v1.4.2 h1:6h7AQ0yhTcIsmFmnAwQls75jp2Gzs4iB8W7p
 | 
				
			|||||||
github.com/mitchellh/mapstructure v1.4.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
 | 
					github.com/mitchellh/mapstructure v1.4.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
 | 
				
			||||||
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
 | 
					github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
 | 
				
			||||||
github.com/moby/buildkit v0.8.1/go.mod h1:/kyU1hKy/aYCuP39GZA9MaKioovHku57N6cqlKZIaiQ=
 | 
					github.com/moby/buildkit v0.8.1/go.mod h1:/kyU1hKy/aYCuP39GZA9MaKioovHku57N6cqlKZIaiQ=
 | 
				
			||||||
github.com/moby/buildkit v0.10.0-rc2.0.20220308185020-fdecd0ae108b h1:plbnJxjht8Z6D3c/ga79D1+VaA/IUfNVp08J3lcDgI8=
 | 
					github.com/moby/buildkit v0.10.0 h1:ElHQJJdnj/VR/pfNJwhrjQJj8GXFIwVNGZh/Qbd5tVo=
 | 
				
			||||||
github.com/moby/buildkit v0.10.0-rc2.0.20220308185020-fdecd0ae108b/go.mod h1:WvwAZv8aRScHkqc/+X46cRC2CKMKpqcaX+pRvUTtPes=
 | 
					github.com/moby/buildkit v0.10.0/go.mod h1:WvwAZv8aRScHkqc/+X46cRC2CKMKpqcaX+pRvUTtPes=
 | 
				
			||||||
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
 | 
					github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
 | 
				
			||||||
github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc=
 | 
					github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc=
 | 
				
			||||||
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
 | 
					github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,6 @@ package imagetools
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"encoding/base64"
 | 
					 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
@@ -16,9 +15,9 @@ import (
 | 
				
			|||||||
	"github.com/containerd/containerd/platforms"
 | 
						"github.com/containerd/containerd/platforms"
 | 
				
			||||||
	"github.com/docker/distribution/reference"
 | 
						"github.com/docker/distribution/reference"
 | 
				
			||||||
	binfotypes "github.com/moby/buildkit/util/buildinfo/types"
 | 
						binfotypes "github.com/moby/buildkit/util/buildinfo/types"
 | 
				
			||||||
 | 
						"github.com/moby/buildkit/util/imageutil"
 | 
				
			||||||
	"github.com/opencontainers/go-digest"
 | 
						"github.com/opencontainers/go-digest"
 | 
				
			||||||
	ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
 | 
						ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
 | 
				
			||||||
	"github.com/pkg/errors"
 | 
					 | 
				
			||||||
	"golang.org/x/sync/errgroup"
 | 
						"golang.org/x/sync/errgroup"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -123,7 +122,7 @@ func (p *Printer) Print(raw bool, out io.Writer) error {
 | 
				
			|||||||
				} else if img != nil {
 | 
									} else if img != nil {
 | 
				
			||||||
					imageconfigs[platforms.Format(platform)] = img
 | 
										imageconfigs[platforms.Format(platform)] = img
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if bi, err := p.getBuildInfo(dtic); err != nil {
 | 
									if bi, err := imageutil.BuildInfo(dtic); err != nil {
 | 
				
			||||||
					return err
 | 
										return err
 | 
				
			||||||
				} else if bi != nil {
 | 
									} else if bi != nil {
 | 
				
			||||||
					buildinfos[platforms.Format(platform)] = bi
 | 
										buildinfos[platforms.Format(platform)] = bi
 | 
				
			||||||
@@ -335,23 +334,3 @@ func (p *Printer) getImageConfig(platform *ocispecs.Platform) (*ocispecs.Image,
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return img, dtic, nil
 | 
						return img, dtic, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *Printer) getBuildInfo(dtic []byte) (*binfotypes.BuildInfo, error) {
 | 
					 | 
				
			||||||
	var binfo *binfotypes.BuildInfo
 | 
					 | 
				
			||||||
	if len(dtic) > 0 {
 | 
					 | 
				
			||||||
		var biconfig binfotypes.ImageConfig
 | 
					 | 
				
			||||||
		if err := json.Unmarshal(dtic, &biconfig); err != nil {
 | 
					 | 
				
			||||||
			return nil, errors.Wrap(err, "failed to unmarshal image config")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if len(biconfig.BuildInfo) > 0 {
 | 
					 | 
				
			||||||
			dtbi, err := base64.StdEncoding.DecodeString(biconfig.BuildInfo)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return nil, errors.Wrap(err, "failed to decode build info")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if err = json.Unmarshal(dtbi, &binfo); err != nil {
 | 
					 | 
				
			||||||
				return nil, errors.Wrap(err, "failed to unmarshal build info")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return binfo, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										32
									
								
								vendor/github.com/moby/buildkit/util/imageutil/buildinfo.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								vendor/github.com/moby/buildkit/util/imageutil/buildinfo.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
				
			|||||||
 | 
					package imageutil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/base64"
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						binfotypes "github.com/moby/buildkit/util/buildinfo/types"
 | 
				
			||||||
 | 
						"github.com/pkg/errors"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// BuildInfo returns build info from image config.
 | 
				
			||||||
 | 
					func BuildInfo(dt []byte) (*binfotypes.BuildInfo, error) {
 | 
				
			||||||
 | 
						if len(dt) == 0 {
 | 
				
			||||||
 | 
							return nil, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var config binfotypes.ImageConfig
 | 
				
			||||||
 | 
						if err := json.Unmarshal(dt, &config); err != nil {
 | 
				
			||||||
 | 
							return nil, errors.Wrap(err, "failed to unmarshal image config")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(config.BuildInfo) == 0 {
 | 
				
			||||||
 | 
							return nil, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						dtbi, err := base64.StdEncoding.DecodeString(config.BuildInfo)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var bi binfotypes.BuildInfo
 | 
				
			||||||
 | 
						if err = json.Unmarshal(dtbi, &bi); err != nil {
 | 
				
			||||||
 | 
							return nil, errors.Wrap(err, "failed to decode buildinfo from image config")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return &bi, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										2
									
								
								vendor/modules.txt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/modules.txt
									
									
									
									
										vendored
									
									
								
							@@ -294,7 +294,7 @@ github.com/miekg/pkcs11
 | 
				
			|||||||
github.com/mitchellh/go-wordwrap
 | 
					github.com/mitchellh/go-wordwrap
 | 
				
			||||||
# github.com/mitchellh/mapstructure v1.4.2
 | 
					# github.com/mitchellh/mapstructure v1.4.2
 | 
				
			||||||
github.com/mitchellh/mapstructure
 | 
					github.com/mitchellh/mapstructure
 | 
				
			||||||
# github.com/moby/buildkit v0.10.0-rc2.0.20220308185020-fdecd0ae108b
 | 
					# github.com/moby/buildkit v0.10.0
 | 
				
			||||||
## explicit
 | 
					## explicit
 | 
				
			||||||
github.com/moby/buildkit/api/services/control
 | 
					github.com/moby/buildkit/api/services/control
 | 
				
			||||||
github.com/moby/buildkit/api/types
 | 
					github.com/moby/buildkit/api/types
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user