Skip to content

Commit

Permalink
Merge pull request #743 from tonistiigi/v0.6-client-ctx
Browse files Browse the repository at this point in the history
[v0.6] use long-running context for client initialization
  • Loading branch information
crazy-max authored Aug 20, 2021
2 parents 260d07a + 43e51fd commit de7dfb9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bake/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ReadRemoteFiles(ctx context.Context, dis []build.DriverInfo, url string, na
return nil, nil, nil
}

c, err := driver.Boot(ctx, di.Driver, pw)
c, err := driver.Boot(ctx, ctx, di.Driver, pw)
if err != nil {
return nil, nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ func allIndexes(l int) []int {
func ensureBooted(ctx context.Context, drivers []DriverInfo, idxs []int, pw progress.Writer) ([]*client.Client, error) {
clients := make([]*client.Client, len(drivers))

baseCtx := ctx
eg, ctx := errgroup.WithContext(ctx)

for _, i := range idxs {
func(i int) {
eg.Go(func() error {
c, err := driver.Boot(ctx, drivers[i].Driver, pw)
c, err := driver.Boot(ctx, baseCtx, drivers[i].Driver, pw)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion build/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func createTempDockerfileFromURL(ctx context.Context, d driver.Driver, url string, pw progress.Writer) (string, error) {
c, err := driver.Boot(ctx, d, pw)
c, err := driver.Boot(ctx, ctx, d, pw)
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ func boot(ctx context.Context, ngi *nginfo, dockerCli command.Cli) (bool, error)

printer := progress.NewPrinter(context.TODO(), os.Stderr, "auto")

baseCtx := ctx
eg, _ := errgroup.WithContext(ctx)
for _, idx := range toBoot {
func(idx int) {
eg.Go(func() error {
pw := progress.WithPrefix(printer, ngi.ng.Nodes[idx].Name, len(toBoot) > 1)
_, err := driver.Boot(ctx, ngi.drivers[idx].di.Driver, pw)
_, err := driver.Boot(ctx, baseCtx, ngi.drivers[idx].di.Driver, pw)
if err != nil {
ngi.drivers[idx].err = err
}
Expand Down
4 changes: 2 additions & 2 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Driver interface {
Config() InitConfig
}

func Boot(ctx context.Context, d Driver, pw progress.Writer) (*client.Client, error) {
func Boot(ctx, clientContext context.Context, d Driver, pw progress.Writer) (*client.Client, error) {
try := 0
for {
info, err := d.Info(ctx)
Expand All @@ -78,7 +78,7 @@ func Boot(ctx context.Context, d Driver, pw progress.Writer) (*client.Client, er
}
}

c, err := d.Client(ctx)
c, err := d.Client(clientContext)
if err != nil {
if errors.Cause(err) == ErrNotRunning && try <= 2 {
continue
Expand Down

0 comments on commit de7dfb9

Please sign in to comment.