1
1
package main
2
2
3
3
import (
4
+ _ "embed"
4
5
"errors"
5
6
"fmt"
6
7
"io"
@@ -19,14 +20,36 @@ import (
19
20
"github.com/urfave/cli"
20
21
)
21
22
22
- // version must be set from the contents of VERSION file by go build's
23
- // -X main.version= option in the Makefile.
24
- var version = "unknown"
23
+ // version is set from the contents of VERSION file.
24
+ //
25
+ //go:embed VERSION
26
+ var version string
27
+
28
+ // extraVersion is an optional suffix appended to runc version.
29
+ // It can be set via Makefile ("make EXTRA_VERSION=xxx") or by
30
+ // adding -X main.extraVersion=xxx option to the go build command.
31
+ var extraVersion = ""
25
32
26
33
// gitCommit will be the hash that the binary was built from
27
- // and will be populated by the Makefile
34
+ // and will be populated by the Makefile.
28
35
var gitCommit = ""
29
36
37
+ func printVersion (c * cli.Context ) {
38
+ w := c .App .Writer
39
+
40
+ fmt .Fprintln (w , "runc version" , c .App .Version )
41
+ if gitCommit != "" {
42
+ fmt .Fprintln (w , "commit:" , gitCommit )
43
+ }
44
+ fmt .Fprintln (w , "spec:" , specs .Version )
45
+ fmt .Fprintln (w , "go:" , runtime .Version ())
46
+
47
+ major , minor , micro := seccomp .Version ()
48
+ if major + minor + micro > 0 {
49
+ fmt .Fprintf (w , "libseccomp: %d.%d.%d\n " , major , minor , micro )
50
+ }
51
+ }
52
+
30
53
const (
31
54
specConfig = "config.json"
32
55
usage = `Open Container Initiative runtime
@@ -57,21 +80,10 @@ value for "bundle" is the current directory.`
57
80
func main () {
58
81
app := cli .NewApp ()
59
82
app .Name = "runc"
83
+ app .Version = strings .TrimSpace (version ) + extraVersion
60
84
app .Usage = usage
61
85
62
- v := []string {version }
63
-
64
- if gitCommit != "" {
65
- v = append (v , "commit: " + gitCommit )
66
- }
67
- v = append (v , "spec: " + specs .Version )
68
- v = append (v , "go: " + runtime .Version ())
69
-
70
- major , minor , micro := seccomp .Version ()
71
- if major + minor + micro > 0 {
72
- v = append (v , fmt .Sprintf ("libseccomp: %d.%d.%d" , major , minor , micro ))
73
- }
74
- app .Version = strings .Join (v , "\n " )
86
+ cli .VersionPrinter = printVersion
75
87
76
88
root := "/run/runc"
77
89
xdgDirUsed := false
0 commit comments