HealthCheck: show enterprise commit (#75242)
This commit is contained in:
+11
-1
@@ -222,15 +222,25 @@ func ldflags(opts BuildOpts) (string, error) {
|
||||
commitSha = v
|
||||
}
|
||||
|
||||
var enterpriseCommitSha string
|
||||
if opts.enterprise {
|
||||
enterpriseCommitSha = getGitEnterpriseSha()
|
||||
if v := os.Getenv("ENTERPRISE_COMMIT_SHA"); v != "" {
|
||||
enterpriseCommitSha = v
|
||||
}
|
||||
}
|
||||
|
||||
buildBranch := getGitBranch()
|
||||
if v := os.Getenv("BUILD_BRANCH"); v != "" {
|
||||
buildBranch = v
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
b.WriteString("-w")
|
||||
b.WriteString(fmt.Sprintf(" -X main.version=%s", opts.version))
|
||||
b.WriteString(fmt.Sprintf(" -X main.commit=%s", commitSha))
|
||||
if enterpriseCommitSha != "" {
|
||||
b.WriteString(fmt.Sprintf(" -X main.enterpriseCommit=%s", enterpriseCommitSha))
|
||||
}
|
||||
b.WriteString(fmt.Sprintf(" -X main.buildstamp=%d", buildStamp))
|
||||
b.WriteString(fmt.Sprintf(" -X main.buildBranch=%s", buildBranch))
|
||||
if v := os.Getenv("LDFLAGS"); v != "" {
|
||||
|
||||
@@ -10,9 +10,10 @@ import (
|
||||
)
|
||||
|
||||
type Revision struct {
|
||||
Timestamp int64
|
||||
SHA256 string
|
||||
Branch string
|
||||
Timestamp int64
|
||||
SHA256 string
|
||||
EnterpriseCommit string
|
||||
Branch string
|
||||
}
|
||||
|
||||
func GrafanaTimestamp(ctx context.Context, dir string) (int64, error) {
|
||||
@@ -42,14 +43,23 @@ func GrafanaRevision(ctx context.Context, grafanaDir string) (Revision, error) {
|
||||
return Revision{}, err
|
||||
}
|
||||
|
||||
enterpriseCommit, err := executil.OutputAt(ctx, grafanaDir, "git", "-C", "../grafana-enterprise", "rev-parse", "--short", "HEAD")
|
||||
if err != nil {
|
||||
enterpriseCommit, err = executil.OutputAt(ctx, grafanaDir, "git", "-C", "..", "rev-parse", "--short", "HEAD")
|
||||
if err != nil {
|
||||
return Revision{}, err
|
||||
}
|
||||
}
|
||||
|
||||
branch, err := executil.OutputAt(ctx, grafanaDir, "git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||
if err != nil {
|
||||
return Revision{}, err
|
||||
}
|
||||
|
||||
return Revision{
|
||||
SHA256: sha,
|
||||
Branch: branch,
|
||||
Timestamp: stamp,
|
||||
SHA256: sha,
|
||||
EnterpriseCommit: enterpriseCommit,
|
||||
Branch: branch,
|
||||
Timestamp: stamp,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -15,3 +15,16 @@ func getGitSha() string {
|
||||
}
|
||||
return string(v)
|
||||
}
|
||||
|
||||
func getGitEnterpriseSha() string {
|
||||
// supporting the old way of dev setup
|
||||
v, err := runError("git", "-C", "../grafana-enterprise", "rev-parse", "--short", "HEAD")
|
||||
if err != nil {
|
||||
// supporting the new way of dev setup
|
||||
v, err = runError("git", "-C", "..", "rev-parse", "--short", "HEAD")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return string(v)
|
||||
}
|
||||
|
||||
@@ -23,13 +23,19 @@ const (
|
||||
)
|
||||
|
||||
func GrafanaLDFlags(version string, r config.Revision) []string {
|
||||
return []string{
|
||||
cmd := []string{
|
||||
"-w",
|
||||
fmt.Sprintf("-X main.version=%s", version),
|
||||
fmt.Sprintf("-X main.commit=%s", r.SHA256),
|
||||
fmt.Sprintf("-X main.buildstamp=%d", r.Timestamp),
|
||||
fmt.Sprintf("-X main.buildBranch=%s", r.Branch),
|
||||
}
|
||||
|
||||
if r.EnterpriseCommit != "" {
|
||||
cmd = append(cmd, fmt.Sprintf("-X main.enterpriseCommit=%s", r.EnterpriseCommit))
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// BinaryFolder returns the path to where the Grafana binary is build given the provided arguments.
|
||||
|
||||
Reference in New Issue
Block a user