diff --git a/log/version.go b/log/version.go index 23e72c986..1d5676510 100644 --- a/log/version.go +++ b/log/version.go @@ -1,6 +1,7 @@ package log import ( + "os" "runtime/debug" ) @@ -48,6 +49,11 @@ func init() { Version = getVersionFromBuildInfo(info) } } + // Try to read version from environment variable if it's not stamped at + // compile time nor from go toolchain + if Version == "" { + Version = getVersionFromEnvVar() + } } func getVersionFromBuildInfo(info *debug.BuildInfo) string { @@ -81,3 +87,9 @@ func getVersionFromBuildInfo(info *debug.BuildInfo) string { } return "" } + +const versionEnvVar = "VERSION" + +func getVersionFromEnvVar() string { + return os.Getenv(versionEnvVar) +}