diff --git a/commands/build.go b/commands/build.go index fdfc1b39..2861820c 100644 --- a/commands/build.go +++ b/commands/build.go @@ -27,11 +27,13 @@ import ( "github.com/moby/buildkit/session/auth/authprovider" "github.com/moby/buildkit/solver/errdefs" "github.com/moby/buildkit/util/appcontext" + "github.com/moby/buildkit/util/grpcerrors" "github.com/morikuni/aec" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" + "google.golang.org/grpc/codes" ) const defaultTargetName = "default" @@ -217,6 +219,7 @@ func runBuild(dockerCli command.Cli, in buildOptions) (err error) { } imageID, err := buildTargets(ctx, dockerCli, map[string]build.Options{defaultTargetName: opts}, in.progress, contextPathHash, in.builder, in.metadataFile) + err = wrapBuildError(err) if err != nil { return err } @@ -492,3 +495,29 @@ func parseContextNames(values []string) (map[string]string, error) { } return result, nil } + +func wrapBuildError(err error) error { + if err == nil { + return nil + } + st, ok := grpcerrors.AsGRPCStatus(err) + if ok { + if st.Code() == codes.Unimplemented && strings.Contains(st.Message(), "unsupported frontend capability moby.buildkit.frontend.contexts") { + return &wrapped{err, "current frontend does not support --build-context. Named contexts are supported since Dockerfile v1.4"} + } + } + return err +} + +type wrapped struct { + err error + msg string +} + +func (w *wrapped) Error() string { + return w.msg +} + +func (w *wrapped) Unwrap() error { + return w.err +} diff --git a/go.mod b/go.mod index c2699bfd..611f3acf 100644 --- a/go.mod +++ b/go.mod @@ -47,6 +47,7 @@ require ( go.opentelemetry.io/otel v1.2.0 go.opentelemetry.io/otel/trace v1.2.0 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c + google.golang.org/grpc v1.42.0 gopkg.in/dancannon/gorethink.v3 v3.0.5 // indirect gopkg.in/fatih/pool.v2 v2.0.0 // indirect gopkg.in/gorethink/gorethink.v3 v3.0.5 // indirect diff --git a/vendor/modules.txt b/vendor/modules.txt index 360b2221..7d0ca6ef 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -564,6 +564,7 @@ google.golang.org/genproto/googleapis/rpc/errdetails google.golang.org/genproto/googleapis/rpc/status google.golang.org/genproto/protobuf/field_mask # google.golang.org/grpc v1.42.0 +## explicit google.golang.org/grpc google.golang.org/grpc/attributes google.golang.org/grpc/backoff