nolint:gocyclo
(dockerCli command.Cli, cmd *cobra.Command, args, osargs []string)
| 48 | |
| 49 | //nolint:gocyclo |
| 50 | func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []string) ([]string, []string, []string, error) { |
| 51 | var buildKitDisabled, useBuilder, useAlias bool |
| 52 | var envs []string |
| 53 | |
| 54 | // check DOCKER_BUILDKIT env var is not empty |
| 55 | // if it is assume we want to use the builder component |
| 56 | if v := os.Getenv("DOCKER_BUILDKIT"); v != "" { |
| 57 | enabled, err := strconv.ParseBool(v) |
| 58 | if err != nil { |
| 59 | return args, osargs, nil, fmt.Errorf("DOCKER_BUILDKIT environment variable expects boolean value: %w", err) |
| 60 | } |
| 61 | if !enabled { |
| 62 | buildKitDisabled = true |
| 63 | } else { |
| 64 | useBuilder = true |
| 65 | } |
| 66 | } |
| 67 | // docker bake always requires buildkit; ignore "DOCKER_BUILDKIT=0". |
| 68 | if buildKitDisabled && len(args) > 0 && args[0] == "bake" { |
| 69 | buildKitDisabled = false |
| 70 | } |
| 71 | |
| 72 | // if a builder alias is defined, use it instead |
| 73 | // of the default one |
| 74 | builderAlias := builderDefaultPlugin |
| 75 | aliasMap := dockerCli.ConfigFile().Aliases |
| 76 | if v, ok := aliasMap[keyBuilderAlias]; ok { |
| 77 | useBuilder = true |
| 78 | useAlias = true |
| 79 | builderAlias = v |
| 80 | } |
| 81 | |
| 82 | // is this a build that should be forwarded to the builder? |
| 83 | fwargs, fwosargs, fwcmdpath, forwarded := forwardBuilder(builderAlias, args, osargs) |
| 84 | if !forwarded { |
| 85 | return args, osargs, nil, nil |
| 86 | } |
| 87 | |
| 88 | if !useBuilder { |
| 89 | // Builder is not explicitly configured as an alias for buildx. |
| 90 | // Detect whether we should use BuildKit, or fallback to the |
| 91 | // legacy builder. |
| 92 | if si := dockerCli.ServerInfo(); si.BuildkitVersion != build.BuilderBuildKit && si.OSType == "windows" { |
| 93 | // The daemon didn't advertise BuildKit as the preferred builder, |
| 94 | // so use the legacy builder, which is still the default for |
| 95 | // Windows / WCOW. |
| 96 | return args, osargs, nil, nil |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if buildKitDisabled { |
| 101 | // When using a Linux daemon, print a warning that the legacy builder |
| 102 | // is deprecated. For Windows / WCOW, BuildKit is still experimental, |
| 103 | // so we don't print this warning, even if the daemon advertised that |
| 104 | // it supports BuildKit. |
| 105 | if dockerCli.ServerInfo().OSType != "windows" { |
| 106 | _, _ = fmt.Fprintf(dockerCli.Err(), "%s\n\n", buildkitDisabledWarning) |
| 107 | } |
searching dependent graphs…