[v9.5.x] Build: Add optional build-args for COMMIT_SHA and BUILD_BRANCH (#66759)
Build: Add optional build-args for COMMIT_SHA and BUILD_BRANCH (#66672) * Remove .git from .dockerignore * Revert "Remove .git from .dockerignore" This reverts commit5a4658f270. * Add optional COMMIT_SHA and BUILD_BRANCH environment variables (cherry picked from commit614427c602) Co-authored-by: Guilherme Caulada <guilherme.caulada@grafana.com>
This commit is contained in:
co-authored by
Guilherme Caulada
parent
826e500bf2
commit
6a1a71f8bd
+12
-2
@@ -217,12 +217,22 @@ func ldflags(opts BuildOpts) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
commitSha := getGitSha()
|
||||
if v := os.Getenv("COMMIT_SHA"); v != "" {
|
||||
commitSha = 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", getGitSha()))
|
||||
b.WriteString(fmt.Sprintf(" -X main.commit=%s", commitSha))
|
||||
b.WriteString(fmt.Sprintf(" -X main.buildstamp=%d", buildStamp))
|
||||
b.WriteString(fmt.Sprintf(" -X main.buildBranch=%s", getGitBranch()))
|
||||
b.WriteString(fmt.Sprintf(" -X main.buildBranch=%s", buildBranch))
|
||||
if v := os.Getenv("LDFLAGS"); v != "" {
|
||||
b.WriteString(fmt.Sprintf(" -extldflags \"%s\"", v))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user