Merge pull request #3806 from giggsoff/update-buildkit

Update buildkit to have platform fix
This commit is contained in:
Avi Deitcher 2022-07-22 07:36:07 -04:00 committed by GitHub
commit ea61ff95ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 219 additions and 45 deletions

View File

@ -26,12 +26,11 @@ require (
github.com/gophercloud/gophercloud v0.1.0
github.com/gophercloud/utils v0.0.0-20181029231510-34f5991525d1
github.com/hashicorp/go-version v1.2.0
github.com/moby/buildkit v0.10.1-0.20220617010517-a6a114a1a476
github.com/moby/buildkit v0.10.1-0.20220721175135-c75998aec3d4
github.com/moby/hyperkit v0.0.0-20180416161519-d65b09c1c28a
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
github.com/moby/vpnkit v0.4.1-0.20200311130018-2ffc1dd8a84e
github.com/moul/gotty-client v1.7.1-0.20180526075433-e5589f6df359
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/packethost/packngo v0.1.1-0.20171201154433-f1be085ecd6f

View File

@ -1064,10 +1064,8 @@ github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
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.10.1-0.20220403220257-10e6f94bf90d/go.mod h1:WvwAZv8aRScHkqc/+X46cRC2CKMKpqcaX+pRvUTtPes=
github.com/moby/buildkit v0.10.1-0.20220614084718-b3d272e22672 h1:cDyvSdAMu2BSuEaodU0d9Jm7ki/wWibm/s8G/xRurYA=
github.com/moby/buildkit v0.10.1-0.20220614084718-b3d272e22672/go.mod h1:yle9eiU1fiJ/WhC4VTLOaQ6rxFou1mc4AhwScHwysi0=
github.com/moby/buildkit v0.10.1-0.20220617010517-a6a114a1a476 h1:quXwiNE0nC/0bHFJkQKcwetpk1jNHIwwzDpq9hVmxSM=
github.com/moby/buildkit v0.10.1-0.20220617010517-a6a114a1a476/go.mod h1:yle9eiU1fiJ/WhC4VTLOaQ6rxFou1mc4AhwScHwysi0=
github.com/moby/buildkit v0.10.1-0.20220721175135-c75998aec3d4 h1:+AwP6ma57EBQ5+eOSsg29MAylks33kt2MverACSqJv0=
github.com/moby/buildkit v0.10.1-0.20220721175135-c75998aec3d4/go.mod h1:yle9eiU1fiJ/WhC4VTLOaQ6rxFou1mc4AhwScHwysi0=
github.com/moby/hyperkit v0.0.0-20180416161519-d65b09c1c28a h1:hExo7kltIidoitYnXsnqfvkJXG3YEMbHuQbf9nOMvow=
github.com/moby/hyperkit v0.0.0-20180416161519-d65b09c1c28a/go.mod h1:zGAVB/FkAf4ozkR8CCuj4LcVuErrNsj9APTDFvhOckw=
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=

View File

@ -13,9 +13,9 @@ import (
const (
buildersEnvVar = "LINUXKIT_BUILDERS"
// this is the most recent manifest pointed to by moby/buildkit:master as of 2022-07-13, so it includes
// this is the most recent manifest pointed to by moby/buildkit:master as of 2022-07-22, so it includes
// our required commit. Once there is a normal semver tag later than this, we should switch to it.
defaultBuilderImage = "moby/buildkit@sha256:e7b24395dff0280513cb795fe6dbd77d8f22e49ef9401eedc311c08b2b7fdd0b"
defaultBuilderImage = "moby/buildkit@sha256:19c4637f8809f21af01dedf65f7f0d64636165d8191381ec9d5150fccedbae48"
)
func pkgBuild(args []string) {

View File

@ -609,7 +609,7 @@ func Chown(uid, gid int) HTTPOption {
}
func platformSpecificSource(id string) bool {
return strings.HasPrefix(id, "docker-image://")
return strings.HasPrefix(id, "docker-image://") || strings.HasPrefix(id, "oci-layout://")
}
func addCap(c *Constraints, id apicaps.CapID) {

View File

@ -61,7 +61,7 @@ const (
keyUlimit = "ulimit"
// Don't forget to update frontend documentation if you add
// a new build-arg: frontend/dockerfile/docs/syntax.md
// a new build-arg: frontend/dockerfile/docs/reference.md
keyCacheNSArg = "build-arg:BUILDKIT_CACHE_MOUNT_NS"
keyContextKeepGitDirArg = "build-arg:BUILDKIT_CONTEXT_KEEP_GIT_DIR"
keyHostnameArg = "build-arg:BUILDKIT_SANDBOX_HOSTNAME"
@ -861,6 +861,7 @@ func contextByName(ctx context.Context, c client.Client, sessionID, name string,
if err := json.Unmarshal(data, &img); err != nil {
return nil, nil, nil, err
}
img.Created = nil
st := llb.Image(ref, imgOpt...)
st, err = st.WithImageConfig(data)

View File

@ -13,6 +13,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"github.com/containerd/containerd/platforms"
"github.com/docker/distribution/reference"
@ -72,6 +73,7 @@ type ConvertOpt struct {
func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, *Image, *binfotypes.BuildInfo, error) {
buildInfo := &binfotypes.BuildInfo{}
buildInfoDepsMu := sync.Mutex{}
contextByName := opt.ContextByName
opt.ContextByName = func(ctx context.Context, name, resolveMode string) (*llb.State, *Image, *binfotypes.BuildInfo, error) {
if !strings.EqualFold(name, "scratch") && !strings.EqualFold(name, "context") {
@ -81,12 +83,14 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
return nil, nil, nil, err
}
if bi != nil && bi.Deps != nil {
for k := range bi.Deps {
buildInfoDepsMu.Lock()
if buildInfo.Deps == nil {
buildInfo.Deps = make(map[string]binfotypes.BuildInfo)
}
for k := range bi.Deps {
buildInfo.Deps[k] = bi.Deps[k]
}
buildInfoDepsMu.Unlock()
}
return st, img, bi, nil
}

View File

@ -3,11 +3,25 @@ package errdefs
import (
"context"
"errors"
"strings"
"github.com/moby/buildkit/util/grpcerrors"
"google.golang.org/grpc/codes"
)
func IsCanceled(err error) bool {
return errors.Is(err, context.Canceled) || grpcerrors.Code(err) == codes.Canceled
func IsCanceled(ctx context.Context, err error) bool {
if errors.Is(err, context.Canceled) || grpcerrors.Code(err) == codes.Canceled {
return true
}
// grpc does not set cancel correctly when stream gets cancelled and then Recv is called
if err != nil && ctx.Err() == context.Canceled {
// when this error comes from containerd it is not typed at all, just concatenated string
if strings.Contains(err.Error(), "EOF") {
return true
}
if strings.Contains(err.Error(), context.Canceled.Error()) {
return true
}
}
return false
}

View File

@ -0,0 +1,135 @@
package progressui
import (
"encoding/csv"
"errors"
"strconv"
"strings"
"github.com/morikuni/aec"
"github.com/sirupsen/logrus"
)
var termColorMap = map[string]aec.ANSI{
"default": aec.DefaultF,
"black": aec.BlackF,
"blue": aec.BlueF,
"cyan": aec.CyanF,
"green": aec.GreenF,
"magenta": aec.MagentaF,
"red": aec.RedF,
"white": aec.WhiteF,
"yellow": aec.YellowF,
"light-black": aec.LightBlackF,
"light-blue": aec.LightBlueF,
"light-cyan": aec.LightCyanF,
"light-green": aec.LightGreenF,
"light-magenta": aec.LightMagentaF,
"light-red": aec.LightRedF,
"light-white": aec.LightWhiteF,
"light-yellow": aec.LightYellowF,
}
func setUserDefinedTermColors(colorsEnv string) {
fields := readBuildkitColorsEnv(colorsEnv)
if fields == nil {
return
}
for _, field := range fields {
parts := strings.SplitN(field, "=", 2)
if len(parts) != 2 || strings.Contains(parts[1], "=") {
err := errors.New("A valid entry must have exactly two fields")
logrus.WithError(err).Warnf("Could not parse BUILDKIT_COLORS component: %s", field)
continue
}
k := strings.ToLower(parts[0])
v := parts[1]
if c, ok := termColorMap[strings.ToLower(v)]; ok {
parseKeys(k, c)
} else if strings.Contains(v, ",") {
if c := readRGB(v); c != nil {
parseKeys(k, c)
}
} else {
err := errors.New("Colors must be a name from the pre-defined list or a valid 3-part RGB value")
logrus.WithError(err).Warnf("Unknown color value found in BUILDKIT_COLORS: %s=%s", k, v)
}
}
}
func readBuildkitColorsEnv(colorsEnv string) []string {
csvReader := csv.NewReader(strings.NewReader(colorsEnv))
csvReader.Comma = ':'
fields, err := csvReader.Read()
if err != nil {
logrus.WithError(err).Warnf("Could not parse BUILDKIT_COLORS. Falling back to defaults.")
return nil
}
return fields
}
func readRGB(v string) aec.ANSI {
csvReader := csv.NewReader(strings.NewReader(v))
fields, err := csvReader.Read()
if err != nil {
logrus.WithError(err).Warnf("Could not parse value %s as valid comma-separated RGB color. Ignoring.", v)
return nil
}
if len(fields) != 3 {
err = errors.New("A valid RGB color must have three fields")
logrus.WithError(err).Warnf("Could not parse value %s as valid RGB color. Ignoring.", v)
return nil
}
ok := isValidRGB(fields)
if ok {
p1, _ := strconv.Atoi(fields[0])
p2, _ := strconv.Atoi(fields[1])
p3, _ := strconv.Atoi(fields[2])
c := aec.Color8BitF(aec.NewRGB8Bit(uint8(p1), uint8(p2), uint8(p3)))
return c
}
return nil
}
func parseKeys(k string, c aec.ANSI) {
key := strings.ToLower(k)
switch key {
case "run":
colorRun = c
case "cancel":
colorCancel = c
case "error":
colorError = c
case "warning":
colorWarning = c
default:
logrus.Warnf("Unknown key found in BUILDKIT_COLORS (expected: run, cancel, error, or warning): %s", k)
}
}
func isValidRGB(s []string) bool {
for _, n := range s {
num, err := strconv.Atoi(n)
if err != nil {
logrus.Warnf("A field in BUILDKIT_COLORS appears to contain an RGB value that is not an integer: %s", strings.Join(s, ","))
return false
}
ok := isValidRGBValue(num)
if ok {
continue
} else {
logrus.Warnf("A field in BUILDKIT_COLORS appears to contain an RGB value that is not within the valid range of 0-255: %s", strings.Join(s, ","))
return false
}
}
return true
}
func isValidRGBValue(i int) bool {
if (i >= 0) && (i <= 255) {
return true
}
return false
}

View File

@ -108,6 +108,7 @@ type job struct {
name string
status string
hasError bool
hasWarning bool // This is currently unused, but it's here for future use.
isCanceled bool
vertex *vertex
showTerm bool
@ -829,9 +830,14 @@ func (disp *display) print(d displayInfo, width, height int, all bool) {
color = colorCancel
} else if j.hasError {
color = colorError
} else if j.hasWarning {
// This is currently unused, but it's here for future use.
color = colorWarning
}
if color != nil {
out = aec.Apply(out, color)
}
}
fmt.Fprint(disp.c, out)
lineCount++
if j.showTerm {

View File

@ -0,0 +1,37 @@
package progressui
import (
"os"
"runtime"
"github.com/morikuni/aec"
)
var colorRun aec.ANSI
var colorCancel aec.ANSI
var colorWarning aec.ANSI
var colorError aec.ANSI
func init() {
// As recommended on https://no-color.org/
if _, ok := os.LookupEnv("NO_COLOR"); ok {
// nil values will result in no ANSI color codes being emitted.
return
} else if runtime.GOOS == "windows" {
colorRun = termColorMap["cyan"]
colorCancel = termColorMap["yellow"]
colorWarning = termColorMap["yellow"]
colorError = termColorMap["red"]
} else {
colorRun = termColorMap["blue"]
colorCancel = termColorMap["yellow"]
colorWarning = termColorMap["yellow"]
colorError = termColorMap["red"]
}
// Loosely based on the standard set by Linux LS_COLORS.
if _, ok := os.LookupEnv("BUILDKIT_COLORS"); ok {
envColorString := os.Getenv("BUILDKIT_COLORS")
setUserDefinedTermColors(envColorString)
}
}

View File

@ -1,12 +0,0 @@
//go:build !windows
// +build !windows
package progressui
import "github.com/morikuni/aec"
var (
colorRun = aec.BlueF
colorCancel = aec.YellowF
colorError = aec.RedF
)

View File

@ -1,12 +0,0 @@
//go:build windows
// +build windows
package progressui
import "github.com/morikuni/aec"
var (
colorRun = aec.CyanF
colorCancel = aec.YellowF
colorError = aec.RedF
)

View File

@ -335,7 +335,7 @@ github.com/linuxkit/virtsock/pkg/vsock
github.com/matttproud/golang_protobuf_extensions/pbutil
# github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b
github.com/mitchellh/go-ps
# github.com/moby/buildkit v0.10.1-0.20220617010517-a6a114a1a476
# github.com/moby/buildkit v0.10.1-0.20220721175135-c75998aec3d4
## explicit
github.com/moby/buildkit/api/services/control
github.com/moby/buildkit/api/types
@ -414,7 +414,6 @@ github.com/morikuni/aec
## explicit
github.com/moul/gotty-client
# github.com/opencontainers/go-digest v1.0.0
## explicit
github.com/opencontainers/go-digest
# github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799
## explicit

View File

@ -1,3 +1,4 @@
FROM alpine:3.15
COPY foo /foo
RUN uname -m >/uname_m && uname -s >/uname_s

View File

@ -1,5 +1,9 @@
# this FROM *must* be updated when changing ../build1; just run `lkt pkg show-tag ../build1` and place it here
FROM linuxkit/chained-build-image1-test-does-not-exist-anywhere-else-123456789:ad06eb29c48f0daab0cc2836a1351a053948100c as src
FROM linuxkit/chained-build-image1-test-does-not-exist-anywhere-else-123456789:e247132d6bc3a56bdce0fcb2d0d4848a1dfcf3b6 as src
FROM alpine:3.15
COPY --from=src /foo /foo
RUN cat /foo
# copy output of uname commands from first build and compare with current
COPY --from=src /uname* /
RUN uname -m >/uname_m_current && uname -s >/uname_s_current && cat /uname_m_current && cat /uname_s_current
RUN diff /uname_m /uname_m_current && diff /uname_s /uname_s_current