Skip to content

Commit

Permalink
Build version qualifier (elastic#8310)
Browse files Browse the repository at this point in the history
using the BEAT_VERSION_QUALIFIER environment variable
  • Loading branch information
graphaelli authored Sep 18, 2018
1 parent 06ae246 commit 8137c44
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 15 deletions.
1 change: 1 addition & 0 deletions auditbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func Clean() error {
// Package packages the Beat for distribution.
// Use SNAPSHOT=true to build snapshots.
// Use PLATFORMS to control the target platforms.
// Use BEAT_VERSION_QUALIFIER to control the version qualifier.
func Package() {
start := time.Now()
defer func() { fmt.Println("package ran for", time.Since(start)) }()
Expand Down
4 changes: 4 additions & 0 deletions dev-tools/mage/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func DefaultBuildArgs() BuildArgs {
},
}

if versionQualified {
args.Vars["github.com/elastic/beats/libbeat/version.qualifier"] = "{{ .Qualifier }}"
}

repo, err := GetProjectRepoInfo()
if err != nil {
panic(errors.Wrap(err, "failed to determine project repo info"))
Expand Down
3 changes: 3 additions & 0 deletions dev-tools/mage/crossbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func (b GolangCrossBuilder) Build() error {
"--env", "EXEC_GID="+strconv.Itoa(os.Getgid()),
)
}
if versionQualified {
args = append(args, "--env", "BEAT_VERSION_QUALIFIER="+versionQualifier)
}
args = append(args,
"--rm",
"--env", "MAGEFILE_VERBOSE="+verbose,
Expand Down
47 changes: 34 additions & 13 deletions dev-tools/mage/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ var (

Snapshot bool

versionQualified bool
versionQualifier string

FuncMap = map[string]interface{}{
"beat_doc_branch": BeatDocBranch,
"beat_version": BeatVersion,
"beat_version": BeatQualifiedVersion,
"commit": CommitHash,
"date": BuildDate,
"elastic_beats_dir": ElasticBeatsDir,
Expand Down Expand Up @@ -98,6 +101,8 @@ func init() {
if err != nil {
panic(errors.Errorf("failed to parse SNAPSHOT env value", err))
}

versionQualifier, versionQualified = os.LookupEnv("BEAT_VERSION_QUALIFIER")
}

// EnvMap returns map containing the common settings variables and all variables
Expand Down Expand Up @@ -130,6 +135,7 @@ func varMap(args ...map[string]interface{}) map[string]interface{} {
"BeatLicense": BeatLicense,
"BeatURL": BeatURL,
"Snapshot": Snapshot,
"Qualifier": versionQualifier,
}

// Add the extra args to the map.
Expand All @@ -145,18 +151,19 @@ func varMap(args ...map[string]interface{}) map[string]interface{} {
func dumpVariables() (string, error) {
var dumpTemplate = `## Variables
GOOS = {{.GOOS}}
GOARCH = {{.GOARCH}}
GOARM = {{.GOARM}}
Platform = {{.Platform}}
BinaryExt = {{.BinaryExt}}
BeatName = {{.BeatName}}
BeatServiceName = {{.BeatServiceName}}
BeatIndexPrefix = {{.BeatIndexPrefix}}
BeatDescription = {{.BeatDescription}}
BeatVendor = {{.BeatVendor}}
BeatLicense = {{.BeatLicense}}
BeatURL = {{.BeatURL}}
GOOS = {{.GOOS}}
GOARCH = {{.GOARCH}}
GOARM = {{.GOARM}}
Platform = {{.Platform}}
BinaryExt = {{.BinaryExt}}
BeatName = {{.BeatName}}
BeatServiceName = {{.BeatServiceName}}
BeatIndexPrefix = {{.BeatIndexPrefix}}
BeatDescription = {{.BeatDescription}}
BeatVendor = {{.BeatVendor}}
BeatLicense = {{.BeatLicense}}
BeatURL = {{.BeatURL}}
VersionQualifier = {{.Qualifier}}
## Functions
Expand Down Expand Up @@ -310,6 +317,20 @@ var (
beatVersionOnce sync.Once
)

// BeatQualifiedVersion returns the Beat's qualified version. The value can be overwritten by
// setting BEAT_VERSION_QUALIFIER in the environment.
func BeatQualifiedVersion() (string, error) {
version, err := BeatVersion()
if err != nil {
return "", err
}
// version qualifier can intentionally be set to "" to override build time var
if !versionQualified || versionQualifier == "" {
return version, nil
}
return version + "-" + versionQualifier, nil
}

// BeatVersion returns the Beat's version. The value can be overridden by
// setting BEAT_VERSION in the environment.
func BeatVersion() (string, error) {
Expand Down
1 change: 1 addition & 0 deletions filebeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func Clean() error {
// Package packages the Beat for distribution.
// Use SNAPSHOT=true to build snapshots.
// Use PLATFORMS to control the target platforms.
// Use BEAT_VERSION_QUALIFIER to control the version qualifier.
func Package() {
start := time.Now()
defer func() { fmt.Println("package ran for", time.Since(start)) }()
Expand Down
1 change: 1 addition & 0 deletions heartbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func Clean() error {
// Package packages the Beat for distribution.
// Use SNAPSHOT=true to build snapshots.
// Use PLATFORMS to control the target platforms.
// Use BEAT_VERSION_QUALIFIER to control the version qualifier.
func Package() {
start := time.Now()
defer func() { fmt.Println("package ran for", time.Since(start)) }()
Expand Down
6 changes: 5 additions & 1 deletion libbeat/version/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ import "time"
// GetDefaultVersion returns the current libbeat version.
// This method is in a separate file as the version.go file is auto generated
func GetDefaultVersion() string {
return defaultBeatVersion
if qualifier == "" {
return defaultBeatVersion
}
return defaultBeatVersion + "-" + qualifier
}

var (
buildTime = "unknown"
commit = "unknown"
qualifier = "alpha1"
)

// BuildTime exposes the compile-time build time information.
Expand Down
2 changes: 1 addition & 1 deletion libbeat/version/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions metricbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func Clean() error {
// Package packages the Beat for distribution.
// Use SNAPSHOT=true to build snapshots.
// Use PLATFORMS to control the target platforms.
// Use BEAT_VERSION_QUALIFIER to control the version qualifier.
func Package() {
start := time.Now()
defer func() { fmt.Println("package ran for", time.Since(start)) }()
Expand Down
1 change: 1 addition & 0 deletions packetbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func Clean() error {
// Package packages the Beat for distribution.
// Use SNAPSHOT=true to build snapshots.
// Use PLATFORMS to control the target platforms.
// Use BEAT_VERSION_QUALIFIER to control the version qualifier.
func Package() {
start := time.Now()
defer func() { fmt.Println("package ran for", time.Since(start)) }()
Expand Down
1 change: 1 addition & 0 deletions winlogbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func Clean() error {
// Package packages the Beat for distribution.
// Use SNAPSHOT=true to build snapshots.
// Use PLATFORMS to control the target platforms.
// Use BEAT_VERSION_QUALIFIER to control the version qualifier.
func Package() {
start := time.Now()
defer func() { fmt.Println("package ran for", time.Since(start)) }()
Expand Down

0 comments on commit 8137c44

Please sign in to comment.