Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion auditbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/magefile/mage/mg"
"go.uber.org/multierr"

auditbeat "github.com/elastic/beats/v7/auditbeat/scripts/mage"
devtools "github.com/elastic/beats/v7/dev-tools/mage"
Expand Down Expand Up @@ -59,7 +60,10 @@ func Build() error {
// GolangCrossBuild build the Beat binary inside of the golang-builder.
// Do not use directly, use crossBuild instead.
func GolangCrossBuild() error {
return devtools.GolangCrossBuild(devtools.DefaultGolangCrossBuildArgs())
return multierr.Combine(
devtools.GolangCrossBuild(devtools.DefaultGolangCrossBuildArgs()),
devtools.TestLinuxForCentosGLIBC(),
)
}

// BuildGoDaemon builds the go-daemon binary (use crossBuildGoDaemon).
Expand Down
38 changes: 15 additions & 23 deletions dev-tools/mage/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package mage

import (
"errors"
"fmt"
"log"
"os"
Expand All @@ -28,7 +29,6 @@ import (

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/pkg/errors"
)

// Package packages the Beat for distribution. It generates packages based on
Expand Down Expand Up @@ -201,39 +201,28 @@ func saveIronbank() error {
ironbank := getIronbankContextName()
buildDir := filepath.Join("build", ironbank)
if _, err := os.Stat(buildDir); os.IsNotExist(err) {
return fmt.Errorf("cannot find the folder with the ironbank context: %+v", err)
return fmt.Errorf("cannot find the folder with the ironbank context: %w", err)
}

distributionsDir := "build/distributions"
if _, err := os.Stat(distributionsDir); os.IsNotExist(err) {
err := os.MkdirAll(distributionsDir, 0750)
if err != nil {
return fmt.Errorf("cannot create folder for docker artifacts: %+v", err)
return fmt.Errorf("cannot create folder for docker artifacts: %w", err)
}
}
tarGzFile := filepath.Join(distributionsDir, ironbank+".tar.gz")

// Save the build context as tar.gz artifact
err := TarWithOptions(buildDir, tarGzFile, true)
if err != nil {
return fmt.Errorf("cannot compress the tar.gz file: %+v", err)
return fmt.Errorf("cannot compress the tar.gz file: %w", err)
}

return errors.Wrap(CreateSHA512File(tarGzFile), "failed to create .sha512 file")
}

// updateWithDarwinUniversal checks if darwin/amd64 and darwin/arm64, are listed
// if so, the universal binary was built, then we need to package it as well.
func updateWithDarwinUniversal(platforms BuildPlatformList) BuildPlatformList {
if IsDarwinUniversal() {
platforms = append(platforms,
BuildPlatform{
Name: "darwin/universal",
Flags: CGOSupported | CrossBuildSupported | Default,
})
if err = CreateSHA512File(tarGzFile); err != nil {
return fmt.Errorf("failed to create .sha512 file: %w", err)
}

return platforms
return nil
}

// isPackageTypeSelected returns true if SelectedPackageTypes is empty or if
Expand All @@ -260,8 +249,11 @@ type packageBuilder struct {
func (b packageBuilder) Build() error {
fmt.Printf(">> package: Building %v type=%v for platform=%v\n", b.Spec.Name, b.Type, b.Platform.Name)
log.Printf("Package spec: %+v", b.Spec)
return errors.Wrapf(b.Type.Build(b.Spec), "failed building %v type=%v for platform=%v",
b.Spec.Name, b.Type, b.Platform.Name)
if err := b.Type.Build(b.Spec); err != nil {
return fmt.Errorf("failed building %v type=%v for platform=%v: %w",
b.Spec.Name, b.Type, b.Platform.Name, err)
}
return nil
}

type testPackagesParams struct {
Expand Down Expand Up @@ -366,12 +358,12 @@ func TestPackages(options ...TestPackagesOption) error {
}

// TestLinuxForCentosGLIBC checks the GLIBC requirements of linux/amd64 and
// linux/386 binaries to ensure they meet the requirements for RHEL 6 which has
// glibc 2.12.
// linux/386 binaries to ensure they meet the requirements for RHEL 7 which has
// glibc 2.17.
func TestLinuxForCentosGLIBC() error {
switch Platform.Name {
case "linux/amd64", "linux/386":
return TestBinaryGLIBCVersion(filepath.Join("build/golang-crossbuild", BeatName+"-linux-"+Platform.GOARCH), "2.12")
return TestBinaryGLIBCVersion(filepath.Join("build/golang-crossbuild", BeatName+"-linux-"+Platform.GOARCH), "2.17")
default:
return nil
}
Expand Down
7 changes: 6 additions & 1 deletion packetbeat/scripts/mage/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package mage

import (
"go.uber.org/multierr"

devtools "github.com/elastic/beats/v7/dev-tools/mage"
)

Expand All @@ -34,7 +36,10 @@ func GolangCrossBuild() error {
params.Env["CGO_CFLAGS"] = flags
}

return devtools.GolangCrossBuild(params)
return multierr.Combine(
devtools.GolangCrossBuild(params),
devtools.TestLinuxForCentosGLIBC(),
)
}

// -----------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion x-pack/auditbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/magefile/mage/mg"
"go.uber.org/multierr"

auditbeat "github.com/elastic/beats/v7/auditbeat/scripts/mage"
devtools "github.com/elastic/beats/v7/dev-tools/mage"
Expand Down Expand Up @@ -46,7 +47,10 @@ func Build() error {
// GolangCrossBuild build the Beat binary inside of the golang-builder.
// Do not use directly, use crossBuild instead.
func GolangCrossBuild() error {
return devtools.GolangCrossBuild(devtools.DefaultGolangCrossBuildArgs())
return multierr.Combine(
devtools.GolangCrossBuild(devtools.DefaultGolangCrossBuildArgs()),
devtools.TestLinuxForCentosGLIBC(),
)
}

// CrossBuild cross-builds the beat for all target platforms.
Expand Down
7 changes: 6 additions & 1 deletion x-pack/metricbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"strings"
"time"

"go.uber.org/multierr"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"

Expand Down Expand Up @@ -59,7 +61,10 @@ func GolangCrossBuild() error {
if isWindows32bitRunner() {
args.LDFlags = append(args.LDFlags, "-w")
}
return devtools.GolangCrossBuild(args)
return multierr.Combine(
devtools.GolangCrossBuild(args),
devtools.TestLinuxForCentosGLIBC(),
)
}

// CrossBuild cross-builds the beat for all target platforms.
Expand Down