client: allow empty address for the system-default value

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
docker-18.09
Akihiro Suda 2017-08-08 08:07:51 +00:00
parent 70521789fe
commit c5ba23d886
1 changed files with 5 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"time" "time"
controlapi "github.com/moby/buildkit/api/services/control" controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/util/appdefaults"
"github.com/pkg/errors" "github.com/pkg/errors"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@ -14,7 +15,7 @@ type Client struct {
type ClientOpt interface{} type ClientOpt interface{}
// New returns a new buildkit client // New returns a new buildkit client. Address can be empty for the system-default address.
func New(address string, opts ...ClientOpt) (*Client, error) { func New(address string, opts ...ClientOpt) (*Client, error) {
gopts := []grpc.DialOption{ gopts := []grpc.DialOption{
grpc.WithInsecure(), grpc.WithInsecure(),
@ -27,6 +28,9 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
gopts = append(gopts, grpc.WithBlock(), grpc.FailOnNonTempDialError(true)) gopts = append(gopts, grpc.WithBlock(), grpc.FailOnNonTempDialError(true))
} }
} }
if address == "" {
address = appdefaults.Socket
}
conn, err := grpc.Dial(dialAddress(address), gopts...) conn, err := grpc.Dial(dialAddress(address), gopts...)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q . make sure buildd is running", address) return nil, errors.Wrapf(err, "failed to dial %q . make sure buildd is running", address)