Build: Add optional build-args for COMMIT_SHA and BUILD_BRANCH (#66672)
* Remove .git from .dockerignore
* Revert "Remove .git from .dockerignore"
This reverts commit 5a4658f270.
* Add optional COMMIT_SHA and BUILD_BRANCH environment variables
This commit is contained in:
+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