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

Crossbuild: use host platform as container runtime #40330

Merged
merged 12 commits into from
Aug 14, 2024
10 changes: 0 additions & 10 deletions dev-tools/mage/crossbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,6 @@ func (b GolangCrossBuilder) Build() error {
"-w", workDir,
)

// Ensure the proper platform is passed
// This fixes an issue where during arm64 linux build for the currently used docker image
// docker.elastic.co/beats-dev/golang-crossbuild:1.22.5-arm the image for amd64 arch is pulled
// and causes problems when using native arch tools on the binaries that are built for arm64 arch.
if strings.HasPrefix(b.Platform, "linux/") {
args = append(args,
"--platform", b.Platform,
)
}

args = append(args,
image,

Expand Down
25 changes: 20 additions & 5 deletions x-pack/osquerybeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func Clean() error {

func execCommand(ctx context.Context, name string, args ...string) error {
ps := strings.Join(append([]string{name}, args...), " ")
fmt.Println(ps)
fmt.Println("Executing command: ", ps)
output, err := command.Execute(ctx, name, args...)
if err != nil {
fmt.Println(ps, ", failed: ", err)
Expand Down Expand Up @@ -130,13 +130,13 @@ func stripLinuxOsqueryd() error {

osArchs := osquerybeat.OSArchs(devtools.Platforms)

strip := func(oquerydPath string) error {
strip := func(oquerydPath string, target distro.OSArch) error {
ok, err := fileutil.FileExists(oquerydPath)
if err != nil {
return err
}
if ok {
if err := execCommand(ctx, "strip", oquerydPath); err != nil {
if err := execCommand(ctx, stripCommand(target), oquerydPath); err != nil {
return err
}
}
Expand All @@ -160,13 +160,13 @@ func stripLinuxOsqueryd() error {
// Checking and stripping osqueryd binary and both paths osquerybeat/build and agentbeat/build
// because at the moment it's unclear if this step was initiated from osquerybeat or agentbeat build
osquerybeatPath := filepath.Clean(filepath.Join(cwd, "../..", querydRelativePath))
err = strip(osquerybeatPath)
err = strip(osquerybeatPath, osarch)
if err != nil {
return err
}

agentbeatPath := filepath.Clean(filepath.Join(cwd, "../../../agentbeat", querydRelativePath))
err = strip(agentbeatPath)
err = strip(agentbeatPath, osarch)
if err != nil {
return err
}
Expand Down Expand Up @@ -260,3 +260,18 @@ func Fields() { mg.Deps(osquerybeat.Update.Fields) }
// Config is an alias for update:config. This is a workaround for
// https://github.com/magefile/mage/issues/217.
func Config() { mg.Deps(osquerybeat.Update.Config) }

func stripCommand(target distro.OSArch) string {
if target.OS != "linux" {
return "strip" // fallback
}

switch target.Arch {
case "arm64":
return "aarch64-linux-gnu-strip"
case "amd64":
return "x86_64-linux-gnu-strip"
}

return "strip"
}
Loading