Skip to content

Commit

Permalink
Merge pull request docker#818 from crazy-max/fix-builder-flag
Browse files Browse the repository at this point in the history
cli: fix builder persistent flag
  • Loading branch information
tonistiigi authored Nov 4, 2021
2 parents 4c938c7 + eab0e6a commit 5c4e3fc
Show file tree
Hide file tree
Showing 34 changed files with 277 additions and 172 deletions.
4 changes: 3 additions & 1 deletion commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/docker/buildx/driver"
"github.com/docker/buildx/store"
"github.com/docker/buildx/store/storeutil"
"github.com/docker/buildx/util/cobrautil"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/google/shlex"
Expand Down Expand Up @@ -238,7 +239,8 @@ func createCmd(dockerCli command.Cli) *cobra.Command {
flags.BoolVar(&options.actionLeave, "leave", false, "Remove a node from builder instead of changing it")
flags.BoolVar(&options.use, "use", false, "Set the current builder instance")

_ = flags
// hide builder persistent flag for this command
cobrautil.HideInheritedFlags(cmd, "builder")

return cmd
}
Expand Down
1 change: 0 additions & 1 deletion commands/imagetools/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ func createCmd(dockerCli command.Cli, opts RootOptions) *cobra.Command {
}

flags := cmd.Flags()

flags.StringArrayVarP(&options.files, "file", "f", []string{}, "Read source descriptor from file")
flags.StringArrayVarP(&options.tags, "tag", "t", []string{}, "Set reference for new image")
flags.BoolVar(&options.dryrun, "dry-run", false, "Show final image instead of pushing")
Expand Down
1 change: 0 additions & 1 deletion commands/imagetools/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func inspectCmd(dockerCli command.Cli, rootOpts RootOptions) *cobra.Command {
}

flags := cmd.Flags()

flags.BoolVar(&options.raw, "raw", false, "Show original JSON manifest")

return cmd
Expand Down
3 changes: 0 additions & 3 deletions commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ func inspectCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
}

flags := cmd.Flags()

flags.BoolVar(&options.bootstrap, "bootstrap", false, "Ensure builder has booted before inspecting")

_ = flags

return cmd
}
4 changes: 4 additions & 0 deletions commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"os"

"github.com/docker/buildx/util/cobrautil"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config"
Expand Down Expand Up @@ -48,5 +49,8 @@ func installCmd(dockerCli command.Cli) *cobra.Command {
Hidden: true,
}

// hide builder persistent flag for this command
cobrautil.HideInheritedFlags(cmd, "builder")

return cmd
}
4 changes: 4 additions & 0 deletions commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/docker/buildx/store"
"github.com/docker/buildx/store/storeutil"
"github.com/docker/buildx/util/cobrautil"
"github.com/docker/buildx/util/platformutil"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand Down Expand Up @@ -148,5 +149,8 @@ func lsCmd(dockerCli command.Cli) *cobra.Command {
},
}

// hide builder persistent flag for this command
cobrautil.HideInheritedFlags(cmd, "builder")

return cmd
}
6 changes: 0 additions & 6 deletions commands/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ func stopCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
},
}

flags := cmd.Flags()

// flags.StringArrayVarP(&options.outputs, "output", "o", []string{}, "Output destination (format: type=local,dest=path)")

_ = flags

return cmd
}

Expand Down
4 changes: 4 additions & 0 deletions commands/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"os"

"github.com/docker/buildx/util/cobrautil"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config"
Expand Down Expand Up @@ -54,5 +55,8 @@ func uninstallCmd(dockerCli command.Cli) *cobra.Command {
Hidden: true,
}

// hide builder persistent flag for this command
cobrautil.HideInheritedFlags(cmd, "builder")

return cmd
}
3 changes: 0 additions & 3 deletions commands/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ func useCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
}

flags := cmd.Flags()

flags.BoolVar(&options.isGlobal, "global", false, "Builder persists context changes")
flags.BoolVar(&options.isDefault, "default", false, "Set builder as default for current context")

_ = flags

return cmd
}
5 changes: 5 additions & 0 deletions commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"

"github.com/docker/buildx/util/cobrautil"
"github.com/docker/buildx/version"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand All @@ -23,5 +24,9 @@ func versionCmd(dockerCli command.Cli) *cobra.Command {
return runVersion(dockerCli)
},
}

// hide builder persistent flag for this command
cobrautil.HideInheritedFlags(cmd, "builder")

return cmd
}
18 changes: 9 additions & 9 deletions docs/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"log"
"os"
"path/filepath"

"github.com/docker/buildx/commands"
clidocstool "github.com/docker/cli-docs-tool"
Expand Down Expand Up @@ -40,27 +39,28 @@ func gen(opts *options) error {
}

