builder: correct the command path for docker build

The command path sent for `docker build` should be `docker` rather than
`docker build` to be consistent with the other command paths.

* `docker buildx build` has a command path of `docker buildx`
* `docker builder build` has a command path of `docker builder`
* `docker image build` has a command path of `docker image`

The reason this gets set to `docker buildx` rather than `docker buildx
build` is because the `build` portion of the command path is processed
by the plugin. So the command path only contains the portions of the
command path that were processed by this tool.

Since the `build` of `docker build` gets forwarded to `buildx`, it is
not included in the command path.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg 2024-03-15 10:24:05 -05:00
parent a2f3f40233
commit 9392831817
No known key found for this signature in database
GPG Key ID: 6603D4B96394F6B1
1 changed files with 10 additions and 6 deletions

View File

@ -69,7 +69,7 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st
} }
// is this a build that should be forwarded to the builder? // is this a build that should be forwarded to the builder?
fwargs, fwosargs, alias, forwarded := forwardBuilder(builderAlias, args, osargs) fwargs, fwosargs, fwcmdpath, forwarded := forwardBuilder(builderAlias, args, osargs)
if !forwarded { if !forwarded {
return args, osargs, nil, nil return args, osargs, nil, nil
} }
@ -117,33 +117,37 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st
} }
// overwrite the command path for this plugin using the alias name. // overwrite the command path for this plugin using the alias name.
cmd.Annotations[pluginmanager.CommandAnnotationPluginCommandPath] = fmt.Sprintf("%s %s", cmd.CommandPath(), alias) cmd.Annotations[pluginmanager.CommandAnnotationPluginCommandPath] = strings.Join(append([]string{cmd.CommandPath()}, fwcmdpath...), " ")
return fwargs, fwosargs, envs, nil return fwargs, fwosargs, envs, nil
} }
func forwardBuilder(alias string, args, osargs []string) ([]string, []string, string, bool) { func forwardBuilder(alias string, args, osargs []string) ([]string, []string, []string, bool) {
aliases := [][2][]string{ aliases := [][3][]string{
{ {
{"builder"}, {"builder"},
{alias}, {alias},
{"builder"},
}, },
{ {
{"build"}, {"build"},
{alias, "build"}, {alias, "build"},
{},
}, },
{ {
{"image", "build"}, {"image", "build"},
{alias, "build"}, {alias, "build"},
{"image"},
}, },
} }
for _, al := range aliases { for _, al := range aliases {
if fwargs, changed := command.StringSliceReplaceAt(args, al[0], al[1], 0); changed { if fwargs, changed := command.StringSliceReplaceAt(args, al[0], al[1], 0); changed {
fwosargs, _ := command.StringSliceReplaceAt(osargs, al[0], al[1], -1) fwosargs, _ := command.StringSliceReplaceAt(osargs, al[0], al[1], -1)
return fwargs, fwosargs, al[0][0], true fwcmdpath := al[2]
return fwargs, fwosargs, fwcmdpath, true
} }
} }
return args, osargs, "", false return args, osargs, nil, false
} }
// hasBuilderName checks if a builder name is defined in args or env vars // hasBuilderName checks if a builder name is defined in args or env vars