Skip to content

Commit

Permalink
Merge pull request docker#2660 from tonistiigi/debug-flag-cmds
Browse files Browse the repository at this point in the history
commands: add debug as persistent flag
  • Loading branch information
crazy-max authored Aug 22, 2024
2 parents e403ab2 + 7a7a9c8 commit dc7f679
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 16 deletions.
17 changes: 9 additions & 8 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
)

func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Command {
var opt rootOptions
cmd := &cobra.Command{
Short: "Docker Buildx",
Long: `Extended build capabilities with BuildKit`,
Expand All @@ -32,6 +33,10 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
HiddenDefaultCmd: true,
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if opt.debug {
debug.Enable()
}

cmd.SetContext(appcontext.Context())
if !isPlugin {
return nil
Expand All @@ -47,11 +52,6 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
cmd.TraverseChildren = true
cmd.DisableFlagsInUseLine = true
cli.DisableFlagsInUseLine(cmd)

// DEBUG=1 should perform the same as --debug at the docker root level
if debug.IsEnabled() {
debug.Enable()
}
}

logrus.SetFormatter(&logutil.Formatter{})
Expand All @@ -68,16 +68,16 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
cmd.SetHelpTemplate(cmd.HelpTemplate() + "\nExperimental commands and flags are hidden. Set BUILDX_EXPERIMENTAL=1 to show them.\n")
}

addCommands(cmd, dockerCli)
addCommands(cmd, &opt, dockerCli)
return cmd
}

type rootOptions struct {
builder string
debug bool
}

