mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-10-31 08:03:43 +08:00 
			
		
		
		
	bake: use better error in named contexts not supported
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
		| @@ -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 { | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Tonis Tiigi
					Tonis Tiigi