Skip to content

Commit

Permalink
erroneous driver returned for docker context
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed May 20, 2022
1 parent 4a215a9 commit 3b2a288
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion commands/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions) (err error
return nil
}

resp, err := build.Build(ctx, dis, bo, dockerAPI(dockerCli), confutil.ConfigDir(dockerCli), printer)
resp, err := build.Build(ctx, dis, bo, dockerAPI(ctx, dockerCli), confutil.ConfigDir(dockerCli), printer)
if err != nil {
return wrapBuildError(err, true)
}
Expand Down
2 changes: 1 addition & 1 deletion commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, opts map[string]bu

printer := progress.NewPrinter(ctx2, os.Stderr, os.Stderr, progressMode)

resp, err := build.Build(ctx, dis, opts, dockerAPI(dockerCli), confutil.ConfigDir(dockerCli), printer)
resp, err := build.Build(ctx, dis, opts, dockerAPI(ctx, dockerCli), confutil.ConfigDir(dockerCli), printer)
err1 := printer.Wait()
if err == nil {
err = err1
Expand Down
25 changes: 18 additions & 7 deletions commands/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func driversForNodeGroup(ctx context.Context, dockerCli command.Cli, ng *store.N
}
} else {
ep := ng.Nodes[0].Endpoint
dockerapi, err := clientForEndpoint(dockerCli, ep)
dockerapi, err := clientForEndpoint(ctx, dockerCli, ep)
if err != nil {
return nil, err
}
Expand All @@ -96,7 +96,7 @@ func driversForNodeGroup(ctx context.Context, dockerCli command.Cli, ng *store.N
dis[i] = di
}()

dockerapi, err := clientForEndpoint(dockerCli, n.Endpoint)
dockerapi, err := clientForEndpoint(ctx, dockerCli, n.Endpoint)
if err != nil {
di.Err = err
return nil
Expand Down Expand Up @@ -170,7 +170,7 @@ func configFromContext(endpointName string, s ctxstore.Reader) (clientcmd.Client
}

// clientForEndpoint returns a docker client for an endpoint
func clientForEndpoint(dockerCli command.Cli, name string) (dockerclient.APIClient, error) {
func clientForEndpoint(ctx context.Context, dockerCli command.Cli, name string) (dockerclient.APIClient, error) {
list, err := dockerCli.ContextStore().List()
if err != nil {
return nil, err
Expand All @@ -193,7 +193,14 @@ func clientForEndpoint(dockerCli command.Cli, name string) (dockerclient.APIClie
if err != nil {
return nil, err
}
return dockerclient.NewClientWithOpts(clientOpts...)
client, err := dockerclient.NewClientWithOpts(clientOpts...)
if err != nil {
return nil, err
}
if _, err = client.Ping(ctx); err != nil {
return nil, err
}
return client, nil
}
}

Expand Down Expand Up @@ -399,19 +406,23 @@ func hasNodeGroup(list []*nginfo, ngi *nginfo) bool {
return false
}

func dockerAPI(dockerCli command.Cli) *api {
return &api{dockerCli: dockerCli}
func dockerAPI(ctx context.Context, dockerCli command.Cli) *api {
return &api{
ctx: ctx,
dockerCli: dockerCli,
}
}

type api struct {
ctx context.Context
dockerCli command.Cli
}

func (a *api) DockerAPI(name string) (dockerclient.APIClient, error) {
if name == "" {
name = a.dockerCli.CurrentContext()
}
return clientForEndpoint(a.dockerCli, name)
return clientForEndpoint(a.ctx, a.dockerCli, name)
}

type dinfo struct {
Expand Down

0 comments on commit 3b2a288

Please sign in to comment.