Skip to content

Commit 96bb2b0

Browse files
authored
Merge pull request #4718 from kolyshkin/embed-version
Embed version from VERSION
2 parents a3a8a2e + c12c99b commit 96bb2b0

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ BUILDTAGS += $(EXTRA_BUILDTAGS)
1717

1818
COMMIT := $(shell git describe --dirty --long --always)
1919
EXTRA_VERSION :=
20-
VERSION := $(shell cat ./VERSION)$(EXTRA_VERSION)
21-
LDFLAGS_COMMON := -X main.gitCommit=$(COMMIT) -X main.version=$(VERSION)
20+
LDFLAGS_COMMON := -X main.gitCommit=$(COMMIT) \
21+
$(if $(strip $(EXTRA_VERSION)),-X main.extraVersion=$(EXTRA_VERSION),)
2222

2323
GOARCH := $(shell $(GO) env GOARCH)
2424

@@ -118,11 +118,11 @@ release: runcimage
118118
--rm -v $(CURDIR):/go/src/$(PROJECT) \
119119
-e RELEASE_ARGS=$(RELEASE_ARGS) \
120120
$(RUNC_IMAGE) make localrelease
121-
script/release_sign.sh -S $(GPG_KEYID) -r release/$(VERSION) -v $(VERSION)
121+
script/release_sign.sh -S $(GPG_KEYID)
122122

123123
.PHONY: localrelease
124124
localrelease: verify-changelog
125-
script/release_build.sh -r release/$(VERSION) -v $(VERSION) $(RELEASE_ARGS)
125+
script/release_build.sh $(RELEASE_ARGS)
126126

127127
.PHONY: dbuild
128128
dbuild: runcimage

main.go

+29-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
_ "embed"
45
"errors"
56
"fmt"
67
"io"
@@ -19,14 +20,36 @@ import (
1920
"github.com/urfave/cli"
2021
)
2122

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 = ""
2532

2633
// 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.
2835
var gitCommit = ""
2936

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+
3053
const (
3154
specConfig = "config.json"
3255
usage = `Open Container Initiative runtime
@@ -57,21 +80,10 @@ value for "bundle" is the current directory.`
5780
func main() {
5881
app := cli.NewApp()
5982
app.Name = "runc"
83+
app.Version = strings.TrimSpace(version) + extraVersion
6084
app.Usage = usage
6185

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
7587

7688
root := "/run/runc"
7789
xdgDirUsed := false

0 commit comments

Comments
 (0)