From 0c0e1f971a3f14474515fca02831f7af01db305d Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 3 Feb 2022 15:01:14 +0000 Subject: [PATCH] Revert "[packaging] Bump golang-crossbuild version debian8 (#23872) (#29687)" This reverts commit b4f83b3e6a3083bcd1faba91efe7afc49529e38b. --- dev-tools/mage/crossbuild.go | 4 +- x-pack/auditbeat/magefile.go | 97 ++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/dev-tools/mage/crossbuild.go b/dev-tools/mage/crossbuild.go index 9f56fd125c3e..b2349310abc4 100644 --- a/dev-tools/mage/crossbuild.go +++ b/dev-tools/mage/crossbuild.go @@ -242,8 +242,8 @@ func CrossBuildImage(platform string) (string, error) { tagSuffix = "s390x" case strings.HasPrefix(platform, "linux"): // Use an older version of libc to gain greater OS compatibility. - // Debian 8 uses glibc 2.19. - tagSuffix = "main-debian8" + // Debian 7 uses glibc 2.13. + tagSuffix = "main-debian7" } goVersion, err := GoVersion() diff --git a/x-pack/auditbeat/magefile.go b/x-pack/auditbeat/magefile.go index 72253937d475..b2d52ebbcbcf 100644 --- a/x-pack/auditbeat/magefile.go +++ b/x-pack/auditbeat/magefile.go @@ -12,6 +12,8 @@ import ( "time" "github.com/magefile/mage/mg" + "github.com/magefile/mage/sh" + "github.com/pkg/errors" auditbeat "github.com/elastic/beats/v7/auditbeat/scripts/mage" devtools "github.com/elastic/beats/v7/dev-tools/mage" @@ -43,6 +45,9 @@ func Build() error { // GolangCrossBuild build the Beat binary inside of the golang-builder. // Do not use directly, use crossBuild instead. func GolangCrossBuild() error { + if d, ok := deps[devtools.Platform.Name]; ok { + mg.Deps(d) + } return devtools.GolangCrossBuild(devtools.DefaultGolangCrossBuildArgs()) } @@ -120,3 +125,95 @@ func ExportDashboard() error { func Dashboards() error { return devtools.KibanaDashboards(devtools.OSSBeatDir("module"), "module") } + +// ----------------------------------------------------------------------------- +// - Install the librpm-dev package +var ( + deps = map[string]func() error{ + "linux/386": installLinux386, + "linux/amd64": installLinuxAMD64, + "linux/arm64": installLinuxARM64, + "linux/armv5": installLinuxARMEL, + "linux/armv6": installLinuxARMEL, + "linux/armv7": installLinuxARMHF, + "linux/mips": installLinuxMIPS, + "linux/mipsle": installLinuxMIPSEL, + "linux/mips64le": installLinuxMIPS64EL, + "linux/ppc64le": installLinuxPPC64EL, + "linux/s390x": installLinuxS390X, + + //"linux/ppc64": installLinuxPpc64, + //"linux/mips64": installLinuxMips64, + } +) + +const ( + librpmDevPkgName = "librpm-dev" + + // Dependency of librpm-dev in ARM architectures, that needs to be explicitly + // installed to replace other conflicting packages pre-installed in the image. + libicuDevPkgName = "libicu-dev" +) + +func installLinuxAMD64() error { + return installDependencies("", librpmDevPkgName) +} + +func installLinuxARM64() error { + return installDependencies("arm64", librpmDevPkgName+":arm64") +} + +func installLinuxARMHF() error { + return installDependencies("armhf", librpmDevPkgName+":armhf", libicuDevPkgName+":armhf") +} + +func installLinuxARMEL() error { + return installDependencies("armel", librpmDevPkgName+":armel", libicuDevPkgName+":armel") +} + +func installLinux386() error { + return installDependencies("i386", librpmDevPkgName+":i386") +} + +func installLinuxMIPS() error { + return installDependencies("mips", librpmDevPkgName+":mips") +} + +func installLinuxMIPS64EL() error { + return installDependencies("mips64el", librpmDevPkgName+":mips64el") +} + +func installLinuxMIPSEL() error { + return installDependencies("mispel", librpmDevPkgName+":mipsel") +} + +func installLinuxPPC64EL() error { + return installDependencies("ppc64el", librpmDevPkgName+":ppc64el") +} + +func installLinuxS390X() error { + return installDependencies("s390x", librpmDevPkgName+":s390x") +} + +func installDependencies(arch string, pkgs ...string) error { + if len(pkgs) == 0 { + return nil + } + if arch != "" { + err := sh.Run("dpkg", "--add-architecture", arch) + if err != nil { + return errors.Wrap(err, "error while adding architecture") + } + } + + // TODO: This is only for debian 7 and should be removed when move to a newer OS. This flag is + // going to be used unnecessary when building using non-debian7 images + // (like when making the linux/arm binaries) and we should remove it soonish. + // See https://github.com/elastic/beats/v7/issues/11750 for more details. + if err := sh.Run("apt-get", "update", "-o", "Acquire::Check-Valid-Until=false"); err != nil { + return err + } + + args := append([]string{"install", "-y", "--no-install-recommends"}, pkgs...) + return sh.Run("apt-get", args...) +}