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

Build version qualifier #8310

Merged
merged 3 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all 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 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand versionQualified is always == versionQualifier != "". Would it make sense to remove that variable to avoid confusion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that once the default build qualifier is empty. See the description where mage package produces a binary where the version subcommand is different than that produced by BEAT_VERSION_QUALIFIER= mage package.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that immediately if we update release manager first.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks for the clarification

}

// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we should put BEAT_VERSION_QUALIFIER in the godocs for the release targets (duplicated in each magefile)?

filebeat akroh$ mage -h package
mage package:

Package packages the Beat for distribution.
Use SNAPSHOT=true to build snapshots.
Use PLATFORMS to control the target platforms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, I'll add that now.

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