From b5bf28d7225a30c889d387bbe5a926b7c9e9bf41 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 22 Feb 2022 21:55:44 -0800 Subject: [PATCH] bake: use better error in named contexts not supported Signed-off-by: Tonis Tiigi --- commands/bake.go | 2 +- commands/build.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/commands/bake.go b/commands/bake.go index 94a125e9..74d09113 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -147,7 +147,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions) (err error resp, err := build.Build(ctx, dis, bo, dockerAPI(dockerCli), confutil.ConfigDir(dockerCli), printer) if err != nil { - return err + return wrapBuildError(err, true) } if len(in.metadataFile) > 0 && resp != nil { diff --git a/commands/build.go b/commands/build.go index 2b00c2c7..021dda62 100644 --- a/commands/build.go +++ b/commands/build.go @@ -226,7 +226,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) + err = wrapBuildError(err, false) if err != nil { return err } @@ -526,14 +526,19 @@ func decodeExporterResponse(exporterResponse map[string]string) map[string]inter return out } -func wrapBuildError(err error) error { +func wrapBuildError(err error, bake bool) 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"} + msg := "current frontend does not support --build-context." + if bake { + msg = "current frontend does not support defining additional contexts for targets." + } + msg += " Named contexts are supported since Dockerfile v1.4. Use #syntax directive in Dockerfile or update to latest BuildKit." + return &wrapped{err, msg} } } return err