Skip to content

Commit

Permalink
[build][packaging] Add resilience when docker build (elastic#22050) (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Oct 26, 2020
1 parent ddc3d18 commit 15eedf0
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 @@ -450,8 +450,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 @@ -514,6 +519,10 @@ func packageAgent(requiredPackages []string, packagingFn func()) {
mg.SerialDeps(devtools.Package)
}

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 15eedf0

Please sign in to comment.