Skip to content

Commit 06a3143

Browse files
Merge pull request #312 from depot/retry-container-pull
Retry bootstrapping failures
2 parents cc68bbd + 019e213 commit 06a3143

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

pkg/cmd/docker/docker.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/depot/cli/pkg/buildx/imagetools"
1616
depotdockerclient "github.com/depot/cli/pkg/dockerclient"
1717
"github.com/depot/cli/pkg/helpers"
18+
"github.com/depot/cli/pkg/retry"
1819
"github.com/docker/buildx/store"
1920
"github.com/docker/buildx/store/storeutil"
2021
"github.com/docker/buildx/util/confutil"
@@ -291,7 +292,10 @@ func runConfigureBuildx(ctx context.Context, dockerCli command.Cli, project, tok
291292
}
292293

293294
for _, arch := range []string{"amd64", "arm64"} {
294-
err = Bootstrap(ctx, dockerCli, image, projectName, token, arch)
295+
// Occasionally Docker fails to pull the driver containers on the first try. We retry up to 3 times.
296+
err = retry.Retry(func() error {
297+
return Bootstrap(ctx, dockerCli, image, projectName, token, arch)
298+
}, 3)
295299
if err != nil {
296300
return fmt.Errorf("unable create driver container: %w", err)
297301
}

pkg/retry/retry.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package retry
2+
3+
import "time"
4+
5+
func Retry(fn func() error, attempts int) error {
6+
var err error
7+
for i := 0; i < attempts; i++ {
8+
err = fn()
9+
if err == nil {
10+
return nil
11+
}
12+
time.Sleep(1 * time.Second)
13+
}
14+
return err
15+
}

0 commit comments

Comments
 (0)