Merge pull request #5947 from thaJeztah/docker_bake
build / prepare (push) Has been cancelled
build / build (push) Has been cancelled
build / bin-image (push) Has been cancelled
build / prepare-plugins (push) Has been cancelled
build / plugins (push) Has been cancelled
codeql / codeql (push) Has been cancelled
e2e / tests (alpine, 23, connhelper-ssh) (push) Has been cancelled
e2e / tests (alpine, 23, local) (push) Has been cancelled
e2e / tests (alpine, 26, connhelper-ssh) (push) Has been cancelled
e2e / tests (alpine, 26, local) (push) Has been cancelled
e2e / tests (alpine, 27, connhelper-ssh) (push) Has been cancelled
e2e / tests (alpine, 27, local) (push) Has been cancelled
e2e / tests (alpine, 28, connhelper-ssh) (push) Has been cancelled
e2e / tests (alpine, 28, local) (push) Has been cancelled
e2e / tests (debian, 23, connhelper-ssh) (push) Has been cancelled
e2e / tests (debian, 23, local) (push) Has been cancelled
e2e / tests (debian, 26, connhelper-ssh) (push) Has been cancelled
e2e / tests (debian, 26, local) (push) Has been cancelled
e2e / tests (debian, 27, connhelper-ssh) (push) Has been cancelled
e2e / tests (debian, 27, local) (push) Has been cancelled
e2e / tests (debian, 28, connhelper-ssh) (push) Has been cancelled
e2e / tests (debian, 28, local) (push) Has been cancelled
test / ctn (push) Has been cancelled
test / host (macos-13) (push) Has been cancelled
test / host (macos-14) (push) Has been cancelled
validate / validate (lint) (push) Has been cancelled
validate / validate (shellcheck) (push) Has been cancelled
validate / validate (update-authors) (push) Has been cancelled
validate / validate (validate-vendor) (push) Has been cancelled
validate / validate-md (push) Has been cancelled
validate / validate-make (manpages) (push) Has been cancelled
validate / validate-make (yamldocs) (push) Has been cancelled

add top-level "docker bake" command as alias for "docker buildx bake"
This commit is contained in:
Paweł Gronowski
2025-04-11 14:44:08 +00:00
committed by GitHub
6 changed files with 56 additions and 0 deletions
+19
View File
@@ -23,3 +23,22 @@ func NewBuilderCommand(dockerCli command.Cli) *cobra.Command {
)
return cmd
}
// NewBakeStubCommand returns a cobra command "stub" for the "bake" subcommand.
// This command is a placeholder / stub that is dynamically replaced by an
// alias for "docker buildx bake" if BuildKit is enabled (and the buildx plugin
// installed).
func NewBakeStubCommand(dockerCLI command.Streams) *cobra.Command {
return &cobra.Command{
Use: "bake [OPTIONS] [TARGET...]",
Short: "Build from a file",
RunE: command.ShowHelp(dockerCLI.Err()),
Annotations: map[string]string{
// We want to show this command in the "top" category in --help
// output, and not to be grouped under "management commands".
"category-top": "5",
"aliases": "docker buildx bake",
"version": "1.31",
},
}
}
+1
View File
@@ -43,6 +43,7 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
system.NewInfoCommand(dockerCli),
// management commands
builder.NewBakeStubCommand(dockerCli),
builder.NewBuilderCommand(dockerCli),
checkpoint.NewCheckpointCommand(dockerCli),
container.NewContainerCommand(dockerCli),
+17
View File
@@ -29,6 +29,10 @@ const (
buildxMissingError = `ERROR: BuildKit is enabled but the buildx component is missing or broken.
Install the buildx component to build images with BuildKit:
https://docs.docker.com/go/buildx/`
bakeMissingError = `ERROR: docker bake requires the buildx component but it is missing or broken.
Install the buildx component to use bake:
https://docs.docker.com/go/buildx/`
)
func newBuilderError(errorMsg string, pluginLoadErr error) error {
@@ -59,6 +63,10 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st
useBuilder = true
}
}
// docker bake always requires buildkit; ignore "DOCKER_BUILDKIT=0".
if buildKitDisabled && len(args) > 0 && args[0] == "bake" {
buildKitDisabled = false
}
// if a builder alias is defined, use it instead
// of the default one
@@ -105,6 +113,10 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st
perr = plugin.Err
}
if perr != nil {
// Using bake without buildx installed is always an error.
if len(args) > 0 && args[0] == "bake" {
return args, osargs, nil, newBuilderError(bakeMissingError, perr)
}
// if builder is enforced with DOCKER_BUILDKIT=1, cmd must fail
// if the plugin is missing or broken.
if useBuilder {
@@ -135,6 +147,11 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st
func forwardBuilder(alias string, args, osargs []string) ([]string, []string, []string, bool) {
aliases := [][3][]string{
{
{"bake"},
{alias, "bake"},
{},
},
{
{"builder"},
{alias},
+6
View File
@@ -247,6 +247,12 @@ func setHelpFunc(dockerCli command.Cli, cmd *cobra.Command) {
}
}
// FIXME(thaJeztah): need a better way for this; hiding the command here, so that it's present" by default for generating docs etc.
if c, _, err := ccmd.Find([]string{"buildx"}); c == nil || err != nil {
if b, _, _ := ccmd.Find([]string{"bake"}); b != nil {
b.Hidden = true
}
}
if err := isSupported(ccmd, dockerCli); err != nil {
ccmd.Println(err)
return
+12
View File
@@ -0,0 +1,12 @@
# docker bake
<!---MARKER_GEN_START-->
Build from a file
### Aliases
`docker buildx bake`
<!---MARKER_GEN_END-->
+1
View File
@@ -8,6 +8,7 @@ The base command for the Docker CLI.
| Name | Description |
|:------------------------------|:------------------------------------------------------------------------------|
| [`attach`](attach.md) | Attach local standard input, output, and error streams to a running container |
| [`bake`](bake.md) | Build from a file |
| [`build`](build.md) | Build an image from a Dockerfile |
| [`builder`](builder.md) | Manage builds |
| [`checkpoint`](checkpoint.md) | Manage checkpoints |