func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
opts := &rootOptions{}
func addCommands(cmd *cobra.Command, opts *rootOptions, dockerCli command.Cli) {
rootFlags(opts, cmd.PersistentFlags())

cmd.AddCommand(
Expand Down Expand Up @@ -112,4 +112,5 @@ func addCommands(cmd *cobra.Command, dockerCli command.Cli) {

func rootFlags(options *rootOptions, flags *pflag.FlagSet) {
flags.StringVar(&options.builder, "builder", os.Getenv("BUILDX_BUILDER"), "Override the configured builder instance")
flags.BoolVarP(&options.debug, "debug", "D", debug.IsEnabled(), "Enable debug logging")
}
1 change: 1 addition & 0 deletions docs/reference/buildx.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Extended build capabilities with BuildKit
| Name | Type | Default | Description |
|:------------------------|:---------|:--------|:-----------------------------------------|
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |


<!---MARKER_GEN_END-->
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_bake.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Build from a file
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| [`--call`](#call) | `string` | `build` | Set method for evaluating build (`check`, `outline`, `targets`) |
| [`--check`](#check) | `bool` | | Shorthand for `--call=check` |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| [`-f`](#file), [`--file`](#file) | `stringArray` | | Build definition file |
| `--load` | `bool` | | Shorthand for `--set=*.output=type=docker` |
| [`--metadata-file`](#metadata-file) | `string` | | Write build result metadata to a file |
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Start a build
| [`--call`](#call) | `string` | `build` | Set method for evaluating build (`check`, `outline`, `targets`) |
| [`--cgroup-parent`](#cgroup-parent) | `string` | | Set the parent cgroup for the `RUN` instructions during build |
| [`--check`](#check) | `bool` | | Shorthand for `--call=check` |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| `--detach` | `bool` | | Detach buildx server (supported only on linux) (EXPERIMENTAL) |
| [`-f`](#file), [`--file`](#file) | `string` | | Name of the Dockerfile (default: `PATH/Dockerfile`) |
| `--iidfile` | `string` | | Write the image ID to a file |
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Create a new builder instance
| `--bootstrap` | `bool` | | Boot builder after creation |
| [`--buildkitd-config`](#buildkitd-config) | `string` | | BuildKit daemon config file |
| [`--buildkitd-flags`](#buildkitd-flags) | `string` | | BuildKit daemon flags |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| [`--driver`](#driver) | `string` | | Driver to use (available: `docker-container`, `kubernetes`, `remote`) |
| [`--driver-opt`](#driver-opt) | `stringArray` | | Options for the driver |
| [`--leave`](#leave) | `bool` | | Remove a node from builder instead of changing it |
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Start debugger (EXPERIMENTAL)
| Name | Type | Default | Description |
|:------------------|:---------|:--------|:--------------------------------------------------------------------------------------------------------------------|
| `--builder` | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| `--detach` | `bool` | `true` | Detach buildx server for the monitor (supported only on linux) (EXPERIMENTAL) |
| `--invoke` | `string` | | Launch a monitor with executing specified command (EXPERIMENTAL) |
| `--on` | `string` | `error` | When to launch the monitor ([always, error]) (EXPERIMENTAL) |
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_debug_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Start a build
| `--call` | `string` | `build` | Set method for evaluating build (`check`, `outline`, `targets`) |
| `--cgroup-parent` | `string` | | Set the parent cgroup for the `RUN` instructions during build |
| `--check` | `bool` | | Shorthand for `--call=check` |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| `--detach` | `bool` | | Detach buildx server (supported only on linux) (EXPERIMENTAL) |
| `-f`, `--file` | `string` | | Name of the Dockerfile (default: `PATH/Dockerfile`) |
| `--iidfile` | `string` | | Write the image ID to a file |
Expand Down
11 changes: 6 additions & 5 deletions docs/reference/buildx_dial-stdio.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ Proxy current stdio streams to builder instance

### Options

| Name | Type | Default | Description |
|:-------------|:---------|:--------|:----------------------------------------------------------------------------------------------------|
| `--builder` | `string` | | Override the configured builder instance |
| `--platform` | `string` | | Target platform: this is used for node selection |
| `--progress` | `string` | `quiet` | Set type of progress output (`auto`, `plain`, `tty`, `rawjson`). Use plain to show container output |
| Name | Type | Default | Description |
|:----------------|:---------|:--------|:----------------------------------------------------------------------------------------------------|
| `--builder` | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| `--platform` | `string` | | Target platform: this is used for node selection |
| `--progress` | `string` | `quiet` | Set type of progress output (`auto`, `plain`, `tty`, `rawjson`). Use plain to show container output |


<!---MARKER_GEN_END-->
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_du.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Disk usage
| Name | Type | Default | Description |
|:------------------------|:---------|:--------|:-----------------------------------------|
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| `--filter` | `filter` | | Provide filter values |
| [`--verbose`](#verbose) | `bool` | | Provide a more verbose output |

Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_imagetools.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Commands to work on images in registry
| Name | Type | Default | Description |
|:------------------------|:---------|:--------|:-----------------------------------------|
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |


<!---MARKER_GEN_END-->
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_imagetools_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Create a new image based on source images
| [`--annotation`](#annotation) | `stringArray` | | Add annotation to the image |
| [`--append`](#append) | `bool` | | Append to existing manifest |
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| [`--dry-run`](#dry-run) | `bool` | | Show final image instead of pushing |
| [`-f`](#file), [`--file`](#file) | `stringArray` | | Read source descriptor from file |
| `--prefer-index` | `bool` | `true` | When only a single source is specified, prefer outputting an image index or manifest list instead of performing a carbon copy |
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_imagetools_inspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Show details of an image in the registry
| Name | Type | Default | Description |
|:------------------------|:---------|:----------------|:----------------------------------------------|
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| [`--format`](#format) | `string` | `{{.Manifest}}` | Format the output using the given Go template |
| [`--raw`](#raw) | `bool` | | Show original, unformatted JSON manifest |

Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_inspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Inspect current builder instance
|:----------------------------|:---------|:--------|:--------------------------------------------|
| [`--bootstrap`](#bootstrap) | `bool` | | Ensure builder has booted before inspecting |
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |


<!---MARKER_GEN_END-->
Expand Down
7 changes: 4 additions & 3 deletions docs/reference/buildx_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ List builder instances

### Options

| Name | Type | Default | Description |
|:----------------------|:---------|:--------|:------------------|
| [`--format`](#format) | `string` | `table` | Format the output |
| Name | Type | Default | Description |
|:----------------------|:---------|:--------|:---------------------|
| `-D`, `--debug` | `bool` | | Enable debug logging |
| [`--format`](#format) | `string` | `table` | Format the output |


<!---MARKER_GEN_END-->
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_prune.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Remove build cache
|:------------------------|:---------|:--------|:------------------------------------------|
| `-a`, `--all` | `bool` | | Include internal/frontend images |
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| `--filter` | `filter` | | Provide filter values (e.g., `until=24h`) |
| `-f`, `--force` | `bool` | | Do not prompt for confirmation |
| `--keep-storage` | `bytes` | `0` | Amount of disk space to keep for cache |
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Remove one or more builder instances
|:------------------------------------|:---------|:--------|:-----------------------------------------|
| [`--all-inactive`](#all-inactive) | `bool` | | Remove all inactive builders |
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| [`-f`](#force), [`--force`](#force) | `bool` | | Do not prompt for confirmation |
| [`--keep-daemon`](#keep-daemon) | `bool` | | Keep the BuildKit daemon running |
| [`--keep-state`](#keep-state) | `bool` | | Keep BuildKit state |
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Stop builder instance
| Name | Type | Default | Description |
|:------------------------|:---------|:--------|:-----------------------------------------|
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |


<!---MARKER_GEN_END-->
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_use.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Set the current builder instance
| Name | Type | Default | Description |
|:------------------------|:---------|:--------|:-------------------------------------------|
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| `--default` | `bool` | | Set builder as default for current context |
| `--global` | `bool` | | Builder persists context changes |

Expand Down
6 changes: 6 additions & 0 deletions docs/reference/buildx_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ docker buildx version
<!---MARKER_GEN_START-->
Show buildx version information

### Options

| Name | Type | Default | Description |
|:----------------|:-------|:--------|:---------------------|
| `-D`, `--debug` | `bool` | | Enable debug logging |


<!---MARKER_GEN_END-->

Expand Down

0 comments on commit dc7f679

Please sign in to comment.