Skip to content

Commit a0d6964

Browse files
authored
Merge pull request #417 from Mashimiao/add-version
add version file
2 parents 8a6d284 + 3a46197 commit a0d6964

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ BINDIR ?= $(DESTDIR)/usr/bin
44
BUILDTAGS=
55
RUNTIME ?= runc
66
COMMIT=$(shell git rev-parse HEAD 2> /dev/null || true)
7+
VERSION := ${shell cat ./VERSION}
78

89
all: tool runtimetest
910

1011
tool:
11-
go build -tags "$(BUILDTAGS)" -ldflags "-X main.gitCommit=${COMMIT}" -o oci-runtime-tool ./cmd/oci-runtime-tool
12+
go build -tags "$(BUILDTAGS)" -ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o oci-runtime-tool ./cmd/oci-runtime-tool
1213

1314
.PHONY: runtimetest
1415
runtimetest:
15-
CGO_ENABLED=0 go build -installsuffix cgo -tags "$(BUILDTAGS)" -o runtimetest ./cmd/runtimetest
16+
CGO_ENABLED=0 go build -installsuffix cgo -tags "$(BUILDTAGS)" -ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o runtimetest ./cmd/runtimetest
1617

1718
.PHONY: man
1819
man:

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.3.0

cmd/oci-runtime-tool/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ import (
1212
// and will be populated by the Makefile
1313
var gitCommit = ""
1414

15+
// version will be populated by the Makefile, read from
16+
// VERSION file of the source code.
17+
var version = ""
18+
1519
func main() {
1620
app := cli.NewApp()
1721
app.Name = "oci-runtime-tool"
1822
if gitCommit != "" {
19-
app.Version = fmt.Sprintf("0.3.0, commit: %s", gitCommit)
23+
app.Version = fmt.Sprintf("%s, commit: %s", version, gitCommit)
2024
} else {
21-
app.Version = "0.3.0"
25+
app.Version = version
2226
}
2327
app.Usage = "OCI (Open Container Initiative) runtime tools"
2428
app.Flags = []cli.Flag{

cmd/runtimetest/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ import (
2828
"golang.org/x/sys/unix"
2929
)
3030

31+
// gitCommit will be the hash that the binary was built from
32+
// and will be populated by the Makefile
33+
var gitCommit = ""
34+
35+
// version will be populated by the Makefile, read from
36+
// VERSION file of the source code.
37+
var version = ""
38+
3139
// PrGetNoNewPrivs isn't exposed in Golang so we define it ourselves copying the value from
3240
// the kernel
3341
const PrGetNoNewPrivs = 39
@@ -928,7 +936,11 @@ func run(context *cli.Context) error {
928936
func main() {
929937
app := cli.NewApp()
930938
app.Name = "runtimetest"
931-
app.Version = "0.3.0"
939+
if gitCommit != "" {
940+
app.Version = fmt.Sprintf("%s, commit: %s", version, gitCommit)
941+
} else {
942+
app.Version = version
943+
}
932944
app.Usage = "Compare the environment with an OCI configuration"
933945
app.Description = "runtimetest compares its current environment with an OCI runtime configuration read from config.json in its current working directory. The tests are fairly generic and cover most configurations used by the runtime validation suite, but there are corner cases where a container launched by a valid runtime would not satisfy runtimetest."
934946
app.Flags = []cli.Flag{

0 commit comments

Comments
 (0)