Skip to content

Commit

Permalink
vendor buildkit v0.9.1-0.20211025222436-33fb83eb7166
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Oct 26, 2021
1 parent 9aa0b24 commit 8e2e651
Show file tree
Hide file tree
Showing 806 changed files with 114,111 additions and 39,391 deletions.
36 changes: 18 additions & 18 deletions builder/builder-next/adapters/containerimage/pull.go
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/solver"
"github.com/moby/buildkit/source"
srctypes "github.com/moby/buildkit/source/types"
"github.com/moby/buildkit/util/flightcontrol"
"github.com/moby/buildkit/util/imageutil"
"github.com/moby/buildkit/util/leaseutil"
Expand Down Expand Up @@ -74,7 +75,7 @@ func NewSource(opt SourceOpt) (*Source, error) {

// ID returns image scheme identifier
func (is *Source) ID() string {
return source.DockerImageScheme
return srctypes.DockerImageScheme
}

func (is *Source) resolveLocal(refStr string) (*image.Image, error) {
Expand Down Expand Up @@ -302,51 +303,51 @@ func (p *puller) resolve(ctx context.Context, g session.Group) error {
return err
}

func (p *puller) CacheKey(ctx context.Context, g session.Group, index int) (string, solver.CacheOpts, bool, error) {
func (p *puller) CacheKey(ctx context.Context, g session.Group, index int) (string, string, solver.CacheOpts, bool, error) {
p.resolveLocal()

if p.desc.Digest != "" && index == 0 {
dgst, err := p.mainManifestKey(p.platform)
if err != nil {
return "", nil, false, err
return "", "", nil, false, err
}
return dgst.String(), nil, false, nil
return dgst.String(), dgst.String(), nil, false, nil
}

if p.config != nil {
k := cacheKeyFromConfig(p.config).String()
if k == "" {
return digest.FromBytes(p.config).String(), nil, true, nil
return digest.FromBytes(p.config).String(), digest.FromBytes(p.config).String(), nil, true, nil
}
return k, nil, true, nil
return k, k, nil, true, nil
}

if err := p.resolve(ctx, g); err != nil {
return "", nil, false, err
return "", "", nil, false, err
}

if p.desc.Digest != "" && index == 0 {
dgst, err := p.mainManifestKey(p.platform)
if err != nil {
return "", nil, false, err
return "", "", nil, false, err
}
return dgst.String(), nil, false, nil
return dgst.String(), dgst.String(), nil, false, nil
}

if len(p.config) == 0 && p.desc.MediaType != images.MediaTypeDockerSchema1Manifest {
return "", nil, false, errors.Errorf("invalid empty config file resolved for %s", p.src.Reference.String())
return "", "", nil, false, errors.Errorf("invalid empty config file resolved for %s", p.src.Reference.String())
}

k := cacheKeyFromConfig(p.config).String()
if k == "" || p.desc.MediaType == images.MediaTypeDockerSchema1Manifest {
dgst, err := p.mainManifestKey(p.platform)
if err != nil {
return "", nil, false, err
return "", "", nil, false, err
}
return dgst.String(), nil, true, nil
return dgst.String(), dgst.String(), nil, true, nil
}

return k, nil, true, nil
return k, "", nil, true, nil
}

func (p *puller) getRef(ctx context.Context, diffIDs []layer.DiffID, opts ...cache.RefOption) (cache.ImmutableRef, error) {
Expand Down Expand Up @@ -407,7 +408,7 @@ func (p *puller) Snapshot(ctx context.Context, g session.Group) (cache.Immutable

pctx, stopProgress := context.WithCancel(ctx)

pw, _, ctx := progress.FromContext(ctx)
pw, _, ctx := progress.NewFromContext(ctx)
defer pw.Close()

progressDone := make(chan struct{})
Expand Down Expand Up @@ -587,9 +588,8 @@ func (p *puller) Snapshot(ctx context.Context, g session.Group) (cache.Immutable
}

// TODO: handle windows layers for cross platform builds

if p.src.RecordType != "" && cache.GetRecordType(ref) == "" {
if err := cache.SetRecordType(ref, p.src.RecordType); err != nil {
if p.src.RecordType != "" && ref.GetRecordType() == "" {
if err := ref.SetRecordType(p.src.RecordType); err != nil {
ref.Release(context.TODO())
return nil, err
}
Expand Down Expand Up @@ -808,7 +808,7 @@ type statusInfo struct {
}

func oneOffProgress(ctx context.Context, id string) func(err error) error {
pw, _, _ := progress.FromContext(ctx)
pw, _, _ := progress.NewFromContext(ctx)
now := time.Now()
st := progress.Status{
Started: &now,
Expand Down
Expand Up @@ -75,7 +75,7 @@ func (li *localImporter) Resolve(ctx context.Context, _ specs.Descriptor, id str
if err != nil {
return nil, err
}
return solver.NewCacheManager(id, keysStorage, resultStorage), nil
return solver.NewCacheManager(ctx, id, keysStorage, resultStorage), nil
}

func (li *localImporter) importInlineCache(ctx context.Context, dt []byte, cc solver.CacheExporterTarget) error {
Expand Down
24 changes: 24 additions & 0 deletions builder/builder-next/builder.go
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/docker/docker/libnetwork"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/go-units"
controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/control"
Expand Down Expand Up @@ -319,6 +320,17 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.
}
frontendAttrs["add-hosts"] = extraHosts

if opt.Options.ShmSize > 0 {
frontendAttrs["shm-size"] = strconv.FormatInt(opt.Options.ShmSize, 10)
}

ulimits, err := toBuildkitUlimits(opt.Options.Ulimits)
if err != nil {
return nil, err
} else if len(ulimits) > 0 {
frontendAttrs["ulimit"] = ulimits
}

exporterName := ""
exporterAttrs := map[string]string{}

Expand Down Expand Up @@ -558,6 +570,18 @@ func toBuildkitExtraHosts(inp []string) (string, error) {
return strings.Join(hosts, ","), nil
}

// toBuildkitUlimits converts ulimits from docker type=soft:hard format to buildkit's csv format
func toBuildkitUlimits(inp []*units.Ulimit) (string, error) {
if len(inp) == 0 {
return "", nil
}
ulimits := make([]string, 0, len(inp))
for _, ulimit := range inp {
ulimits = append(ulimits, ulimit.String())
}
return strings.Join(ulimits, ","), nil
}

func toBuildkitPruneInfo(opts types.BuildCachePruneOptions) (client.PruneInfo, error) {
var until time.Duration
untilValues := opts.Filters.Get("until") // canonical
Expand Down
1 change: 0 additions & 1 deletion builder/builder-next/controller.go
Expand Up @@ -184,7 +184,6 @@ func newController(rt http.RoundTripper, opt Opt) (*control.Controller, error) {

wopt := mobyworker.Opt{
ID: "moby",
MetadataStore: md,
ContentStore: store,
CacheManager: cm,
GCPolicy: gcPolicy,
Expand Down
11 changes: 9 additions & 2 deletions builder/builder-next/exporter/export.go
Expand Up @@ -93,9 +93,13 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp exporter.Source,
}

var config []byte
var buildInfo []byte
switch len(inp.Refs) {
case 0:
config = inp.Metadata[exptypes.ExporterImageConfigKey]
if v, ok := inp.Metadata[exptypes.ExporterBuildInfo]; ok {
buildInfo = v
}
case 1:
platformsBytes, ok := inp.Metadata[exptypes.ExporterPlatformsKey]
if !ok {
Expand All @@ -109,13 +113,16 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp exporter.Source,
return nil, errors.Errorf("number of platforms does not match references %d %d", len(p.Platforms), len(inp.Refs))
}
config = inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, p.Platforms[0].ID)]
if v, ok := inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterBuildInfo, p.Platforms[0].ID)]; ok {
buildInfo = v
}
}

var diffs []digest.Digest
if ref != nil {
layersDone := oneOffProgress(ctx, "exporting layers")

if err := ref.Finalize(ctx, true); err != nil {
if err := ref.Finalize(ctx); err != nil {
return nil, layersDone(err)
}

Expand Down Expand Up @@ -147,7 +154,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp exporter.Source,

diffs, history = normalizeLayersAndHistory(diffs, history, ref)

config, err = patchImageConfig(config, diffs, history, inp.Metadata[exptypes.ExporterInlineCache])
config, err = patchImageConfig(config, diffs, history, inp.Metadata[exptypes.ExporterInlineCache], buildInfo)
if err != nil {
return nil, err
}
Expand Down
19 changes: 15 additions & 4 deletions builder/builder-next/exporter/writer.go
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/util/buildinfo"
"github.com/moby/buildkit/util/progress"
"github.com/moby/buildkit/util/system"
digest "github.com/opencontainers/go-digest"
Expand Down Expand Up @@ -41,7 +42,7 @@ func parseHistoryFromConfig(dt []byte) ([]ocispec.History, error) {
return config.History, nil
}

func patchImageConfig(dt []byte, dps []digest.Digest, history []ocispec.History, cache []byte) ([]byte, error) {
func patchImageConfig(dt []byte, dps []digest.Digest, history []ocispec.History, cache []byte, buildInfo []byte) ([]byte, error) {
m := map[string]json.RawMessage{}
if err := json.Unmarshal(dt, &m); err != nil {
return nil, errors.Wrap(err, "failed to parse image config for patch")
Expand Down Expand Up @@ -85,6 +86,16 @@ func patchImageConfig(dt []byte, dps []digest.Digest, history []ocispec.History,
m["moby.buildkit.cache.v0"] = dt
}

if buildInfo != nil {
dt, err := json.Marshal(buildInfo)
if err != nil {
return nil, err
}
m[buildinfo.ImageConfigField] = dt
} else if len(m[buildinfo.ImageConfigField]) > 0 {
delete(m, buildinfo.ImageConfigField)
}

dt, err = json.Marshal(m)
return dt, errors.Wrap(err, "failed to marshal config after patch")
}
Expand Down Expand Up @@ -187,10 +198,10 @@ func getRefMetadata(ref cache.ImmutableRef, limit int) []refMetadata {
if ref == nil {
return append(getRefMetadata(nil, limit-1), meta)
}
if descr := cache.GetDescription(ref.Metadata()); descr != "" {
if descr := ref.GetDescription(); descr != "" {
meta.description = descr
}
meta.createdAt = cache.GetCreatedAt(ref.Metadata())
meta.createdAt = ref.GetCreatedAt()
p := ref.Parent()
if p != nil {
defer p.Release(context.TODO())
Expand All @@ -199,7 +210,7 @@ func getRefMetadata(ref cache.ImmutableRef, limit int) []refMetadata {
}

func oneOffProgress(ctx context.Context, id string) func(err error) error {
pw, _, _ := progress.FromContext(ctx)
pw, _, _ := progress.NewFromContext(ctx)
now := time.Now()
st := progress.Status{
Started: &now,
Expand Down

0 comments on commit 8e2e651

Please sign in to comment.