Skip to content

Commit 937f7ac

Browse files
remove mage changes
1 parent 824cc7b commit 937f7ac

File tree

2 files changed

+91
-113
lines changed

2 files changed

+91
-113
lines changed

dev-tools/mage/settings.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var (
8888

8989
Snapshot bool
9090
DevBuild bool
91-
ExternalBuild string
91+
ExternalBuild bool
9292

9393
versionQualified bool
9494
versionQualifier string
@@ -149,7 +149,10 @@ func initGlobals() {
149149
panic(fmt.Errorf("failed to parse DEV env value: %w", err))
150150
}
151151

152-
ExternalBuild = EnvOr("EXTERNAL", "false")
152+
ExternalBuild, err = strconv.ParseBool(EnvOr("EXTERNAL", "false"))
153+
if err != nil {
154+
panic(fmt.Errorf("failed to parse EXTERNAL env value: %w", err))
155+
}
153156

154157
versionQualifier, versionQualified = os.LookupEnv("VERSION_QUALIFIER")
155158

magefile.go

+86-111
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (Dev) Package() {
196196
os.Setenv(devEnv, "true")
197197

198198
if _, hasExternal := os.LookupEnv(externalArtifacts); !hasExternal {
199-
devtools.ExternalBuild = "true"
199+
devtools.ExternalBuild = true
200200
}
201201

202202
devtools.DevBuild = true
@@ -813,7 +813,7 @@ func (Cloud) Image() {
813813
devtools.SelectedPackageTypes = []devtools.PackageType{devtools.Docker}
814814

815815
if _, hasExternal := os.LookupEnv(externalArtifacts); !hasExternal {
816-
devtools.ExternalBuild = "true"
816+
devtools.ExternalBuild = true
817817
}
818818

819819
Package()
@@ -1055,7 +1055,7 @@ func collectPackageDependencies(platforms []string, packageVersion string, requi
10551055

10561056
os.Setenv(agentDropPath, dropPath)
10571057

1058-
if devtools.ExternalBuild == "true" {
1058+
if devtools.ExternalBuild == true {
10591059
// Map of binaries to download to their project name in the unified-release manager.
10601060
// The project names are used to generate the URLs when downloading binaries. For example:
10611061
//
@@ -1077,126 +1077,101 @@ func collectPackageDependencies(platforms []string, packageVersion string, requi
10771077
"pf-elastic-symbolizer": "prodfiler",
10781078
"pf-host-agent": "prodfiler",
10791079
}
1080-
downloadFromExternalBuild(platforms, archivePath, packageVersion, externalBinaries)
1081-
} else if devtools.ExternalBuild == "agentbeat" {
1082-
// package agentbeat, then also pull external builds for non-agentbeat binaries
1083-
externalBinaries := map[string]string{
1084-
"cloudbeat": "cloudbeat", // only supporting linux/amd64 or linux/arm64
1085-
"cloud-defend": "cloud-defend",
1086-
"apm-server": "apm-server", // not supported on darwin/aarch64
1087-
"endpoint-security": "endpoint-dev",
1088-
"fleet-server": "fleet-server",
1089-
"pf-elastic-collector": "prodfiler",
1090-
"pf-elastic-symbolizer": "prodfiler",
1091-
"pf-host-agent": "prodfiler",
1092-
}
1093-
downloadFromExternalBuild(platforms, archivePath, packageVersion, externalBinaries)
1094-
packageAgentBeat(packageVersion, archivePath, requiredPackages)
1095-
1096-
} else {
1097-
packageAgentBeat(packageVersion, archivePath, requiredPackages)
1098-
}
1099-
} else {
1100-
archivePath = movePackagesToArchive(dropPath, requiredPackages)
1101-
}
1102-
return archivePath, dropPath
1103-
}
1104-
1105-
// downloadFromExternalBuild downloads the component binaries and places them in the drop path for the rest of the build
1106-
func downloadFromExternalBuild(platforms []string, archivePath string, packageVersion string, externalBinaries map[string]string) {
1107-
1108-
// Only log fatal logs for logs produced using logrus. This is the global logger
1109-
// used by github.com/elastic/e2e-testing/pkg/downloads which can only be configured globally like this or via
1110-
// environment variables.
1111-
//
1112-
// Using FatalLevel avoids filling the build log with scary looking errors when we attempt to
1113-
// download artifacts on unsupported platforms and choose to ignore the errors.
1114-
//
1115-
// Change this to InfoLevel to see exactly what the downloader is doing.
1116-
logrus.SetLevel(logrus.FatalLevel)
1117-
1118-
errGroup, ctx := errgroup.WithContext(context.Background())
1119-
completedDownloads := &atomic.Int32{}
1120-
for binary, project := range externalBinaries {
1121-
for _, platform := range platforms {
1122-
reqPackage := platformPackages[platform]
1123-
targetPath := filepath.Join(archivePath, reqPackage)
1124-
os.MkdirAll(targetPath, 0755)
1125-
newVersion, packageName := getPackageName(binary, packageVersion, reqPackage)
1126-
errGroup.Go(downloadBinary(ctx, project, packageName, binary, platform, newVersion, targetPath, completedDownloads))
1127-
}
1128-
}
1129-
1130-
err := errGroup.Wait()
1131-
if err != nil {
1132-
panic(err)
1133-
}
1134-
if completedDownloads.Load() == 0 {
1135-
panic(fmt.Sprintf("No packages were successfully downloaded. You may be building against an invalid or unreleased version. version=%s. If this is an unreleased version, try SNAPSHOT=true or EXTERNAL=false", packageVersion))
1136-
}
1137-
}
1138-
1139-
// packageAgentBeat packages the beat from the local code in the beats path
1140-
func packageAgentBeat(packageVersion string, archivePath string, requiredPackages []string) {
1141-
packedBeats := []string{"agentbeat"}
1142-
// build from local repo, will assume beats repo is located on the same root level
1143-
for _, b := range packedBeats {
1144-
pwd, err := filepath.Abs(filepath.Join("../beats/x-pack", b))
1145-
if err != nil {
1146-
panic(err)
1147-
}
1148-
1149-
packagesCopied := 0
11501080

1151-
if !requiredPackagesPresent(pwd, b, packageVersion, requiredPackages) {
1152-
fmt.Printf("--- Package %s\n", pwd)
1153-
cmd := exec.Command("mage", "package")
1154-
cmd.Dir = pwd
1155-
cmd.Stdout = os.Stdout
1156-
cmd.Stderr = os.Stderr
1157-
cmd.Env = append(os.Environ(), fmt.Sprintf("PWD=%s", pwd), "AGENT_PACKAGING=on")
1158-
if envVar := selectedPackageTypes(); envVar != "" {
1159-
cmd.Env = append(cmd.Env, envVar)
1160-
}
1161-
1162-
if err := cmd.Run(); err != nil {
1163-
panic(err)
1081+
// Only log fatal logs for logs produced using logrus. This is the global logger
1082+
// used by github.com/elastic/e2e-testing/pkg/downloads which can only be configured globally like this or via
1083+
// environment variables.
1084+
//
1085+
// Using FatalLevel avoids filling the build log with scary looking errors when we attempt to
1086+
// download artifacts on unsupported platforms and choose to ignore the errors.
1087+
//
1088+
// Change this to InfoLevel to see exactly what the downloader is doing.
1089+
logrus.SetLevel(logrus.FatalLevel)
1090+
1091+
errGroup, ctx := errgroup.WithContext(context.Background())
1092+
completedDownloads := &atomic.Int32{}
1093+
for binary, project := range externalBinaries {
1094+
for _, platform := range platforms {
1095+
reqPackage := platformPackages[platform]
1096+
targetPath := filepath.Join(archivePath, reqPackage)
1097+
os.MkdirAll(targetPath, 0755)
1098+
newVersion, packageName := getPackageName(binary, packageVersion, reqPackage)
1099+
errGroup.Go(downloadBinary(ctx, project, packageName, binary, platform, newVersion, targetPath, completedDownloads))
1100+
}
11641101
}
1165-
}
11661102

1167-
// copy to new drop
1168-
sourcePath := filepath.Join(pwd, "build", "distributions")
1169-
for _, rp := range requiredPackages {
1170-
files, err := filepath.Glob(filepath.Join(sourcePath, "*"+rp+"*"))
1103+
err = errGroup.Wait()
11711104
if err != nil {
11721105
panic(err)
11731106
}
1107+
if completedDownloads.Load() == 0 {
1108+
panic(fmt.Sprintf("No packages were successfully downloaded. You may be building against an invalid or unreleased version. version=%s. If this is an unreleased version, try SNAPSHOT=true or EXTERNAL=false", packageVersion))
1109+
}
1110+
} else {
1111+
packedBeats := []string{"agentbeat"}
1112+
// build from local repo, will assume beats repo is located on the same root level
1113+
for _, b := range packedBeats {
1114+
pwd, err := filepath.Abs(filepath.Join("../beats/x-pack", b))
1115+
if err != nil {
1116+
panic(err)
1117+
}
1118+
1119+
packagesCopied := 0
1120+
1121+
if !requiredPackagesPresent(pwd, b, packageVersion, requiredPackages) {
1122+
fmt.Printf("--- Package %s\n", pwd)
1123+
cmd := exec.Command("mage", "package")
1124+
cmd.Dir = pwd
1125+
cmd.Stdout = os.Stdout
1126+
cmd.Stderr = os.Stderr
1127+
cmd.Env = append(os.Environ(), fmt.Sprintf("PWD=%s", pwd), "AGENT_PACKAGING=on")
1128+
if envVar := selectedPackageTypes(); envVar != "" {
1129+
cmd.Env = append(cmd.Env, envVar)
1130+
}
11741131

1175-
targetPath := filepath.Join(archivePath, rp)
1176-
os.MkdirAll(targetPath, 0755)
1177-
for _, f := range files {
1178-
// safety check; if the user has an older version of the beats repo,
1179-
// for example right after a release where you've `git pulled` from on repo and not the other,
1180-
// they might end up with a mishmash of packages from different versions.
1181-
// check to see if we have mismatched versions.
1182-
if !strings.Contains(f, packageVersion) {
1183-
// if this panic hits weird edge cases where we don't want actual failures, revert to a printf statement.
1184-
panic(fmt.Sprintf("the file %s doesn't match agent version %s, beats repo might be out of date", f, packageVersion))
1132+
if err := cmd.Run(); err != nil {
1133+
panic(err)
1134+
}
11851135
}
11861136

1187-
targetFile := filepath.Join(targetPath, filepath.Base(f))
1188-
packagesCopied += 1
1189-
if err := sh.Copy(targetFile, f); err != nil {
1190-
panic(err)
1137+
// copy to new drop
1138+
sourcePath := filepath.Join(pwd, "build", "distributions")
1139+
for _, rp := range requiredPackages {
1140+
files, err := filepath.Glob(filepath.Join(sourcePath, "*"+rp+"*"))
1141+
if err != nil {
1142+
panic(err)
1143+
}
1144+
1145+
targetPath := filepath.Join(archivePath, rp)
1146+
os.MkdirAll(targetPath, 0755)
1147+
for _, f := range files {
1148+
// safety check; if the user has an older version of the beats repo,
1149+
// for example right after a release where you've `git pulled` from on repo and not the other,
1150+
// they might end up with a mishmash of packages from different versions.
1151+
// check to see if we have mismatched versions.
1152+
if !strings.Contains(f, packageVersion) {
1153+
// if this panic hits weird edge cases where we don't want actual failures, revert to a printf statement.
1154+
panic(fmt.Sprintf("the file %s doesn't match agent version %s, beats repo might be out of date", f, packageVersion))
1155+
}
1156+
1157+
targetFile := filepath.Join(targetPath, filepath.Base(f))
1158+
packagesCopied += 1
1159+
if err := sh.Copy(targetFile, f); err != nil {
1160+
panic(err)
1161+
}
1162+
}
1163+
}
1164+
// a very basic footcannon protector; if packages are missing and we need to rebuild them, check to see if those files were copied
1165+
// if we needed to repackage beats but still somehow copied nothing, could indicate an issue. Usually due to beats and agent being at different versions.
1166+
if packagesCopied == 0 {
1167+
fmt.Println(">>> WARNING: no packages were copied, but we repackaged beats anyway. Check binary to see if intended beats are there.")
11911168
}
11921169
}
11931170
}
1194-
// a very basic footcannon protector; if packages are missing and we need to rebuild them, check to see if those files were copied
1195-
// if we needed to repackage beats but still somehow copied nothing, could indicate an issue. Usually due to beats and agent being at different versions.
1196-
if packagesCopied == 0 {
1197-
fmt.Println(">>> WARNING: no packages were copied, but we repackaged beats anyway. Check binary to see if intended beats are there.")
1198-
}
1171+
} else {
1172+
archivePath = movePackagesToArchive(dropPath, requiredPackages)
11991173
}
1174+
return archivePath, dropPath
12001175
}
12011176

12021177
// flattenDependencies will extract all the required packages collected in archivePath and dropPath in flatPath and
@@ -1240,7 +1215,7 @@ func flattenDependencies(requiredPackages []string, packageVersion, archivePath,
12401215
log.Printf(">>> Extracting %s to %s", m, versionedFlatPath)
12411216
}
12421217
if err := devtools.Extract(m, versionedFlatPath); err != nil {
1243-
panic(fmt.Errorf("error extracting %s: %s", m, err))
1218+
panic(err)
12441219
}
12451220
}
12461221

0 commit comments

Comments
 (0)