fix(cmd): retry clean tag logic for dockerhub (#1976)
This change will ensure that if the curl command for the cleaning of Docker tags on DockerHub fails it will be reattempted up to 2 more times (total of 3) with a 10 second sleep between each attempt. The clean tag logic itself within curl attempts to execute the http request upto 3 times so this will ensure a maximum of 9 attempts.pull/1978/head
parent
4e8d472e46
commit
a31a17b222
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -57,27 +58,27 @@ func dockerBuildOfficialImage(arch string) error {
|
||||||
if buildkiteQEMU != stringTrue {
|
if buildkiteQEMU != stringTrue {
|
||||||
err := utils.CommandWithStdout("docker", "run", "--rm", "--privileged", "multiarch/qemu-user-static", "--reset", "-p", "yes").Run()
|
err := utils.CommandWithStdout("docker", "run", "--rm", "--privileged", "multiarch/qemu-user-static", "--reset", "-p", "yes").Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := utils.CommandWithStdout("bash", "-c", "wget https://github.com/multiarch/qemu-user-static/releases/download/"+qemuversion+"/qemu-arm-static -O ./qemu-arm-static && chmod +x ./qemu-arm-static").Run()
|
err := utils.CommandWithStdout("bash", "-c", "wget https://github.com/multiarch/qemu-user-static/releases/download/"+qemuversion+"/qemu-arm-static -O ./qemu-arm-static && chmod +x ./qemu-arm-static").Run()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
} else if arch == "arm64v8" {
|
} else if arch == "arm64v8" {
|
||||||
if buildkiteQEMU != stringTrue {
|
if buildkiteQEMU != stringTrue {
|
||||||
err := utils.CommandWithStdout("docker", "run", "--rm", "--privileged", "multiarch/qemu-user-static", "--reset", "-p", "yes").Run()
|
err := utils.CommandWithStdout("docker", "run", "--rm", "--privileged", "multiarch/qemu-user-static", "--reset", "-p", "yes").Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := utils.CommandWithStdout("bash", "-c", "wget https://github.com/multiarch/qemu-user-static/releases/download/"+qemuversion+"/qemu-aarch64-static -O ./qemu-aarch64-static && chmod +x ./qemu-aarch64-static").Run()
|
err := utils.CommandWithStdout("bash", "-c", "wget https://github.com/multiarch/qemu-user-static/releases/download/"+qemuversion+"/qemu-aarch64-static -O ./qemu-aarch64-static && chmod +x ./qemu-aarch64-static").Run()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +119,7 @@ var DockerBuildCmd = &cobra.Command{
|
||||||
err = docker.Tag(IntermediateDockerImageName, DockerImageName)
|
err = docker.Tag(IntermediateDockerImageName, DockerImageName)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -204,8 +205,11 @@ func deployManifest(docker *Docker, tag, amd64tag, arm32v7tag, arm64v8tag, regis
|
||||||
for _, t := range tags {
|
for _, t := range tags {
|
||||||
log.Infof("Docker removing tag for %s%s on Docker Hub", dockerImagePrefix, t)
|
log.Infof("Docker removing tag for %s%s on Docker Hub", dockerImagePrefix, t)
|
||||||
|
|
||||||
if err := docker.CleanTag(t); err != nil {
|
if err := utils.RunFuncWithRetry(3, 10*time.Second, func() (err error) {
|
||||||
panic(err)
|
err = docker.CleanTag(t)
|
||||||
|
return
|
||||||
|
}); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,3 +147,23 @@ func RunCommandWithTimeout(cmd *exec.Cmd, timeout time.Duration) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunFuncWithRetry run a function for n attempts with a sleep of n duration between each attempt.
|
||||||
|
func RunFuncWithRetry(attempts int, sleep time.Duration, f func() error) (err error) {
|
||||||
|
for i := 0; ; i++ {
|
||||||
|
err = f()
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if i >= (attempts - 1) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(sleep)
|
||||||
|
|
||||||
|
log.Printf("Retrying after error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("Failed after %d attempts, last error: %s", attempts, err)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue