Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Elastic Agent] Pick up version from libbeat #18350

Merged
merged 7 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@
- Enable introspecting configuration {pull}18124[18124]
- Follow home path for all config files {pull}18161[18161]
- Use nested objects so fleet can handle metadata correctly {pull}18234[18234]
- Pick up version from libbeat {pull}18350[18350]
67 changes: 29 additions & 38 deletions x-pack/elastic-agent/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (Build) GenerateConfig() error {
// Do not use directly, use crossBuild instead.
func GolangCrossBuildOSS() error {
params := devtools.DefaultGolangCrossBuildArgs()
params.LDFlags = flagsSet()
injectBuildVars(params.Vars)
return devtools.GolangCrossBuild(params)
}

Expand All @@ -117,7 +117,8 @@ func GolangCrossBuildOSS() error {
func GolangCrossBuild() error {
params := devtools.DefaultGolangCrossBuildArgs()
params.OutputDir = "build/golang-crossbuild"
params.LDFlags = flagsSet()
injectBuildVars(params.Vars)

if err := devtools.GolangCrossBuild(params); err != nil {
return err
}
Expand All @@ -136,32 +137,23 @@ func BuildGoDaemon() error {
// BinaryOSS build the fleet artifact.
func (Build) BinaryOSS() error {
mg.Deps(Prepare.Env)
return RunGo(
"build",
"-o", filepath.Join(buildDir, "elastic-agent-oss"),
"-ldflags", flags(),
)
buildArgs := devtools.DefaultBuildArgs()
buildArgs.Name = "elastic-agent-oss"
buildArgs.OutputDir = buildDir
injectBuildVars(buildArgs.Vars)

return devtools.Build(buildArgs)
}

// Binary build the fleet artifact.
func (Build) Binary() error {
mg.Deps(Prepare.Env)
return RunGo(
"build",
"-o", filepath.Join(buildDir, "elastic-agent"),
"-ldflags", flags(),
)
}

// Dev make a special build with the Dev tags.
func (Build) Dev() error {
mg.Deps(Prepare.Env)
return RunGo(
"build",
"-tags", "dev",
"-o", filepath.Join(buildDir, "elastic-agent"),
"-ldflags", flags(),
)
buildArgs := devtools.DefaultBuildArgs()
buildArgs.OutputDir = buildDir
injectBuildVars(buildArgs.Vars)

return devtools.Build(buildArgs)
}

// Clean up dev environment.
Expand Down Expand Up @@ -325,22 +317,6 @@ func commitID() string {
return commitID
}

func flags() string {
return strings.Join(flagsSet(), " ")
}

func flagsSet() []string {
ts := time.Now().Format(time.RFC3339)
commitID := commitID()
isSnapshot, _ := os.LookupEnv(snapshotEnv)

return []string{
fmt.Sprintf(`-X "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release.buildTime=%s"`, ts),
fmt.Sprintf(`-X "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release.commit=%s"`, commitID),
fmt.Sprintf(` -X "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release.snapshot=%s"`, isSnapshot),
}
}

// Update is an alias for executing fields, dashboards, config, includes.
func Update() {
mg.SerialDeps(Config, BuildSpec, BuildFleetCfg)
Expand Down Expand Up @@ -540,3 +516,18 @@ func dockerTag() string {

return tagBase
}

func buildVars() map[string]string {
vars := make(map[string]string)

isSnapshot, _ := os.LookupEnv(snapshotEnv)
vars["github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release.snapshot"] = isSnapshot

return vars
}

func injectBuildVars(m map[string]string) {
for k, v := range buildVars() {
m[k] = v
}
}
16 changes: 0 additions & 16 deletions x-pack/elastic-agent/pkg/release/release_dev.go

This file was deleted.

27 changes: 5 additions & 22 deletions x-pack/elastic-agent/pkg/release/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,26 @@ package release
import (
"strconv"
"time"
)

// version is the current version of the elastic-agent.
var version = "8.0.0"

// buildHash is the hash of the current build.
var commit = "<unknown>"

// buildTime when the binary was build
var buildTime = "<unknown>"

// qualifier returns the version qualifier like alpha1.
var qualifier = ""
libbeatVersion "github.com/elastic/beats/v7/libbeat/version"
)

// snapshot is a flag marking build as a snapshot.
var snapshot = ""

// Commit returns the current build hash or unknown if it was not injected in the build process.
func Commit() string {
return commit
return libbeatVersion.Commit()
}

// BuildTime returns the build time of the binaries.
func BuildTime() time.Time {
t, err := time.Parse(time.RFC3339, buildTime)
if err != nil {
return time.Time{}
}
return t
return libbeatVersion.BuildTime()
}

// Version returns the version of the application.
func Version() string {
if qualifier == "" {
return version
}
return version + "-" + qualifier
return libbeatVersion.GetDefaultVersion()
}

// Snapshot returns true if binary was built as snapshot.
Expand Down
42 changes: 0 additions & 42 deletions x-pack/elastic-agent/pkg/release/version_test.go

This file was deleted.