Skip to content

Commit

Permalink
Merge pull request kata-containers#7 from jodh-intel/add-version-details
Browse files Browse the repository at this point in the history
Add version details
  • Loading branch information
bergwolf authored Dec 11, 2017
2 parents 478e978 + 2cf7266 commit 37db356
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
all:
go build -o kata-shim
TARGET = kata-shim
SOURCES := $(shell find . 2>&1 | grep -E '.*\.go$$')

VERSION_FILE := ./VERSION
VERSION := $(shell grep -v ^\# $(VERSION_FILE))
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),${COMMIT_NO}-dirty,${COMMIT_NO})
VERSION_COMMIT := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION))

$(TARGET): $(SOURCES) $(VERSION_FILE)
go build -o $@ -ldflags "-X main.version=$(VERSION_COMMIT)"

test:
go test -v -race -coverprofile=coverage.txt -covermode=atomic

clean:
rm -f kata-shim
rm -f $(TARGET)
2 changes: 2 additions & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is the shim version.
0.0.1
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main

import (
"flag"
"fmt"
"os"
"os/signal"
"sync"
Expand All @@ -21,6 +22,9 @@ const (
exitFailure = 1
)

// version is the shim version. This variable is populated at build time.
var version = "unknown"

var shimLog = logrus.WithFields(logrus.Fields{
"name": shimName,
"pid": os.Getpid(),
Expand All @@ -36,6 +40,8 @@ func initLogger(logLevel string) error {

logrus.SetLevel(level)

shimLog.WithField("version", version).Info()

return nil
}

Expand All @@ -46,8 +52,10 @@ func main() {
container string
pid uint
proxyExitCode bool
showVersion bool
)

flag.BoolVar(&showVersion, "version", false, "display program version and exit")
flag.StringVar(&logLevel, "log", "warn", "set shim log level: debug, info, warn, error, fatal or panic")
flag.StringVar(&agentAddr, "agent", "", "agent gRPC socket endpoint")

Expand All @@ -57,6 +65,11 @@ func main() {

flag.Parse()

if showVersion {
fmt.Printf("%v version %v\n", shimName, version)
os.Exit(0)
}

if agentAddr == "" || container == "" || pid == 0 {
shimLog.WithField("agentAddr", agentAddr).WithField("container", container).WithField("pid", pid).Error("container ID, process ID and agent socket endpoint must be set")
os.Exit(exitFailure)
Expand Down

0 comments on commit 37db356

Please sign in to comment.