cmd.AddCommand(commands.NewRootCmd("buildx", true, dockerCLI))
clidocstool.DisableFlagsInUseLine(cmd)

cwd, _ := os.Getwd()
source := filepath.Join(cwd, opts.source)

if err = os.MkdirAll(source, 0755); err != nil {
c, err := clidocstool.New(clidocstool.Options{
Root: cmd,
SourceDir: opts.source,
Plugin: true,
})
if err != nil {
return err
}

for _, format := range opts.formats {
switch format {
case "md":
if err = clidocstool.GenMarkdownTree(cmd, source); err != nil {
if err = c.GenMarkdownTree(cmd); err != nil {
return err
}
case "yaml":
if err = clidocstool.GenYamlTree(cmd, source); err != nil {
if err = c.GenYamlTree(cmd); err != nil {
return err
}
default:
return errors.Errorf("unknwown doc format %q", format)
return errors.Errorf("unknown format %q", format)
}
}

Expand Down
12 changes: 12 additions & 0 deletions docs/reference/buildx.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,17 @@ Extended build capabilities with BuildKit
| [`version`](buildx_version.md) | Show buildx version information |


### Options

| Name | Description |
| --- | --- |
| [`--builder string`](#builder) | Override the configured builder instance |


<!---MARKER_GEN_END-->

## Examples

### <a name="builder"></a> Override the configured builder instance (--builder)

You can also use the `BUILDX_BUILDER` environment variable.
6 changes: 5 additions & 1 deletion docs/reference/buildx_bake.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Build from a file

| Name | Description |
| --- | --- |
| `--builder string` | Override the configured builder instance |
| [`--builder string`](#builder) | Override the configured builder instance |
| [`-f`](#file), [`--file stringArray`](#file) | Build definition file |
| `--load` | Shorthand for `--set=*.output=type=docker` |
| `--metadata-file string` | Write build result metadata to the file |
Expand Down Expand Up @@ -43,6 +43,10 @@ command and extending the functionality further.

## Examples

### <a name="builder"></a> Override the configured builder instance (--builder)

Same as [`buildx --builder`](buildx.md#builder).

### <a name="file"></a> Specify a build definition file (-f, --file)

By default, `buildx bake` looks for build definition files in the current
Expand Down
6 changes: 5 additions & 1 deletion docs/reference/buildx_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Start a build
| [`--add-host stringSlice`](https://docs.docker.com/engine/reference/commandline/build/#add-entries-to-container-hosts-file---add-host) | Add a custom host-to-IP mapping (format: `host:ip`) |
| [`--allow stringSlice`](#allow) | Allow extra privileged entitlement (e.g., `network.host`, `security.insecure`) |
| [`--build-arg stringArray`](https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg) | Set build-time variables |
| `--builder string` | Override the configured builder instance |
| [`--builder string`](#builder) | Override the configured builder instance |
| [`--cache-from stringArray`](#cache-from) | External cache sources (e.g., `user/app:cache`, `type=local,src=path/to/dir`) |
| [`--cache-to stringArray`](#cache-to) | Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`) |
| [`--cgroup-parent string`](https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent) | Optional parent cgroup for the container |
Expand Down Expand Up @@ -56,6 +56,10 @@ here we’ll document a subset of the new flags.

## Examples

### <a name="builder"></a> Override the configured builder instance (--builder)

Same as [`buildx --builder`](buildx.md#builder).

### <a name="platform"></a> Set the target platforms for the build (--platform)

```
Expand Down
1 change: 0 additions & 1 deletion docs/reference/buildx_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Create a new builder instance
| --- | --- |
| [`--append`](#append) | Append a node to builder instead of changing it |
| `--bootstrap` | Boot builder after creation |
| `--builder string` | Override the configured builder instance |
| [`--buildkitd-flags string`](#buildkitd-flags) | Flags for buildkitd daemon |
| [`--config string`](#config) | BuildKit config file |
| [`--driver string`](#driver) | Driver to use (available: `docker`, `docker-container`, `kubernetes`) |
Expand Down
10 changes: 8 additions & 2 deletions docs/reference/buildx_du.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ Disk usage

| Name | Description |
| --- | --- |
| `--builder string` | Override the configured builder instance |
| [`--builder string`](#builder) | Override the configured builder instance |
| `--filter filter` | Provide filter values |
| `--verbose` | Provide a more verbose output |


<!---MARKER_GEN_END-->
<!---MARKER_GEN_END-->

## Examples

### <a name="builder"></a> Override the configured builder instance (--builder)

Same as [`buildx --builder`](buildx.md#builder).
12 changes: 12 additions & 0 deletions docs/reference/buildx_imagetools.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@ Commands to work on images in registry
| [`inspect`](buildx_imagetools_inspect.md) | Show details of image in the registry |


### Options

| Name | Description |
| --- | --- |
| [`--builder string`](#builder) | Override the configured builder instance |


<!---MARKER_GEN_END-->

## Description

Imagetools contains commands for working with manifest lists in the registry.
These commands are useful for inspecting multi-platform build results.

## Examples

### <a name="builder"></a> Override the configured builder instance (--builder)

Same as [`buildx --builder`](buildx.md#builder).
6 changes: 5 additions & 1 deletion docs/reference/buildx_imagetools_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Create a new image based on source images
| Name | Description |
| --- | --- |
| [`--append`](#append) | Append to existing manifest |
| `--builder string` | Override the configured builder instance |
| [`--builder string`](#builder) | Override the configured builder instance |
| [`--dry-run`](#dry-run) | Show final image instead of pushing |
| [`-f`](#file), [`--file stringArray`](#file) | Read source descriptor from file |
| [`-t`](#tag), [`--tag stringArray`](#tag) | Set reference for new image |
Expand All @@ -37,6 +37,10 @@ specified, create performs a carbon copy.
Use the `--append` flag to append the new sources to an existing manifest list
in the destination.

### <a name="builder"></a> Override the configured builder instance (--builder)

Same as [`buildx --builder`](buildx.md#builder).

### <a name="dry-run"></a> Show final image instead of pushing (--dry-run)

Use the `--dry-run` flag to not push the image, just show it.
Expand Down
8 changes: 7 additions & 1 deletion docs/reference/buildx_imagetools_inspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Show details of image in the registry

| Name | Description |
| --- | --- |
| `--builder string` | Override the configured builder instance |
| [`--builder string`](#builder) | Override the configured builder instance |
| [`--raw`](#raw) | Show original JSON manifest |


Expand Down Expand Up @@ -41,6 +41,12 @@ Manifests:
...
```

## Examples

### <a name="builder"></a> Override the configured builder instance (--builder)

Same as [`buildx --builder`](buildx.md#builder).

### <a name="raw"></a> Show original, unformatted JSON manifest (--raw)

Use the `--raw` option to print the original JSON bytes instead of the formatted
Expand Down
24 changes: 14 additions & 10 deletions docs/reference/buildx_inspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Inspect current builder instance
| Name | Description |
| --- | --- |
| [`--bootstrap`](#bootstrap) | Ensure builder has booted before inspecting |
| `--builder string` | Override the configured builder instance |
| [`--builder string`](#builder) | Override the configured builder instance |


<!---MARKER_GEN_END-->
Expand All @@ -23,6 +23,19 @@ Shows information about the current or specified builder.

## Examples

### <a name="bootstrap"></a> Ensure that the builder is running before inspecting (--bootstrap)

Use the `--bootstrap` option to ensure that the builder is running before
inspecting it. If the driver is `docker-container`, then `--bootstrap` starts
the buildkit container and waits until it is operational. Bootstrapping is
automatically done during build, and therefore not necessary. The same BuildKit
container is used during the lifetime of the associated builder node (as
displayed in `buildx ls`).

### <a name="builder"></a> Override the configured builder instance (--builder)

Same as [`buildx --builder`](buildx.md#builder).

### Get information about a builder instance

By default, `inspect` shows information about the current builder. Specify the
Expand All @@ -47,12 +60,3 @@ Endpoint: ssh://[email protected]
Status: running
Platforms: linux/arm64, linux/arm/v7, linux/arm/v6
```

### <a name="bootstrap"></a> Ensure that the builder is running before inspecting (--bootstrap)

Use the `--bootstrap` option to ensure that the builder is running before
inspecting it. If the driver is `docker-container`, then `--bootstrap` starts
the buildkit container and waits until it is operational. Bootstrapping is
automatically done during build, and therefore not necessary. The same BuildKit
container is used during the lifetime of the associated builder node (as
displayed in `buildx ls`).
7 changes: 6 additions & 1 deletion docs/reference/buildx_prune.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Remove build cache
| Name | Description |
| --- | --- |
| `-a`, `--all` | Remove all unused images, not just dangling ones |
| `--builder string` | Override the configured builder instance |
| [`--builder string`](#builder) | Override the configured builder instance |
| `--filter filter` | Provide filter values (e.g., `until=24h`) |
| `-f`, `--force` | Do not prompt for confirmation |
| `--keep-storage bytes` | Amount of disk space to keep for cache |
Expand All @@ -21,3 +21,8 @@ Remove build cache

<!---MARKER_GEN_END-->

## Examples

### <a name="builder"></a> Override the configured builder instance (--builder)

Same as [`buildx --builder`](buildx.md#builder).
Loading

0 comments on commit 5c4e3fc

Please sign in to comment.