Skip to content

add timeout parameter to cli and driver #2586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion builder/builder.go
Original file line number Diff line number Diff line change
@@ -343,6 +343,7 @@ type CreateOpts struct {
Use bool
Endpoint string
Append bool
Timeout time.Duration
}

func Create(ctx context.Context, txn *store.Txn, dockerCli command.Cli, opts CreateOpts) (*Builder, error) {
@@ -522,7 +523,7 @@ func Create(ctx context.Context, txn *store.Txn, dockerCli command.Cli, opts Cre
return nil, err
}

timeoutCtx, cancel := context.WithTimeout(ctx, 20*time.Second)
timeoutCtx, cancel := context.WithTimeout(ctx, opts.Timeout)
defer cancel()

nodes, err := b.LoadNodes(timeoutCtx, WithData())
4 changes: 4 additions & 0 deletions builder/node.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (
"encoding/json"
"sort"
"strings"
"time"

"github.com/containerd/platforms"
"github.com/docker/buildx/driver"
@@ -38,6 +39,8 @@ type Node struct {
Labels map[string]string
}

const defaultDriverTimeout = 120 * time.Second
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as such:

  • CLI by default has 20 seconds timeout, it can be changed by a user by providing CLI option or env. variable
  • buildx driver factory has 120 seconds timeout, it cannot be changed by a user, it's up to a buildx driver developer to define that value


// Nodes returns nodes for this builder.
func (b *Builder) Nodes() []Node {
return b.nodes
@@ -129,6 +132,7 @@ func (b *Builder) LoadNodes(ctx context.Context, opts ...LoadNodesOption) (_ []N
Platforms: n.Platforms,
ContextPathHash: b.opts.contextPathHash,
DialMeta: lno.dialMeta,
Timeout: defaultDriverTimeout,
})
if err != nil {
node.Err = err
6 changes: 5 additions & 1 deletion commands/create.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"time"

"github.com/docker/buildx/builder"
"github.com/docker/buildx/driver"
@@ -27,6 +28,7 @@ type createOptions struct {
buildkitdFlags string
buildkitdConfigFile string
bootstrap bool
timeout time.Duration
// upgrade bool // perform upgrade of the driver
}

@@ -61,6 +63,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
Use: in.use,
Endpoint: ep,
Append: in.actionAppend,
Timeout: in.timeout,
})
if err != nil {
return err
@@ -80,7 +83,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
return nil
}

func createCmd(dockerCli command.Cli) *cobra.Command {
func createCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
var options createOptions

var drivers bytes.Buffer
@@ -96,6 +99,7 @@ func createCmd(dockerCli command.Cli) *cobra.Command {
Short: "Create a new builder instance",
Args: cli.RequiresMaxArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
options.timeout = rootOpts.timeout
return runCreate(cmd.Context(), dockerCli, options, args)
},
ValidArgsFunction: completion.Disable,
4 changes: 3 additions & 1 deletion commands/inspect.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import (
type inspectOptions struct {
bootstrap bool
builder string
timeout time.Duration
}

func runInspect(ctx context.Context, dockerCli command.Cli, in inspectOptions) error {
@@ -34,7 +35,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, in inspectOptions) e
return err
}

timeoutCtx, cancel := context.WithTimeout(ctx, 20*time.Second)
timeoutCtx, cancel := context.WithTimeout(ctx, in.timeout)
defer cancel()

nodes, err := b.LoadNodes(timeoutCtx, builder.WithData())
@@ -156,6 +157,7 @@ func inspectCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
if len(args) > 0 {
options.builder = args[0]
}
options.timeout = rootOpts.timeout
return runInspect(cmd.Context(), dockerCli, options)
},
ValidArgsFunction: completion.BuilderNames(dockerCli),
8 changes: 5 additions & 3 deletions commands/ls.go
Original file line number Diff line number Diff line change
@@ -35,7 +35,8 @@ const (
)

type lsOptions struct {
format string
format string
timeout time.Duration
}

func runLs(ctx context.Context, dockerCli command.Cli, in lsOptions) error {
@@ -55,7 +56,7 @@ func runLs(ctx context.Context, dockerCli command.Cli, in lsOptions) error {
return err
}

timeoutCtx, cancel := context.WithTimeout(ctx, 20*time.Second)
timeoutCtx, cancel := context.WithTimeout(ctx, in.timeout)
defer cancel()

eg, _ := errgroup.WithContext(timeoutCtx)
@@ -92,14 +93,15 @@ func runLs(ctx context.Context, dockerCli command.Cli, in lsOptions) error {
return nil
}

func lsCmd(dockerCli command.Cli) *cobra.Command {
func lsCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
var options lsOptions

cmd := &cobra.Command{
Use: "ls",
Short: "List builder instances",
Args: cli.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
options.timeout = rootOpts.timeout
return runLs(cmd.Context(), dockerCli, options)
},
ValidArgsFunction: completion.Disable,
4 changes: 3 additions & 1 deletion commands/rm.go
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ type rmOptions struct {
keepDaemon bool
allInactive bool
force bool
timeout time.Duration
}

const (
@@ -109,6 +110,7 @@ func rmCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
}
options.builders = args
}
options.timeout = rootOpts.timeout
return runRm(cmd.Context(), dockerCli, options)
},
ValidArgsFunction: completion.BuilderNames(dockerCli),
@@ -150,7 +152,7 @@ func rmAllInactive(ctx context.Context, txn *store.Txn, dockerCli command.Cli, i
return err
}

timeoutCtx, cancel := context.WithTimeout(ctx, 20*time.Second)
timeoutCtx, cancel := context.WithTimeout(ctx, in.timeout)
defer cancel()

eg, _ := errgroup.WithContext(timeoutCtx)
18 changes: 16 additions & 2 deletions commands/root.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package commands

import (
"os"
"time"

debugcmd "github.com/docker/buildx/commands/debug"
imagetoolscmd "github.com/docker/buildx/commands/imagetools"
@@ -20,6 +21,8 @@ import (
"github.com/spf13/pflag"
)

const defaultTimeoutCli = 20 * time.Second

func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Command {
var opt rootOptions
cmd := &cobra.Command{
@@ -75,6 +78,7 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
type rootOptions struct {
builder string
debug bool
timeout time.Duration
}

func addCommands(cmd *cobra.Command, opts *rootOptions, dockerCli command.Cli) {
@@ -83,10 +87,10 @@ func addCommands(cmd *cobra.Command, opts *rootOptions, dockerCli command.Cli) {
cmd.AddCommand(
buildCmd(dockerCli, opts, nil),
bakeCmd(dockerCli, opts),
createCmd(dockerCli),
createCmd(dockerCli, opts),
dialStdioCmd(dockerCli, opts),
rmCmd(dockerCli, opts),
lsCmd(dockerCli),
lsCmd(dockerCli, opts),
useCmd(dockerCli, opts),
inspectCmd(dockerCli, opts),
stopCmd(dockerCli, opts),
@@ -113,4 +117,14 @@ func addCommands(cmd *cobra.Command, opts *rootOptions, 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")

var timeoutDuration = defaultTimeoutCli
if value, ok := os.LookupEnv("BUILDX_TIMEOUT"); ok {
var err error
timeoutDuration, err = time.ParseDuration(value)
if err != nil {
timeoutDuration = defaultTimeoutCli
}
}
flags.DurationVar(&options.timeout, "timeout", timeoutDuration, "Override the default global timeout (as duration, for example 1m20s)")
}
2 changes: 2 additions & 0 deletions controller/control/controller.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package control
import (
"context"
"io"
"time"

"github.com/docker/buildx/build"
controllerapi "github.com/docker/buildx/controller/pb"
@@ -30,4 +31,5 @@ type ControlOptions struct {
ServerConfig string
Root string
Detach bool
Timeout time.Duration
}
5 changes: 2 additions & 3 deletions controller/remote/controller.go
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ import (
"path/filepath"
"strconv"
"syscall"
"time"

"github.com/containerd/log"
"github.com/docker/buildx/build"
@@ -62,7 +61,7 @@ func NewRemoteBuildxController(ctx context.Context, dockerCli command.Cli, opts
serverRoot := filepath.Join(rootDir, "shared")

// connect to buildx server if it is already running
ctx2, cancel := context.WithTimeout(ctx, 1*time.Second)
ctx2, cancel := context.WithTimeout(ctx, opts.Timeout)
c, err := newBuildxClientAndCheck(ctx2, filepath.Join(serverRoot, defaultSocketFilename))
cancel()
if err != nil {
@@ -90,7 +89,7 @@ func NewRemoteBuildxController(ctx context.Context, dockerCli command.Cli, opts
go wait()

// wait for buildx server to be ready
ctx2, cancel = context.WithTimeout(ctx, 10*time.Second)
ctx2, cancel = context.WithTimeout(ctx, opts.Timeout)
c, err = newBuildxClientAndCheck(ctx2, filepath.Join(serverRoot, defaultSocketFilename))
cancel()
if err != nil {
9 changes: 5 additions & 4 deletions docs/reference/buildx.md
Original file line number Diff line number Diff line change
@@ -29,10 +29,11 @@ Extended build capabilities with BuildKit

### Options

| Name | Type | Default | Description |
|:------------------------|:---------|:--------|:-----------------------------------------|
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| Name | Type | Default | Description |
|:------------------------|:-----------|:--------|:---------------------------------------------------------------------|
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| `--timeout` | `duration` | `20s` | Override the default global timeout (as duration, for example 1m20s) |


<!---MARKER_GEN_END-->
1 change: 1 addition & 0 deletions docs/reference/buildx_bake.md
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ Build from a file
| `--push` | `bool` | | Shorthand for `--set=*.output=type=registry` |
| [`--sbom`](#sbom) | `string` | | Shorthand for `--set=*.attest=type=sbom` |
| [`--set`](#set) | `stringArray` | | Override target value (e.g., `targetpattern.key=value`) |
| `--timeout` | `duration` | `20s` | Override the default global timeout (as duration, for example 1m20s) |


<!---MARKER_GEN_END-->
1 change: 1 addition & 0 deletions docs/reference/buildx_build.md
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ Start a build
| [`--ssh`](#ssh) | `stringArray` | | SSH agent socket or keys to expose to the build (format: `default\|<id>[=<socket>\|<key>[,<key>]]`) |
| [`-t`](#tag), [`--tag`](#tag) | `stringArray` | | Name and optionally a tag (format: `name:tag`) |
| [`--target`](#target) | `string` | | Set the target build stage to build |
| `--timeout` | `duration` | `20s` | Override the default global timeout (as duration, for example 1m20s) |
| [`--ulimit`](#ulimit) | `ulimit` | | Ulimit options |


1 change: 1 addition & 0 deletions docs/reference/buildx_create.md
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ Create a new builder instance
| [`--name`](#name) | `string` | | Builder instance name |
| [`--node`](#node) | `string` | | Create/modify node with given name |
| [`--platform`](#platform) | `stringArray` | | Fixed platforms for current node |
| `--timeout` | `duration` | `20s` | Override the default global timeout (as duration, for example 1m20s) |
| [`--use`](#use) | `bool` | | Set the current builder instance |


21 changes: 11 additions & 10 deletions docs/reference/buildx_debug.md
Original file line number Diff line number Diff line change
@@ -12,16 +12,17 @@ Start debugger (EXPERIMENTAL)

### Options

| 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) |
| `--progress` | `string` | `auto` | Set type of progress output (`auto`, `plain`, `tty`, `rawjson`) for the monitor. Use plain to show container output |
| `--root` | `string` | | Specify root directory of server to connect for the monitor (EXPERIMENTAL) |
| `--server-config` | `string` | | Specify buildx server config file for the monitor (used only when launching new server) (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) |
| `--progress` | `string` | `auto` | Set type of progress output (`auto`, `plain`, `tty`, `rawjson`) for the monitor. Use plain to show container output |
| `--root` | `string` | | Specify root directory of server to connect for the monitor (EXPERIMENTAL) |
| `--server-config` | `string` | | Specify buildx server config file for the monitor (used only when launching new server) (EXPERIMENTAL) |
| `--timeout` | `duration` | `20s` | Override the default global timeout (as duration, for example 1m20s) |


<!---MARKER_GEN_END-->
1 change: 1 addition & 0 deletions docs/reference/buildx_debug_build.md
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ Start a build
| `--ssh` | `stringArray` | | SSH agent socket or keys to expose to the build (format: `default\|<id>[=<socket>\|<key>[,<key>]]`) |
| `-t`, `--tag` | `stringArray` | | Name and optionally a tag (format: `name:tag`) |
| `--target` | `string` | | Set the target build stage to build |
| `--timeout` | `duration` | `20s` | Override the default global timeout (as duration, for example 1m20s) |
| `--ulimit` | `ulimit` | | Ulimit options |


13 changes: 7 additions & 6 deletions docs/reference/buildx_dial-stdio.md
Original file line number Diff line number Diff line change
@@ -5,12 +5,13 @@ Proxy current stdio streams to builder instance

### Options

| 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 |
| 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 |
| `--timeout` | `duration` | `20s` | Override the default global timeout (as duration, for example 1m20s) |


<!---MARKER_GEN_END-->
13 changes: 7 additions & 6 deletions docs/reference/buildx_du.md
Original file line number Diff line number Diff line change
@@ -9,12 +9,13 @@ Disk usage

### Options

| 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 |
| Name | Type | Default | Description |
|:------------------------|:-----------|:--------|:---------------------------------------------------------------------|
| [`--builder`](#builder) | `string` | | Override the configured builder instance |
| `-D`, `--debug` | `bool` | | Enable debug logging |
| `--filter` | `filter` | | Provide filter values |
| `--timeout` | `duration` | `20s` | Override the default global timeout (as duration, for example 1m20s) |
| [`--verbose`](#verbose) | `bool` | | Provide a more verbose output |


<!---MARKER_GEN_END-->
Loading
Oops, something went wrong.