This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
/
version.go
76 lines (66 loc) · 1.88 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package version
import (
"fmt"
"runtime"
"strings"
"github.com/weaveworks/ignite/pkg/providers"
igniteruntime "github.com/weaveworks/ignite/pkg/runtime"
)
var (
gitMajor = ""
gitMinor = ""
gitVersion = ""
gitCommit = ""
gitTreeState = ""
buildDate = ""
firecrackerVersion = ""
)
// Info stores information about a component's version
type Info struct {
Major string `json:"major"`
Minor string `json:"minor"`
GitVersion string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
GitTreeState string `json:"gitTreeState"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
}
// String returns info as a human-friendly version string.
func (info Info) String() string {
return info.GitVersion
}
// ImageTag returns .GitVersion, but without "+" signs which are disallowed in docker image tags
// Also, if the binary was built from a dirty commit, always use the :dev tag of the ignite-spawn image
func (info Info) ImageTag() string {
// Use the :dev image tag for non-release builds
if GetIgnite().GitTreeState == "dirty" {
return "dev"
}
// Replace plus signs
return strings.ReplaceAll(GetIgnite().GitVersion, "+", "-")
}
// GetIgnite gets ignite's version
func GetIgnite() Info {
return Info{
Major: gitMajor,
Minor: gitMinor,
GitVersion: gitVersion,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}
// GetFirecracker returns firecracker's version
func GetFirecracker() Info {
return Info{
GitVersion: firecrackerVersion,
}
}
func GetCurrentRuntime() igniteruntime.Name {
return providers.RuntimeName
}