mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-10-31 08:03:43 +08:00 
			
		
		
		
	commands: provide more helpful error when —build-context is not supported
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
		| @@ -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 | ||||
| } | ||||
|   | ||||
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								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 | ||||
|   | ||||
							
								
								
									
										1
									
								
								vendor/modules.txt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								vendor/modules.txt
									
									
									
									
										vendored
									
									
								
							| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Tonis Tiigi
					Tonis Tiigi