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.x: [build][packaging] Add resilience when docker build (#22050) #22081

Merged
merged 1 commit into from
Oct 22, 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 @@ -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