@@ -26,6 +26,7 @@ import (
26
26
devtools "github.com/elastic/elastic-agent-poc/dev-tools/mage"
27
27
"github.com/elastic/elastic-agent-poc/elastic-agent/pkg/release"
28
28
29
+ downloads "github.com/elastic/e2e-testing/pkg/downloads"
29
30
// mage:import
30
31
"github.com/elastic/elastic-agent-poc/dev-tools/mage/target/common"
31
32
// mage:import
@@ -37,14 +38,15 @@ import (
37
38
)
38
39
39
40
const (
40
- goLintRepo = "golang.org/x/lint/golint"
41
- goLicenserRepo = "github.com/elastic/go-licenser"
42
- buildDir = "build"
43
- metaDir = "_meta"
44
- snapshotEnv = "SNAPSHOT"
45
- devEnv = "DEV"
46
- configFile = "elastic-agent.yml"
47
- agentDropPath = "AGENT_DROP_PATH"
41
+ goLintRepo = "golang.org/x/lint/golint"
42
+ goLicenserRepo = "github.com/elastic/go-licenser"
43
+ buildDir = "build"
44
+ metaDir = "_meta"
45
+ snapshotEnv = "SNAPSHOT"
46
+ devEnv = "DEV"
47
+ externalArtifacts = "EXTERNAL"
48
+ configFile = "elastic-agent.yml"
49
+ agentDropPath = "AGENT_DROP_PATH"
48
50
)
49
51
50
52
// Aliases for commands required by master makefile
@@ -325,13 +327,15 @@ func Package() {
325
327
326
328
packageAgent (requiredPackages , devtools .UseElasticAgentPackaging )
327
329
}
328
-
330
+ func getPackageName (beat , version , pkg string ) (string , string ) {
331
+ if _ , ok := os .LookupEnv (snapshotEnv ); ok {
332
+ version += "-SNAPSHOT"
333
+ }
334
+ return version , fmt .Sprintf ("%s-%s-%s" , beat , version , pkg )
335
+ }
329
336
func requiredPackagesPresent (basePath , beat , version string , requiredPackages []string ) bool {
330
337
for _ , pkg := range requiredPackages {
331
- if _ , ok := os .LookupEnv (snapshotEnv ); ok {
332
- version += "-SNAPSHOT"
333
- }
334
- packageName := fmt .Sprintf ("%s-%s-%s" , beat , version , pkg )
338
+ _ , packageName := getPackageName (beat , version , pkg )
335
339
path := filepath .Join (basePath , "build" , "distributions" , packageName )
336
340
337
341
if _ , err := os .Stat (path ); err != nil {
@@ -589,34 +593,48 @@ func packageAgent(requiredPackages []string, packagingFn func()) {
589
593
defer os .Unsetenv (agentDropPath )
590
594
591
595
packedBeats := []string {"filebeat" , "heartbeat" , "metricbeat" , "osquerybeat" }
592
-
593
- for _ , b := range packedBeats {
594
- pwd , err := filepath .Abs (filepath .Join ("../../beats" , b ))
595
- if err != nil {
596
- panic (err )
596
+ if devtools .ExternalBuild == true {
597
+ ctx := context .Background ()
598
+ for _ , beat := range packedBeats {
599
+ for _ , reqPackage := range requiredPackages {
600
+ newVersion , packageName := getPackageName (beat , version , reqPackage )
601
+ err := fetchBinaryFromArtifactsApi (ctx , packageName , beat , newVersion , dropPath )
602
+ if err != nil {
603
+ panic (err )
604
+ }
605
+ }
597
606
}
607
+ } else {
608
+ //build from local repo, will assume beats repo is located on the same root level
609
+ for _ , b := range packedBeats {
610
+ pwd , err := filepath .Abs (filepath .Join ("../../beats" , b ))
611
+ if err != nil {
612
+ panic (err )
613
+ }
598
614
599
- if ! requiredPackagesPresent (pwd , b , version , requiredPackages ) {
600
- cmd := exec .Command ("mage" , "package" )
601
- cmd .Dir = pwd
602
- cmd .Stdout = os .Stdout
603
- cmd .Stderr = os .Stderr
604
- cmd .Env = append (os .Environ (), fmt .Sprintf ("PWD=%s" , pwd ), "AGENT_PACKAGING=on" )
605
- if envVar := selectedPackageTypes (); envVar != "" {
606
- cmd .Env = append (cmd .Env , envVar )
615
+ if ! requiredPackagesPresent (pwd , b , version , requiredPackages ) {
616
+ cmd := exec .Command ("mage" , "package" )
617
+ cmd .Dir = pwd
618
+ cmd .Stdout = os .Stdout
619
+ cmd .Stderr = os .Stderr
620
+ cmd .Env = append (os .Environ (), fmt .Sprintf ("PWD=%s" , pwd ), "AGENT_PACKAGING=on" )
621
+ if envVar := selectedPackageTypes (); envVar != "" {
622
+ cmd .Env = append (cmd .Env , envVar )
623
+ }
624
+
625
+ if err := cmd .Run (); err != nil {
626
+ panic (err )
627
+ }
607
628
}
608
629
609
- if err := cmd .Run (); err != nil {
630
+ // copy to new drop
631
+ sourcePath := filepath .Join (pwd , "build" , "distributions" )
632
+ if err := copyAll (sourcePath , dropPath ); err != nil {
610
633
panic (err )
611
634
}
612
635
}
613
-
614
- // copy to new drop
615
- sourcePath := filepath .Join (pwd , "build" , "distributions" )
616
- if err := copyAll (sourcePath , dropPath ); err != nil {
617
- panic (err )
618
- }
619
636
}
637
+
620
638
}
621
639
622
640
// package agent
@@ -627,6 +645,14 @@ func packageAgent(requiredPackages []string, packagingFn func()) {
627
645
mg .SerialDeps (devtools .Package , TestPackages )
628
646
}
629
647
648
+ func fetchBinaryFromArtifactsApi (ctx context.Context , packageName , artifact , version , downloadPath string ) error {
649
+ location , err := downloads .FetchBeatsBinary (ctx , packageName , artifact , version , 3 , false , downloadPath , true )
650
+ if err != nil {
651
+ panic (err )
652
+ }
653
+ return nil
654
+ }
655
+
630
656
func selectedPackageTypes () string {
631
657
if len (devtools .SelectedPackageTypes ) == 0 {
632
658
return ""
0 commit comments