Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick to 7.9: [build][packaging] Add resilience when docker build (#22050) #22083

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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