Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #122 from tonistiigi/buildkit-18091
Browse files Browse the repository at this point in the history
[18.09 backport] BuildKit fixes for 18.09.1
Upstream-commit: 9606931393cf097ddc2f13f373cf491fd575e29c
Component: engine
  • Loading branch information
andrewhsu authored Nov 26, 2018
2 parents 2aed215 + 71bb7e0 commit aae62fd
Show file tree
Hide file tree
Showing 26 changed files with 228 additions and 181 deletions.
2 changes: 1 addition & 1 deletion components/engine/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6402,7 +6402,7 @@ paths:
type: "string"
description: |
A JSON encoded value of the filters (a `map[string][]string`) to process on the list of build cache objects. Available filters:
- `unused-for=<duration>`: duration relative to daemon's time, during which build cache was not used, in Go's duration format (e.g., '24h')
- `until=<duration>`: duration relative to daemon's time, during which build cache was not used, in Go's duration format (e.g., '24h')
- `id=<id>`
- `parent=<id>`
- `type=<string>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ func (is *imageSource) getResolver(ctx context.Context, rfn resolver.ResolveOpti
func (is *imageSource) getCredentialsFromSession(ctx context.Context) func(string) (string, string, error) {
id := session.FromContext(ctx)
if id == "" {
return nil
// can be removed after containerd/containerd#2812
return func(string) (string, string, error) {
return "", "", nil
}
}
return func(host string) (string, string, error) {
timeoutCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand Down
50 changes: 39 additions & 11 deletions components/engine/builder/builder-next/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package buildkit

import (
"context"
"fmt"
"io"
"net"
"strings"
Expand Down Expand Up @@ -32,7 +33,21 @@ import (
grpcmetadata "google.golang.org/grpc/metadata"
)

var errMultipleFilterValues = errors.New("filters expect only one value")
type errMultipleFilterValues struct{}

func (errMultipleFilterValues) Error() string { return "filters expect only one value" }

func (errMultipleFilterValues) InvalidParameter() {}

type errConflictFilter struct {
a, b string
}

func (e errConflictFilter) Error() string {
return fmt.Sprintf("conflicting filters: %q and %q", e.a, e.b)
}

func (errConflictFilter) InvalidParameter() {}

var cacheFields = map[string]bool{
"id": true,
Expand Down Expand Up @@ -130,6 +145,9 @@ func (b *Builder) Prune(ctx context.Context, opts types.BuildCachePruneOptions)

validFilters := make(map[string]bool, 1+len(cacheFields))
validFilters["unused-for"] = true
validFilters["until"] = true
validFilters["label"] = true // TODO(tiborvass): handle label
validFilters["label!"] = true // TODO(tiborvass): handle label!
for k, v := range cacheFields {
validFilters[k] = v
}
Expand Down Expand Up @@ -504,6 +522,7 @@ func toBuildkitExtraHosts(inp []string) (string, error) {
hosts := make([]string, 0, len(inp))
for _, h := range inp {
parts := strings.Split(h, ":")

if len(parts) != 2 || parts[0] == "" || net.ParseIP(parts[1]) == nil {
return "", errors.Errorf("invalid host %s", h)
}
Expand All @@ -513,21 +532,30 @@ func toBuildkitExtraHosts(inp []string) (string, error) {
}

func toBuildkitPruneInfo(opts types.BuildCachePruneOptions) (client.PruneInfo, error) {
var unusedFor time.Duration
unusedForValues := opts.Filters.Get("unused-for")
var until time.Duration
untilValues := opts.Filters.Get("until") // canonical
unusedForValues := opts.Filters.Get("unused-for") // deprecated synonym for "until" filter

switch len(unusedForValues) {
case 0:
if len(untilValues) > 0 && len(unusedForValues) > 0 {
return client.PruneInfo{}, errConflictFilter{"until", "unused-for"}
}
filterKey := "until"
if len(unusedForValues) > 0 {
filterKey = "unused-for"
}
untilValues = append(untilValues, unusedForValues...)

switch len(untilValues) {
case 0:
// nothing to do
case 1:
var err error
unusedFor, err = time.ParseDuration(unusedForValues[0])
until, err = time.ParseDuration(untilValues[0])
if err != nil {
return client.PruneInfo{}, errors.Wrap(err, "unused-for filter expects a duration (e.g., '24h')")
return client.PruneInfo{}, errors.Wrapf(err, "%q filter expects a duration (e.g., '24h')", filterKey)
}

default:
return client.PruneInfo{}, errMultipleFilterValues
return client.PruneInfo{}, errMultipleFilterValues{}
}

bkFilter := make([]string, 0, opts.Filters.Len())
Expand All @@ -544,13 +572,13 @@ func toBuildkitPruneInfo(opts types.BuildCachePruneOptions) (client.PruneInfo, e
bkFilter = append(bkFilter, cacheField+"=="+values[0])
}
default:
return client.PruneInfo{}, errMultipleFilterValues
return client.PruneInfo{}, errMultipleFilterValues{}
}
}
}
return client.PruneInfo{
All: opts.All,
KeepDuration: unusedFor,
KeepDuration: until,
KeepBytes: opts.KeepStorage,
Filter: []string{strings.Join(bkFilter, ",")},
}, nil
Expand Down
4 changes: 2 additions & 2 deletions components/engine/vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/imdario/mergo v0.3.6
golang.org/x/sync 1d60e4601c6fd243af51cc01ddf169918a5407ca

# buildkit
github.com/moby/buildkit c7bb575343df0cbfeab8b5b28149630b8153fcc6
github.com/tonistiigi/fsutil f567071bed2416e4d87d260d3162722651182317
github.com/moby/buildkit 8cf9bec86a7f11fe6591804aee152c8e8a7a8a0d # v0.3.3
github.com/tonistiigi/fsutil 2862f6bc5ac9b97124e552a5c108230b38a1b0ca
github.com/grpc-ecosystem/grpc-opentracing 8e809c8a86450a29b90dcc9efbf062d0fe6d9746
github.com/opentracing/opentracing-go 1361b9cd60be79c4c3a7fa9841b3c132e40066a7
github.com/google/shlex 6f45313302b9c56850fc17f99e40caebce98c716
Expand Down
28 changes: 24 additions & 4 deletions components/engine/vendor/github.com/moby/buildkit/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aae62fd

Please sign in to comment.