Skip to content

Commit

Permalink
ci: reattempt download on failure with a backoff sleep time (#683)
Browse files Browse the repository at this point in the history
Fixes #675

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
  • Loading branch information
mudler authored Sep 21, 2021
1 parent 3e20170 commit 4e56255
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion .github/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"strings"
"sync"
"time"

"github.com/google/go-containerregistry/pkg/crane"
)
Expand All @@ -22,7 +23,18 @@ type resultData struct {
Exists bool
}

func downloadImage(img, dst string) error {
func retryDownload(img, dest string, t int) error {
if err := download(img, dest); err != nil {
if t <= 0 {
return err
}
time.Sleep(time.Duration(t) * time.Second)
return retryDownload(img, dest, t-1)
}
return nil
}

func download(img, dst string) error {
tmpdir, err := ioutil.TempDir(os.TempDir(), "ci")
if err != nil {
return err
Expand All @@ -44,6 +56,10 @@ func downloadImage(img, dst string) error {
return nil
}

func downloadImage(img, dst string) error {
return retryDownload(img, dst, 4)
}

func downloadMeta(p Package, o opData) error {
return downloadImage(p.ImageMetadata(o.FinalRepo), "build")
}
Expand Down Expand Up @@ -179,6 +195,7 @@ func main() {
checkErr(
downloadImage(img, "build"),
)

}
}
} else {
Expand Down

0 comments on commit 4e56255

Please sign in to comment.