-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add build flags #76
base: main
Are you sure you want to change the base?
Add build flags #76
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some naming a documentation-consistency changes.
@@ -23,7 +23,7 @@ jobs: | |||
persist-credentials: false | |||
|
|||
- name: build binary | |||
run: go build | |||
run: go build -ldflags "-X github.com/letsencrypt/unbound_exporter/util.BuildID=$(git rev-parse --short HEAD) -X github.com/letsencrypt/unbound_exporter/util.BuildBranch=$(git rev-parse --abbrev-ref HEAD) -X github.com/letsencrypt/unbound_exporter/util.BuildTime=$(date +%F-%T -u)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run: go build -ldflags "-X github.com/letsencrypt/unbound_exporter/util.BuildID=$(git rev-parse --short HEAD) -X github.com/letsencrypt/unbound_exporter/util.BuildBranch=$(git rev-parse --abbrev-ref HEAD) -X github.com/letsencrypt/unbound_exporter/util.BuildTime=$(date +%F-%T -u)" | |
run: go build -ldflags "-X github.com/letsencrypt/unbound_exporter/build.Revision=$(git rev-parse --short HEAD) -X github.com/letsencrypt/unbound_exporter/build.Branch=$(git rev-parse --abbrev-ref HEAD)" |
// BuildID is set by the compiler (using -ldflags "-X util.BuildID $(git rev-parse --short HEAD)") | ||
// and is used by GetID | ||
var BuildID string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// BuildID is set by the compiler (using -ldflags "-X util.BuildID $(git rev-parse --short HEAD)") | |
// and is used by GetID | |
var BuildID string | |
// Revision is set by the compiler (using -ldflags "-X build.Revision $(git rev-parse --short HEAD)") | |
// and is used by GetRevision | |
var Revision string |
// BuildBranch is set by the compiler and is used by GetBranch | ||
var BuildBranch string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// BuildBranch is set by the compiler and is used by GetBranch | |
var BuildBranch string | |
// Branch is set by the compiler and is used by GetBranch | |
var Branch string |
// GetBuildID identifies what build is running. | ||
func GetID() (BuildID string) { | ||
if BuildID != "" { | ||
return BuildID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// GetBuildID identifies what build is running. | |
func GetID() (BuildID string) { | |
if BuildID != "" { | |
return BuildID | |
// GetRevision identifies what commit this binary was built from. | |
func GetRevision() string { | |
if Revision != "" { | |
return Revision |
// and is used by GetID | ||
var BuildID string | ||
|
||
// BuildBranch is set by the compiler and is used by GetBranch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// BuildBranch is set by the compiler and is used by GetBranch | |
// BuildBranch is set by the compiler (using -ldflags "-X build.Branch $git rev-parse --abbrev-rev HEAD)") | |
// and is used by GetBranch |
|
||
const Unspecified = "Unspecified" | ||
|
||
// BuildID is set by the compiler (using -ldflags "-X util.BuildID $(git rev-parse --short HEAD)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// BuildID is set by the compiler (using -ldflags "-X util.BuildID $(git rev-parse --short HEAD)") | |
// Revision is set by the compiler (using -ldflags "-X build.Revision $(git rev-parse --short HEAD)") |
// GetBranch identifies the building host | ||
func GetBranch() (BuildBranch string) { | ||
if BuildBranch != "" { | ||
return BuildBranch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// GetBranch identifies the building host | |
func GetBranch() (BuildBranch string) { | |
if BuildBranch != "" { | |
return BuildBranch | |
// GetBranch identifies what git branch this binary was built from. | |
func GetBranch() string { | |
if Branch != "" { | |
return Branch |
I was planning to push up a PR which would add a This is what the other Prometheus exporters do: https://github.com/prometheus/node_exporter/blob/3afc0a341e3c2c6605b18a882fb045318c18c444/node_exporter.go#L123 - the functionality uses the prometheus.Version data. |
Added a new
//util
package which contains some variables set by the builder at build time to output more information during process startup. This was largely copied from boulder. See below:Fixes #75