Skip to content

Commit 3ff21a4

Browse files
mergify[bot]pchilaVihasMakwana
authored
Fix local beats build (#7832) (#7871)
(cherry picked from commit 8c4c195) Co-authored-by: Paolo Chilà <[email protected]> Co-authored-by: Vihas Makwana <[email protected]>
1 parent 8a08133 commit 3ff21a4

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

dev-tools/packaging/settings.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ func Settings() GlobalSettings {
254254
return settings.Settings
255255
}
256256

257-
func FilterComponents(filters ...ComponentFilter) []BinarySpec {
258-
ret := make([]BinarySpec, 0, len(settings.Components))
257+
func FilterComponents(components []BinarySpec, filters ...ComponentFilter) []BinarySpec {
258+
ret := make([]BinarySpec, 0, len(components))
259259

260260
COMPLOOP:
261-
for _, c := range settings.Components {
261+
for _, c := range components {
262262
for _, filter := range filters {
263263
if !filter(c) {
264264
// this filter doesn't match, move to the next component
@@ -283,3 +283,9 @@ func WithFIPS(fips bool) ComponentFilter {
283283
return p.FIPS == fips
284284
}
285285
}
286+
287+
func WithBinaryName(binaryName string) ComponentFilter {
288+
return func(p BinarySpec) bool {
289+
return p.BinaryName == binaryName
290+
}
291+
}

magefile.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ func packageAgent(ctx context.Context, platforms []string, dependenciesVersion s
11431143
}
11441144

11451145
// download/copy all the necessary dependencies for packaging elastic-agent
1146-
archivePath, dropPath := collectPackageDependencies(platforms, dependenciesVersion, packageTypes, dependencies)
1146+
archivePath, dropPath, dependencies := collectPackageDependencies(platforms, dependenciesVersion, packageTypes, dependencies)
11471147

11481148
// cleanup after build
11491149
defer os.RemoveAll(archivePath)
@@ -1180,7 +1180,7 @@ func packageAgent(ctx context.Context, platforms []string, dependenciesVersion s
11801180
// NOTE: after the build is done the caller must:
11811181
// - delete archivePath and dropPath contents
11821182
// - unset AGENT_DROP_PATH environment variable
1183-
func collectPackageDependencies(platforms []string, packageVersion string, packageTypes []devtools.PackageType, dependencies []packaging.BinarySpec) (archivePath, dropPath string) {
1183+
func collectPackageDependencies(platforms []string, packageVersion string, packageTypes []devtools.PackageType, dependencies []packaging.BinarySpec) (archivePath, dropPath string, d []packaging.BinarySpec) {
11841184
dropPath, found := os.LookupEnv(agentDropPath)
11851185

11861186
// try not to shadow too many variables
@@ -1259,6 +1259,12 @@ func collectPackageDependencies(platforms []string, packageVersion string, packa
12591259
}
12601260
} else {
12611261
packedBeats := []string{"agentbeat"}
1262+
// restrict the dependency list only to agentbeat in this case
1263+
dependencies = packaging.FilterComponents(dependencies, packaging.WithBinaryName("agentbeat"))
1264+
if mg.Verbose() {
1265+
log.Printf("Packaging using a beats repository, reducing dependendencies to %v", dependencies)
1266+
}
1267+
12621268
// build from local repo, will assume beats repo is located on the same root level
12631269
for _, b := range packedBeats {
12641270
pwd, err := filepath.Abs(filepath.Join("../beats/x-pack", b))
@@ -1326,7 +1332,7 @@ func collectPackageDependencies(platforms []string, packageVersion string, packa
13261332
} else {
13271333
archivePath = movePackagesToArchive(dropPath, platforms, packageVersion, dependencies)
13281334
}
1329-
return archivePath, dropPath
1335+
return archivePath, dropPath, dependencies
13301336
}
13311337

13321338
func removePythonWheels(matches []string, version string, dependencies []packaging.BinarySpec) []string {
@@ -1436,7 +1442,11 @@ type branchInfo struct {
14361442
// place them under build/dra/buildID. It accepts one argument that has to be a release branch present in staging DRA
14371443
func FetchLatestAgentCoreStagingDRA(ctx context.Context, branch string) error {
14381444

1439-
elasticAgentCoreComponents := packaging.FilterComponents(packaging.WithProjectName(agentCoreProjectName), packaging.WithFIPS(devtools.FIPSBuild))
1445+
components, err := packaging.Components()
1446+
if err != nil {
1447+
return fmt.Errorf("retrieving defined components: %w", err)
1448+
}
1449+
elasticAgentCoreComponents := packaging.FilterComponents(components, packaging.WithProjectName(agentCoreProjectName), packaging.WithFIPS(devtools.FIPSBuild))
14401450

14411451
if len(elasticAgentCoreComponents) != 1 {
14421452
return fmt.Errorf(
@@ -1679,8 +1689,11 @@ func downloadDRAArtifacts(ctx context.Context, build *manifest.Build, version st
16791689
}
16801690

16811691
func useDRAAgentBinaryForPackage(ctx context.Context, manifestURL string, version string) error {
1682-
1683-
elasticAgentCoreComponents := packaging.FilterComponents(packaging.WithProjectName(agentCoreProjectName), packaging.WithFIPS(devtools.FIPSBuild))
1692+
components, err := packaging.Components()
1693+
if err != nil {
1694+
return fmt.Errorf("retrieving defined components: %w", err)
1695+
}
1696+
elasticAgentCoreComponents := packaging.FilterComponents(components, packaging.WithProjectName(agentCoreProjectName), packaging.WithFIPS(devtools.FIPSBuild))
16841697

16851698
if len(elasticAgentCoreComponents) != 1 {
16861699
return fmt.Errorf(

0 commit comments

Comments
 (0)