Skip to content

Commit

Permalink
Merge pull request #623 from tonistiigi/failfast
Browse files Browse the repository at this point in the history
buildctl: replace withblock with dial error check
  • Loading branch information
tiborvass committed Sep 17, 2018
2 parents 80f959c + 653fb12 commit 36be95e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
12 changes: 5 additions & 7 deletions client/client.go
Expand Up @@ -25,12 +25,11 @@ type ClientOpt interface{}
func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error) {
gopts := []grpc.DialOption{
grpc.WithDialer(dialer),
grpc.FailOnNonTempDialError(true),
}
needWithInsecure := true
for _, o := range opts {
if _, ok := o.(*withBlockOpt); ok {
gopts = append(gopts, grpc.WithBlock(), grpc.FailOnNonTempDialError(true))
if _, ok := o.(*withFailFast); ok {
gopts = append(gopts, grpc.FailOnNonTempDialError(true))
}
if credInfo, ok := o.(*withCredentials); ok {
opt, err := loadCredentials(credInfo)
Expand All @@ -52,7 +51,6 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error
if address == "" {
address = appdefaults.Address
}

conn, err := grpc.DialContext(ctx, address, gopts...)
if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q . make sure buildkitd is running", address)
Expand All @@ -71,10 +69,10 @@ func (c *Client) Close() error {
return c.conn.Close()
}

type withBlockOpt struct{}
type withFailFast struct{}

func WithBlock() ClientOpt {
return &withBlockOpt{}
func WithFailFast() ClientOpt {
return &withFailFast{}
}

type withCredentials struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/buildctl/debug/workers.go
Expand Up @@ -32,7 +32,7 @@ var WorkersCommand = cli.Command{
}

func resolveClient(c *cli.Context) (*client.Client, error) {
return client.New(commandContext(c), c.GlobalString("addr"), client.WithBlock())
return client.New(commandContext(c), c.GlobalString("addr"), client.WithFailFast())
}

func listWorkers(clicontext *cli.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/buildctl/main.go
Expand Up @@ -116,7 +116,7 @@ func resolveClient(c *cli.Context) (*client.Client, error) {
cert := c.GlobalString("tlscert")
key := c.GlobalString("tlskey")

opts := []client.ClientOpt{client.WithBlock()}
opts := []client.ClientOpt{client.WithFailFast()}

ctx := commandContext(c)

Expand Down
2 changes: 1 addition & 1 deletion examples/build-using-dockerfile/main.go
Expand Up @@ -77,7 +77,7 @@ func action(clicontext *cli.Context) error {
if tag := clicontext.String("tag"); tag == "" {
return errors.New("tag is not specified")
}
c, err := client.New(ctx, clicontext.String("buildkit-addr"), client.WithBlock())
c, err := client.New(ctx, clicontext.String("buildkit-addr"), client.WithFailFast())
if err != nil {
return err
}
Expand Down

0 comments on commit 36be95e

Please sign in to comment.