Skip to content

Commit

Permalink
[build][packaging] Add resilience when docker build (#22050) (#22082)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Oct 22, 2020
1 parent 624c459 commit 6a780e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 8 additions & 1 deletion dev-tools/mage/dockerbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/magefile/mage/sh"
"github.com/pkg/errors"
Expand Down Expand Up @@ -71,7 +72,13 @@ func (b *dockerBuilder) Build() error {

tag, err := b.dockerBuild()
if err != nil {
return errors.Wrap(err, "failed to build docker")
fmt.Println(">> Building docker images again (after 10 seconds)")
// This sleep is to avoid hitting the docker build issues when resources are not available.
time.Sleep(10)
tag, err = b.dockerBuild()
if err != nil {
return errors.Wrap(err, "failed to build docker")
}
}

if err := b.dockerSave(tag); err != nil {
Expand Down
13 changes: 11 additions & 2 deletions x-pack/elastic-agent/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,13 @@ func runAgent(env map[string]string) error {
}

// build docker image
if err := sh.Run("docker", "build", "-t", tag, "."); err != nil {
return err
if err := dockerBuild(tag); err != nil {
fmt.Println(">> Building docker images again (after 10 seconds)")
// This sleep is to avoid hitting the docker build issues when resources are not available.
time.Sleep(10)
if err := dockerBuild(tag); err != nil {
return err
}
}
}

Expand Down Expand Up @@ -612,6 +617,10 @@ func copyAll(from, to string) error {
})
}

func dockerBuild(tag string) error {
return sh.Run("docker", "build", "-t", tag, ".")
}

func dockerTag() string {
const commitLen = 7
tagBase := "elastic-agent"
Expand Down

0 comments on commit 6a780e7

Please sign in to comment.