@@ -2,6 +2,7 @@ package commands
22
33import (
44 "os"
5+ "time"
56
67 debugcmd "github.com/docker/buildx/commands/debug"
78 imagetoolscmd "github.com/docker/buildx/commands/imagetools"
@@ -20,6 +21,8 @@ import (
2021 "github.com/spf13/pflag"
2122)
2223
24+ const defaultTimeoutCli = 20 * time .Second
25+
2326func NewRootCmd (name string , isPlugin bool , dockerCli command.Cli ) * cobra.Command {
2427 cmd := & cobra.Command {
2528 Short : "Docker Buildx" ,
@@ -74,6 +77,7 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
7477
7578type rootOptions struct {
7679 builder string
80+ timeout time.Duration
7781}
7882
7983func addCommands (cmd * cobra.Command , dockerCli command.Cli ) {
@@ -83,10 +87,10 @@ func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
8387 cmd .AddCommand (
8488 buildCmd (dockerCli , opts , nil ),
8589 bakeCmd (dockerCli , opts ),
86- createCmd (dockerCli ),
90+ createCmd (dockerCli , opts ),
8791 dialStdioCmd (dockerCli , opts ),
8892 rmCmd (dockerCli , opts ),
89- lsCmd (dockerCli ),
93+ lsCmd (dockerCli , opts ),
9094 useCmd (dockerCli , opts ),
9195 inspectCmd (dockerCli , opts ),
9296 stopCmd (dockerCli , opts ),
@@ -112,4 +116,14 @@ func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
112116
113117func rootFlags (options * rootOptions , flags * pflag.FlagSet ) {
114118 flags .StringVar (& options .builder , "builder" , os .Getenv ("BUILDX_BUILDER" ), "Override the configured builder instance" )
119+
120+ var timeoutDuration = defaultTimeoutCli
121+ if value , ok := os .LookupEnv ("BUILDX_TIMEOUT" ); ok {
122+ var err error
123+ timeoutDuration , err = time .ParseDuration (value )
124+ if err != nil {
125+ timeoutDuration = defaultTimeoutCli
126+ }
127+ }
128+ flags .DurationVar (& options .timeout , "timeout" , timeoutDuration , "Override the default global timeout (20 seconds)" )
115129}
0 commit comments