Skip to content

Commit 29cef4a

Browse files
committed
mge package
1 parent 0ea2166 commit 29cef4a

File tree

12 files changed

+1141
-1265
lines changed

12 files changed

+1141
-1265
lines changed

NOTICE.txt

+524-567
Large diffs are not rendered by default.

dev-tools/mage/crossbuild.go

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ func (b GolangCrossBuilder) Build() error {
319319
"--env", "MAGEFILE_TIMEOUT="+EnvOr("MAGEFILE_TIMEOUT", ""),
320320
"--env", fmt.Sprintf("SNAPSHOT=%v", Snapshot),
321321
"--env", fmt.Sprintf("DEV=%v", DevBuild),
322+
"--env", fmt.Sprintf("EXTERNAL=%v", ExternalBuild),
322323
"-v", repoInfo.RootDir+":"+mountPoint,
323324
"-w", workDir,
324325
image,

dev-tools/mage/settings.go

+7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var (
8080

8181
Snapshot bool
8282
DevBuild bool
83+
ExternalBuild bool
8384

8485
versionQualified bool
8586
versionQualifier string
@@ -125,6 +126,11 @@ func init() {
125126
panic(errors.Wrap(err, "failed to parse DEV env value"))
126127
}
127128

129+
ExternalBuild, err = strconv.ParseBool(EnvOr("EXTERNAL", "false"))
130+
if err != nil {
131+
panic(errors.Wrap(err, "failed to parse EXTERNAL env value"))
132+
}
133+
128134
versionQualifier, versionQualified = os.LookupEnv("VERSION_QUALIFIER")
129135
}
130136

@@ -176,6 +182,7 @@ func varMap(args ...map[string]interface{}) map[string]interface{} {
176182
"BeatUser": BeatUser,
177183
"Snapshot": Snapshot,
178184
"DEV": DevBuild,
185+
"EXTERNAL": ExternalBuild,
179186
"Qualifier": versionQualifier,
180187
}
181188

dev-tools/mage/settings_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package mage
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
10+
func TestGetVersion(t *testing.T) {
11+
bp, err := BeatQualifiedVersion()
12+
assert.NoError(t, err)
13+
_= bp
14+
}

dev-tools/set_version

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import re
55
import sys
66
from subprocess import check_call
77

8-
vendored_elastic_agent = os.path.normpath("vendor/github.com/elastic/elastic-agent_poc")
8+
vendored_elastic_agent = os.path.normpath("vendor/github.com/elastic/elastic-agent-poc")
99

1010

1111
goversion_var_elastic_agent = "defaultAgentVersion" # version in agent

elastic-agent/Jenkinsfile.yml

-106
This file was deleted.

elastic-agent/docs/version.asciidoc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:stack-version: 8.0.0
2+
:doc-branch: master
3+
:go-version: 1.17.5
4+
:release-state: unreleased
5+
:python: 3.7
6+
:docker: 1.12
7+
:docker-compose: 1.11
8+
:libpcap: 0.8

elastic-agent/magefile.go

+59-33
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
devtools "github.com/elastic/elastic-agent-poc/dev-tools/mage"
2727
"github.com/elastic/elastic-agent-poc/elastic-agent/pkg/release"
2828

29+
downloads "github.com/elastic/e2e-testing/pkg/downloads"
2930
// mage:import
3031
"github.com/elastic/elastic-agent-poc/dev-tools/mage/target/common"
3132
// mage:import
@@ -37,14 +38,15 @@ import (
3738
)
3839

3940
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"
4850
)
4951

5052
// Aliases for commands required by master makefile
@@ -325,13 +327,15 @@ func Package() {
325327

326328
packageAgent(requiredPackages, devtools.UseElasticAgentPackaging)
327329
}
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+
}
329336
func requiredPackagesPresent(basePath, beat, version string, requiredPackages []string) bool {
330337
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)
335339
path := filepath.Join(basePath, "build", "distributions", packageName)
336340

337341
if _, err := os.Stat(path); err != nil {
@@ -589,34 +593,48 @@ func packageAgent(requiredPackages []string, packagingFn func()) {
589593
defer os.Unsetenv(agentDropPath)
590594

591595
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+
}
597606
}
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+
}
598614

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+
}
607628
}
608629

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 {
610633
panic(err)
611634
}
612635
}
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-
}
619636
}
637+
620638
}
621639

622640
// package agent
@@ -627,6 +645,14 @@ func packageAgent(requiredPackages []string, packagingFn func()) {
627645
mg.SerialDeps(devtools.Package, TestPackages)
628646
}
629647

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+
630656
func selectedPackageTypes() string {
631657
if len(devtools.SelectedPackageTypes) == 0 {
632658
return ""

elastic-agent/pkg/release/version.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
package release
1919

2020
import (
21+
"github.com/elastic/elastic-agent-poc/elastic-agent/version"
2122
"strconv"
2223
"strings"
2324
"time"
2425

25-
libbeatVersion "github.com/elastic/beats/v7/libbeat/version"
2626
)
2727

2828
const (
@@ -51,7 +51,7 @@ func TrimCommit(commit string) string {
5151

5252
// Commit returns the current build hash or unknown if it was not injected in the build process.
5353
func Commit() string {
54-
return libbeatVersion.Commit()
54+
return version.Commit()
5555
}
5656

5757
// ShortCommit returns commit up to 6 characters.
@@ -61,12 +61,12 @@ func ShortCommit() string {
6161

6262
// BuildTime returns the build time of the binaries.
6363
func BuildTime() time.Time {
64-
return libbeatVersion.BuildTime()
64+
return version.BuildTime()
6565
}
6666

6767
// Version returns the version of the application.
6868
func Version() string {
69-
return libbeatVersion.GetDefaultVersion()
69+
return version.GetDefaultVersion()
7070
}
7171

7272
// Snapshot returns true if binary was built as snapshot.

elastic-agent/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
package version
66

7-
const defaultBeatVersion = "7.15.3"
7+
const defaultBeatVersion = "8.1.0"

0 commit comments

Comments
 (0)